summary refs log tree commit diff stats
path: root/svc/query_test.go
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2019-06-05 15:36:23 -0400
committerBen Morrison <ben@gbmor.dev>2019-06-05 15:36:23 -0400
commitfd43c61bd128ad77b22db0537a9a4eb58490b0b5 (patch)
tree4c5fa7b33fadbf7c3e14e69b7d68ce280bc3810a /svc/query_test.go
parent4658fe82be3e9d95e93fa5c7c7ca64a15cf2f1a1 (diff)
downloadgetwtxt-fd43c61bd128ad77b22db0537a9a4eb58490b0b5.tar.gz
moved bulk of code to its own package to clean up source tree
Diffstat (limited to 'svc/query_test.go')
-rw-r--r--svc/query_test.go75
1 files changed, 75 insertions, 0 deletions
diff --git a/svc/query_test.go b/svc/query_test.go
new file mode 100644
index 0000000..f93cd92
--- /dev/null
+++ b/svc/query_test.go
@@ -0,0 +1,75 @@
+package svc // import github.com/getwtxt/getwtxt/svc
+
+import (
+	"net"
+	"reflect"
+	"strings"
+	"testing"
+
+	"github.com/getwtxt/registry"
+)
+
+func Test_parseQueryOut(t *testing.T) {
+	initTestConf()
+
+	urls := "https://gbmor.dev/twtxt.txt"
+	nick := "gbmor"
+
+	out, _, err := registry.GetTwtxt(urls)
+	if err != nil {
+		t.Errorf("Couldn't set up test: %v\n", err)
+	}
+
+	statusmap, err := registry.ParseUserTwtxt(out, nick, urls)
+	if err != nil {
+		t.Errorf("Couldn't set up test: %v\n", err)
+	}
+
+	twtxtCache.AddUser(nick, urls, "", net.ParseIP("127.0.0.1"), statusmap)
+
+	t.Run("Parsing Status Query", func(t *testing.T) {
+		data, err := twtxtCache.QueryAllStatuses()
+		if err != nil {
+			t.Errorf("%v\n", err)
+		}
+
+		out := parseQueryOut(data)
+
+		conv := strings.Split(string(out), "\n")
+
+		if !reflect.DeepEqual(data, conv) {
+			t.Errorf("Pre- and Post- parseQueryOut data are inequal:\n%#v\n%#v\n", data, conv)
+		}
+	})
+}
+
+func Benchmark_parseQueryOut(b *testing.B) {
+	initTestConf()
+
+	urls := "https://gbmor.dev/twtxt.txt"
+	nick := "gbmor"
+
+	out, _, err := registry.GetTwtxt(urls)
+	if err != nil {
+		b.Errorf("Couldn't set up test: %v\n", err)
+	}
+
+	statusmap, err := registry.ParseUserTwtxt(out, nick, urls)
+	if err != nil {
+		b.Errorf("Couldn't set up test: %v\n", err)
+	}
+
+	twtxtCache.AddUser(nick, urls, "", net.ParseIP("127.0.0.1"), statusmap)
+
+	data, err := twtxtCache.QueryAllStatuses()
+	if err != nil {
+		b.Errorf("%v\n", err)
+	}
+
+	b.ResetTimer()
+
+	for i := 0; i < b.N; i++ {
+		parseQueryOut(data)
+	}
+
+}