From 1b5f9eb013ca9bb884ae0e726010c5b4998b9c35 Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Wed, 5 Feb 2014 23:32:12 -0500 Subject: [PATCH] test (isHidden) add unit test for isHidden function --- store/store_test.go | 1 - store/watcher_hub_test.go | 43 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 store/watcher_hub_test.go diff --git a/store/store_test.go b/store/store_test.go index d39e9993b..aa86f5206 100644 --- a/store/store_test.go +++ b/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", "") diff --git a/store/watcher_hub_test.go b/store/watcher_hub_test.go new file mode 100644 index 000000000..08a30f71b --- /dev/null +++ b/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) + } +}