file_change_notify_test.go 805 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package filehelper
  2. import (
  3. "testing"
  4. "time"
  5. "github.com/fsnotify/fsnotify"
  6. "github.com/stretchr/testify/require"
  7. )
  8. func TestProcessDebounceCapturesEventName(t *testing.T) {
  9. debounceWriteLogMutex.Lock()
  10. debounceWriteLog = make(map[string]*FsNotifyLogEntry)
  11. debounceWriteLogMutex.Unlock()
  12. callbackNames := make(chan string, 1)
  13. firstEvent := fsnotify.Event{Name: "first"}
  14. ctx := &watchContext{
  15. callback: func(filename string) {
  16. callbackNames <- filename
  17. },
  18. event: &firstEvent,
  19. filename: t.Name(),
  20. }
  21. processDebounce(ctx)
  22. secondEvent := fsnotify.Event{Name: "second"}
  23. ctx.event = &secondEvent
  24. select {
  25. case callbackName := <-callbackNames:
  26. require.Equal(t, firstEvent.Name, callbackName)
  27. case <-time.After(time.Second):
  28. t.Fatal("debounced callback did not run")
  29. }
  30. }