watcher_hub_test.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright 2015 The etcd Authors
  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 v2store
  15. import "testing"
  16. // TestIsHidden tests isHidden functions.
  17. func TestIsHidden(t *testing.T) {
  18. // watch at "/"
  19. // key is "/_foo", hidden to "/"
  20. // expected: hidden = true
  21. watch := "/"
  22. key := "/_foo"
  23. hidden := isHidden(watch, key)
  24. if !hidden {
  25. t.Fatalf("%v should be hidden to %v\n", key, watch)
  26. }
  27. // watch at "/_foo"
  28. // key is "/_foo", not hidden to "/_foo"
  29. // expected: hidden = false
  30. watch = "/_foo"
  31. hidden = isHidden(watch, key)
  32. if hidden {
  33. t.Fatalf("%v should not be hidden to %v\n", key, watch)
  34. }
  35. // watch at "/_foo/"
  36. // key is "/_foo/foo", not hidden to "/_foo"
  37. key = "/_foo/foo"
  38. hidden = isHidden(watch, key)
  39. if hidden {
  40. t.Fatalf("%v should not be hidden to %v\n", key, watch)
  41. }
  42. // watch at "/_foo/"
  43. // key is "/_foo/_foo", hidden to "/_foo"
  44. key = "/_foo/_foo"
  45. hidden = isHidden(watch, key)
  46. if !hidden {
  47. t.Fatalf("%v should be hidden to %v\n", key, watch)
  48. }
  49. // watch at "/_foo/foo"
  50. // key is "/_foo"
  51. watch = "_foo/foo"
  52. key = "/_foo/"
  53. hidden = isHidden(watch, key)
  54. if hidden {
  55. t.Fatalf("%v should not be hidden to %v\n", key, watch)
  56. }
  57. }