watcher_test.go 735 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package fileSystem
  2. import (
  3. "testing"
  4. )
  5. func TestWatcher(t *testing.T) {
  6. fs := New()
  7. wh := fs.WatcherHub
  8. c, err := wh.watch("/foo", true, 0)
  9. if err != nil {
  10. t.Fatal("%v", err)
  11. }
  12. select {
  13. case <-c:
  14. t.Fatal("should not receive from channel before send the event")
  15. default:
  16. // do nothing
  17. }
  18. e := newEvent(Create, "/foo/bar", 1, 0)
  19. wh.notify(e)
  20. re := <-c
  21. if e != re {
  22. t.Fatal("recv != send")
  23. }
  24. c, _ = wh.watch("/foo", false, 0)
  25. e = newEvent(Create, "/foo/bar", 1, 0)
  26. wh.notify(e)
  27. select {
  28. case <-c:
  29. t.Fatal("should not receive from channel if not recursive")
  30. default:
  31. // do nothing
  32. }
  33. e = newEvent(Create, "/foo", 1, 0)
  34. wh.notify(e)
  35. re = <-c
  36. if e != re {
  37. t.Fatal("recv != send")
  38. }
  39. }