summary refs log tree commit diff stats
path: root/svc/query_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'svc/query_test.go')
-rw-r--r--svc/query_test.go56
1 files changed, 56 insertions, 0 deletions
diff --git a/svc/query_test.go b/svc/query_test.go
index a01de90..477808b 100644
--- a/svc/query_test.go
+++ b/svc/query_test.go
@@ -73,3 +73,59 @@ func Benchmark_parseQueryOut(b *testing.B) {
 	}
 
 }
+
+func Test_compositeStatusQuery(t *testing.T) {
+	initTestConf()
+	statuses, _, err := registry.GetTwtxt("https://gbmor.dev/twtxt.txt")
+	if err != nil {
+		t.Errorf("%v\n", err)
+	}
+	parsed, err := registry.ParseUserTwtxt(statuses, "gbmor", "https://gbmor.dev/twtxt.txt")
+	if err != nil {
+		t.Errorf("%v\n", err)
+	}
+	err = twtxtCache.AddUser("gbmor", "https://gbmor.dev/twtxt.txt", "1", net.ParseIP("127.0.0.1"), parsed)
+	if err != nil {
+		t.Errorf("%v\n", err)
+	}
+
+	t.Run("Composite Query Test", func(t *testing.T) {
+		out1, err := twtxtCache.QueryInStatus("sqlite")
+		if err != nil {
+			t.Errorf("%v\n", err)
+		}
+		out2, err := twtxtCache.QueryInStatus("Sqlite")
+		if err != nil {
+			t.Errorf("%v\n", err)
+		}
+		out3, err := twtxtCache.QueryInStatus("SQLITE")
+		if err != nil {
+			t.Errorf("%v\n", err)
+		}
+
+		outro := make([]string, 0)
+		outro = append(outro, out1...)
+		outro = append(outro, out2...)
+		outro = append(outro, out3...)
+		out := dedupe(outro)
+
+		data := compositeStatusQuery("sqlite", nil)
+
+		if !reflect.DeepEqual(out, data) {
+			t.Errorf("Returning different data.\nManual: %v\nCompositeQuery: %v\n", out, data)
+		}
+	})
+}
+
+func Benchmark_compositeStatusQuery(b *testing.B) {
+	initTestConf()
+	statuses, _, _ := registry.GetTwtxt("https://gbmor.dev/twtxt.txt")
+	parsed, _ := registry.ParseUserTwtxt(statuses, "gbmor", "https://gbmor.dev/twtxt.txt")
+	_ = twtxtCache.AddUser("gbmor", "https://gbmor.dev/twtxt.txt", "1", net.ParseIP("127.0.0.1"), parsed)
+	b.ResetTimer()
+
+	for i := 0; i < b.N; i++ {
+		compositeStatusQuery("sqlite", nil)
+	}
+
+}