-
Notifications
You must be signed in to change notification settings - Fork 67
/
watch_test.go
62 lines (50 loc) · 1.4 KB
/
watch_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
package watcher
import (
"os"
"testing"
)
func TestPrepareRootDir(t *testing.T) {
w := &Watcher{}
dir, err := w.prepareRootDir()
if err != nil {
t.Errorf("Expected nil but got %s for prepareRootDir", err)
}
workingDir, _ := os.Getwd()
if dir != workingDir {
t.Errorf("Expected %s but got %s for prepareRootDir", workingDir, dir)
}
w.rootdir = "balcony"
os.Setenv("GOPATH", "")
dir, err = w.prepareRootDir()
if err != ErrPathNotSet {
t.Errorf("Expected %s but got %s for prepareRootDir", ErrPathNotSet, err)
}
os.Setenv("GOPATH", "go")
dir, err = w.prepareRootDir()
if err != nil {
t.Errorf("Expected nil but got %s for prepareRootDir", err)
}
if dir != "go/src/balcony" {
t.Errorf("Expected go/src/balcony but got %s for prepareRootDir", dir)
}
}
func TestIsTestFile(t *testing.T) {
fileName := "/go/src/github.com/canthefason/go-watcher/common.go"
if isTestFile(fileName) {
t.Error("expected false, got true")
}
fileName = "/go/src/github.com/canthefason/go-watcher/common_test.go"
if !isTestFile(fileName) {
t.Error("expected true, got false")
}
}
func TestIsWatchedFileType(t *testing.T) {
fileName := "/go/src/github.com/canthefason/go-watcher/common.go"
if !isWatchedFileType(fileName) {
t.Errorf("expected true, got false")
}
fileName = "/go/src/github.com/canthefason/go-watcher/README.md"
if isWatchedFileType(fileName) {
t.Errorf("expected false, got true")
}
}