test (isHidden) add unit test for isHidden function

This commit is contained in:
Xiang Li 2014-02-05 23:32:12 -05:00
parent 5851cb5b8d
commit 1b5f9eb013
2 changed files with 43 additions and 1 deletions

View File

@ -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
store/watcher_hub_test.go Normal file
View File

@ -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)
}
}