watcher_hub_test.go 1.7 KB

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