summaryrefslogtreecommitdiff
path: root/internal/cache/status_test.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2021-08-29 15:41:41 +0100
committerLibravatar GitHub <noreply@github.com>2021-08-29 16:41:41 +0200
commited462245730bd7832019bd43e0bc1c9d1c055e8e (patch)
tree1caad78ea6aabf5ea93c93a8ade97176b4889500 /internal/cache/status_test.go
parentMention fixup (#167) (diff)
downloadgotosocial-ed462245730bd7832019bd43e0bc1c9d1c055e8e.tar.xz
Add SQLite support, fix un-thread-safe DB caches, small performance f… (#172)
* Add SQLite support, fix un-thread-safe DB caches, small performance fixes Signed-off-by: kim (grufwub) <grufwub@gmail.com> * add SQLite licenses to README Signed-off-by: kim (grufwub) <grufwub@gmail.com> * appease the linter, and fix my dumbass-ery Signed-off-by: kim (grufwub) <grufwub@gmail.com> * make requested changes Signed-off-by: kim (grufwub) <grufwub@gmail.com> * add back comment Signed-off-by: kim (grufwub) <grufwub@gmail.com>
Diffstat (limited to 'internal/cache/status_test.go')
-rw-r--r--internal/cache/status_test.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/internal/cache/status_test.go b/internal/cache/status_test.go
new file mode 100644
index 000000000..10dee5bca
--- /dev/null
+++ b/internal/cache/status_test.go
@@ -0,0 +1,41 @@
+package cache_test
+
+import (
+ "testing"
+
+ "github.com/superseriousbusiness/gotosocial/internal/cache"
+ "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
+)
+
+func TestStatusCache(t *testing.T) {
+ cache := cache.NewStatusCache()
+
+ // Attempt to place a status
+ status := gtsmodel.Status{
+ ID: "id",
+ URI: "uri",
+ URL: "url",
+ }
+ cache.Put(&status)
+
+ var ok bool
+ var check *gtsmodel.Status
+
+ // Check we can retrieve
+ check, ok = cache.GetByID(status.ID)
+ if !ok || !statusIs(&status, check) {
+ t.Fatal("Could not find expected status")
+ }
+ check, ok = cache.GetByURI(status.URI)
+ if !ok || !statusIs(&status, check) {
+ t.Fatal("Could not find expected status")
+ }
+ check, ok = cache.GetByURL(status.URL)
+ if !ok || !statusIs(&status, check) {
+ t.Fatal("Could not find expected status")
+ }
+}
+
+func statusIs(status1, status2 *gtsmodel.Status) bool {
+ return status1.ID == status2.ID && status1.URI == status2.URI && status1.URL == status2.URL
+}