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-12 02:26:06 -0400
committerGitHub <noreply@github.com>2019-06-12 02:26:06 -0400
commitf5d40abf409016f297b2f0749ce9d26299381828 (patch)
treef3464aaa2cb16e922295cd7321d3b8cba01c8564 /svc/query_test.go
parent3681615abf46112646c009cf17f29d07c2755c11 (diff)
parenta6900c200808dbc5aa77dbf1454c6e369fb328e9 (diff)
downloadgetwtxt-f5d40abf409016f297b2f0749ce9d26299381828.tar.gz
Merge pull request #5 from getwtxt/test-development
Additional Tests
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) {