summaryrefslogtreecommitdiffstats
path: root/htesting/test_helpers.go
diff options
context:
space:
mode:
Diffstat (limited to 'htesting/test_helpers.go')
-rw-r--r--htesting/test_helpers.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/htesting/test_helpers.go b/htesting/test_helpers.go
index 660c76a44..3804f28fe 100644
--- a/htesting/test_helpers.go
+++ b/htesting/test_helpers.go
@@ -56,3 +56,33 @@ var rnd = rand.New(rand.NewSource(time.Now().UnixNano()))
func RandIntn(n int) int {
return rnd.Intn(n)
}
+
+// DiffStringSlices returns the difference between two string slices.
+// Useful in tests.
+// See:
+// http://stackoverflow.com/questions/19374219/how-to-find-the-difference-between-two-slices-of-strings-in-golang
+func DiffStringSlices(slice1 []string, slice2 []string) []string {
+ diffStr := []string{}
+ m := map[string]int{}
+
+ for _, s1Val := range slice1 {
+ m[s1Val] = 1
+ }
+ for _, s2Val := range slice2 {
+ m[s2Val] = m[s2Val] + 1
+ }
+
+ for mKey, mVal := range m {
+ if mVal == 1 {
+ diffStr = append(diffStr, mKey)
+ }
+ }
+
+ return diffStr
+}
+
+// DiffStrings splits the strings into fields and runs it into DiffStringSlices.
+// Useful for tests.
+func DiffStrings(s1, s2 string) []string {
+ return DiffStringSlices(strings.Fields(s1), strings.Fields(s2))
+}