watcher_test.go 723 B

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