watcher_hub_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package store
  2. import (
  3. "testing"
  4. )
  5. // TestIsHidden tests isHidden functions.
  6. func TestIsHidden(t *testing.T) {
  7. // watch at "/"
  8. // key is "/_foo", hidden to "/"
  9. // expected: hidden = true
  10. watch := "/"
  11. key := "/_foo"
  12. hidden := isHidden(watch, key)
  13. if !hidden {
  14. t.Fatalf("%v should be hidden to %v\n", key, watch)
  15. }
  16. // watch at "/_foo"
  17. // key is "/_foo", not hidden to "/_foo"
  18. // expected: hidden = false
  19. watch = "/_foo"
  20. hidden = isHidden(watch, key)
  21. if hidden {
  22. t.Fatalf("%v should not be hidden to %v\n", key, watch)
  23. }
  24. // watch at "/_foo/"
  25. // key is "/_foo/foo", not hidden to "/_foo"
  26. key = "/_foo/foo"
  27. hidden = isHidden(watch, key)
  28. if hidden {
  29. t.Fatalf("%v should not be hidden to %v\n", key, watch)
  30. }
  31. // watch at "/_foo/"
  32. // key is "/_foo/_foo", hidden to "/_foo"
  33. key = "/_foo/_foo"
  34. hidden = isHidden(watch, key)
  35. if !hidden {
  36. t.Fatalf("%v should be hidden to %v\n", key, watch)
  37. }
  38. // watch at "/_foo/foo"
  39. // key is "/_foo"
  40. watch = "_foo/foo"
  41. key = "/_foo/"
  42. hidden = isHidden(watch, key)
  43. if hidden {
  44. t.Fatalf("%v should not be hidden to %v\n", key, watch)
  45. }
  46. }