-
Notifications
You must be signed in to change notification settings - Fork 11
/
watcher_test.go
41 lines (31 loc) · 1.14 KB
/
watcher_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"testing"
"github.com/stretchr/testify/assert"
"gopkg.in/fsnotify.v1"
)
func TestIsFileImportant(t *testing.T) {
assert.True(t, true)
cnf := &config{build: "some-build", Suffixes: []string{".go"}, Ignore: []string{"some/file.c"}}
pm := &processManager{conf: cnf}
watcher := watcher{pm: pm}
// fail if event is not supported
event := fsnotify.Event{"some/file.go", fsnotify.Chmod}
assert.False(t, watcher.isEventImportant(event))
// fail if ext is not supported
event = fsnotify.Event{"some/file.html", fsnotify.Write}
assert.False(t, watcher.isEventImportant(event))
// fail if file is ignored
event = fsnotify.Event{"some/file.c", fsnotify.Write}
assert.False(t, watcher.isEventImportant(event))
// Test attrib event
event = fsnotify.Event{"some/file.go", fsnotify.Chmod}
assert.False(t, watcher.isEventImportant(event))
// Test attrib event in case settings are different
pm.conf.Attrib = true
event = fsnotify.Event{"some/file.go", fsnotify.Chmod}
assert.True(t, watcher.isEventImportant(event))
// all ok
event = fsnotify.Event{"some/file.go", fsnotify.Write}
assert.True(t, watcher.isEventImportant(event))
}