-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathwatcher.event_test.go
95 lines (80 loc) · 2.09 KB
/
watcher.event_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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main
import (
"testing"
"github.com/fsnotify/fsnotify"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
)
type WatcherEventTestSuite struct {
suite.Suite
absoluteFilePath string
fileName string
fileExtension string
}
func TestWatcherEvent(t *testing.T) {
suite.Run(t, new(WatcherEventTestSuite))
}
func (s *WatcherEventTestSuite) SetupTest() {
s.absoluteFilePath = "/absolute/path/to/file.ext"
s.fileName = "file.ext"
s.fileExtension = ".ext"
}
func (s *WatcherEventTestSuite) TestEventType_Create() {
e := WatcherEvent(fsnotify.Event{
Op: fsnotify.Create,
})
assert.Equal(s.T(), "+", e.EventType())
}
func (s *WatcherEventTestSuite) TestEventType_Write() {
e := WatcherEvent(fsnotify.Event{
Op: fsnotify.Write,
})
assert.Equal(s.T(), ">", e.EventType())
}
func (s *WatcherEventTestSuite) TestEventType_Rename() {
e := WatcherEvent(fsnotify.Event{
Op: fsnotify.Rename,
})
assert.Equal(s.T(), "/", e.EventType())
}
func (s *WatcherEventTestSuite) TestEventType_Remove() {
e := WatcherEvent(fsnotify.Event{
Op: fsnotify.Remove,
})
assert.Equal(s.T(), "-", e.EventType())
}
func (s *WatcherEventTestSuite) TestEventType_Chmod() {
e := WatcherEvent(fsnotify.Event{
Op: fsnotify.Chmod,
})
assert.Equal(s.T(), "%", e.EventType())
}
func (s *WatcherEventTestSuite) TestFilePath() {
e := WatcherEvent(fsnotify.Event{
Op: fsnotify.Chmod,
Name: s.absoluteFilePath,
})
assert.Equal(s.T(), s.absoluteFilePath, e.FilePath())
}
func (s *WatcherEventTestSuite) TestFileName() {
e := WatcherEvent(fsnotify.Event{
Op: fsnotify.Chmod,
Name: s.absoluteFilePath,
})
assert.Equal(s.T(), s.fileName, e.FileName())
}
func (s *WatcherEventTestSuite) TestIsAnyOf() {
e := WatcherEvent(fsnotify.Event{
Op: fsnotify.Chmod,
Name: s.absoluteFilePath,
})
assert.True(s.T(), e.IsAnyOf([]string{"ext"}))
assert.True(s.T(), e.IsAnyOf([]string{".ext"}))
}
func (s *WatcherEventTestSuite) TestFileType() {
e := WatcherEvent(fsnotify.Event{
Op: fsnotify.Chmod,
Name: s.absoluteFilePath,
})
assert.Equal(s.T(), s.fileExtension, e.FileType())
}