-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclock_test.go
53 lines (42 loc) · 1.14 KB
/
clock_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
package watchman
import (
"io/ioutil"
"testing"
)
func TestClock(t *testing.T) {
cl := &Client{Sockname: sock}
t.Run("empty path", func(t *testing.T) {
_, err := cl.Clock("")
expectErrEqual(t, err, "invalid argument")
})
t.Run("invalid path", func(t *testing.T) {
_, err := cl.Clock("/stupid dumb i guess this could exist")
expectErrRegex(t, err, "^lstat .*: no such file or directory$")
})
t.Run("no watch", func(t *testing.T) {
path, err := ioutil.TempDir("", "watchmantest")
if err != nil {
t.Fatalf("Error creating temp dir %s", err)
}
_, err = cl.Clock(path)
expectErrRegex(t, err, "^unable to resolve root .*: directory .* is not watched$")
})
t.Run("success", func(t *testing.T) {
path, err := ioutil.TempDir("", "watchmantest")
if err != nil {
t.Fatalf("Error creating temp dir %s", err)
}
w, err := cl.Watch(path)
if err != nil {
t.Fatalf("Error watching path %s: %s", path, err)
}
defer cl.WatchDel(w.Watch)
c, err := cl.Clock(w.Watch)
if err != nil {
t.Errorf("Unexpected error calling clock: %s", err)
}
if c == nil || c.Clock == "" {
t.Errorf("Clock is empty: %#v", c)
}
})
}