watcher_hub_test.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. Copyright 2014 CoreOS, Inc.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package store
  14. import (
  15. "testing"
  16. )
  17. // TestIsHidden tests isHidden functions.
  18. func TestIsHidden(t *testing.T) {
  19. // watch at "/"
  20. // key is "/_foo", hidden to "/"
  21. // expected: hidden = true
  22. watch := "/"
  23. key := "/_foo"
  24. hidden := isHidden(watch, key)
  25. if !hidden {
  26. t.Fatalf("%v should be hidden to %v\n", key, watch)
  27. }
  28. // watch at "/_foo"
  29. // key is "/_foo", not hidden to "/_foo"
  30. // expected: hidden = false
  31. watch = "/_foo"
  32. hidden = isHidden(watch, key)
  33. if hidden {
  34. t.Fatalf("%v should not be hidden to %v\n", key, watch)
  35. }
  36. // watch at "/_foo/"
  37. // key is "/_foo/foo", not hidden to "/_foo"
  38. key = "/_foo/foo"
  39. hidden = isHidden(watch, key)
  40. if hidden {
  41. t.Fatalf("%v should not be hidden to %v\n", key, watch)
  42. }
  43. // watch at "/_foo/"
  44. // key is "/_foo/_foo", hidden to "/_foo"
  45. key = "/_foo/_foo"
  46. hidden = isHidden(watch, key)
  47. if !hidden {
  48. t.Fatalf("%v should be hidden to %v\n", key, watch)
  49. }
  50. // watch at "/_foo/foo"
  51. // key is "/_foo"
  52. watch = "_foo/foo"
  53. key = "/_foo/"
  54. hidden = isHidden(watch, key)
  55. if hidden {
  56. t.Fatalf("%v should not be hidden to %v\n", key, watch)
  57. }
  58. }