-
Notifications
You must be signed in to change notification settings - Fork 2
/
filespane_test.go
52 lines (47 loc) · 1.33 KB
/
filespane_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
package main
import (
"reflect"
"testing"
"github.com/fsnotify/fsnotify"
)
type TestCase struct {
oldEvents []fsnotify.Event
newEvent fsnotify.Event
expected []fsnotify.Event
}
func TestAddEventToBatch(t *testing.T) {
testCases := []TestCase{
{
oldEvents: []fsnotify.Event{
{Op: fsnotify.Create, Name: "file.txt"},
{Op: fsnotify.Write, Name: "file.txt"},
},
newEvent: fsnotify.Event{Op: fsnotify.Remove, Name: "file.txt"},
expected: []fsnotify.Event{{Op: fsnotify.Remove, Name: "file.txt"}},
},
{
oldEvents: []fsnotify.Event{
{Op: fsnotify.Write, Name: "file.txt"},
{Op: fsnotify.Write, Name: "file.txt"},
{Op: fsnotify.Write, Name: "file.txt"},
},
newEvent: fsnotify.Event{Op: fsnotify.Write, Name: "file.txt"},
expected: []fsnotify.Event{{Op: fsnotify.Write, Name: "file.txt"}},
},
{
oldEvents: []fsnotify.Event{
{Op: fsnotify.Create, Name: "file.txt"},
{Op: fsnotify.Create, Name: "file.txt"},
{Op: fsnotify.Create, Name: "file.txt"},
},
newEvent: fsnotify.Event{Op: fsnotify.Create, Name: "file.txt"},
expected: []fsnotify.Event{{Op: fsnotify.Create, Name: "file.txt"}},
},
}
for _, v := range testCases {
got := AddEventToBatch(v.oldEvents, v.newEvent)
if !reflect.DeepEqual(got, v.expected) {
t.Fatalf("Expected %#v, but got %#v", v.expected, got)
}
}
}