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-11 23:34:28 -0400
committerBen Morrison <ben@gbmor.dev>2019-06-11 23:52:01 -0400
commitc18d944f6f53152ddcda3c707571f17307054e48 (patch)
tree228a5a20d64befbd57ca754e801570991853910d /svc/query_test.go
parentb957093e4fbbf4b423745f5365c06f48ccec20bd (diff)
downloadgetwtxt-c18d944f6f53152ddcda3c707571f17307054e48.tar.gz
tests for most of query.go
Diffstat (limited to 'svc/query_test.go')
-rw-r--r--svc/query_test.go76
1 files changed, 76 insertions, 0 deletions
diff --git a/svc/query_test.go b/svc/query_test.go
index 9fe6496..687b102 100644
--- a/svc/query_test.go
+++ b/svc/query_test.go
@@ -9,6 +9,36 @@ import (
 	"github.com/getwtxt/registry"
 )
 
+func Test_dedupe(t *testing.T) {
+	t.Run("Simple Deduplication Test", func(t *testing.T) {
+		start := []string{
+			"first",
+			"second",
+			"third",
+			"third",
+		}
+		finish := dedupe(start)
+		if reflect.DeepEqual(start, finish) {
+			t.Errorf("Deduplication didn't occur\n")
+		}
+		if len(finish) != 3 {
+			t.Errorf("Ending length not what was expected\n")
+		}
+	})
+}
+
+func Benchmark_dedupe(b *testing.B) {
+	start := []string{
+		"first",
+		"second",
+		"third",
+		"third",
+	}
+	for i := 0; i < b.N; i++ {
+		dedupe(start)
+	}
+}
+
 func Test_parseQueryOut(t *testing.T) {
 	initTestConf()
 
@@ -71,7 +101,53 @@ func Benchmark_parseQueryOut(b *testing.B) {
 	for i := 0; i < b.N; i++ {
 		parseQueryOut(data)
 	}
+}
 
+func Test_joinQueryOuts(t *testing.T) {
+	first := []string{
+		"one",
+		"two",
+		"three",
+	}
+	second := []string{
+		"three",
+		"four",
+		"five",
+		"six",
+	}
+	t.Run("Joining two string slices", func(t *testing.T) {
+		third := joinQueryOuts(first, second)
+		if len(third) != (len(first) + len(second) - 1) {
+			t.Errorf("Was not combined or deduplicated properly\n")
+		}
+		fourth := make([]string, 6)
+		for i := 0; i < len(first); i++ {
+			fourth[i] = first[i]
+		}
+		for i := 1; i < len(second); i++ {
+			fourth[2+i] = second[i]
+		}
+		if !reflect.DeepEqual(fourth, third) {
+			t.Errorf("Output not deeply equal to manual construction\n")
+		}
+	})
+}
+
+func Benchmark_joinQueryOuts(b *testing.B) {
+	first := []string{
+		"one",
+		"two",
+		"three",
+	}
+	second := []string{
+		"three",
+		"four",
+		"five",
+		"six",
+	}
+	for i := 0; i < b.N; i++ {
+		joinQueryOuts(first, second)
+	}
 }
 
 func Test_compositeStatusQuery(t *testing.T) {