summary refs log tree commit diff stats
path: root/svc
diff options
context:
space:
mode:
Diffstat (limited to 'svc')
-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) {