Browse Source

test (isHidden) add unit test for isHidden function

Xiang Li 12 years ago
parent
commit
1b5f9eb013
2 changed files with 43 additions and 1 deletions
  1. 0 1
      store/store_test.go
  2. 43 0
      store/watcher_hub_test.go

+ 0 - 1
store/store_test.go

@@ -789,7 +789,6 @@ func TestStoreWatchRecursiveCreateDeeperThanHiddenKey(t *testing.T) {
 	s.Create("/_foo/bar/baz", false, "baz", false, Permanent)
 
 	e := nbselect(w.EventChan)
-	// The NotNil assertion currently fails
 	assert.NotNil(t, e, "")
 	assert.Equal(t, e.Action, "create", "")
 	assert.Equal(t, e.Node.Key, "/_foo/bar/baz", "")

+ 43 - 0
store/watcher_hub_test.go

@@ -0,0 +1,43 @@
+package store
+
+import (
+	"testing"
+)
+
+// TestIsHidden tests isHidden functions.
+func TestIsHidden(t *testing.T) {
+	// watch at "/"
+	// key is "/_foo", hidden to "/"
+	// expected: hidden = true
+	watch := "/"
+	key := "/_foo"
+	hidden := isHidden(watch, key)
+	if !hidden {
+		t.Fatalf("%v should be hidden to %v\n", key, watch)
+	}
+
+	// watch at "/_foo"
+	// key is "/_foo", not hidden to "/_foo"
+	// expected: hidden = false
+	watch = "/_foo"
+	hidden = isHidden(watch, key)
+	if hidden {
+		t.Fatalf("%v should not be hidden to %v\n", key, watch)
+	}
+
+	// watch at "/_foo/"
+	// key is "/_foo/foo", not hidden to "/_foo"
+	key = "/_foo/foo"
+	hidden = isHidden(watch, key)
+	if hidden {
+		t.Fatalf("%v should not be hidden to %v\n", key, watch)
+	}
+
+	// watch at "/_foo/"
+	// key is "/_foo/_foo", hidden to "/_foo"
+	key = "/_foo/_foo"
+	hidden = isHidden(watch, key)
+	if !hidden {
+		t.Fatalf("%v should be hidden to %v\n", key, watch)
+	}
+}