This repository has been archived by the owner on Oct 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwalk_test.go
73 lines (66 loc) · 1.87 KB
/
walk_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
package main
import (
"path/filepath"
"testing"
)
func TestSkipDir(t *testing.T) {
t.Run("recursive disabled", func(t *testing.T) {
result := skipDir("./directory", false)
if result != filepath.SkipDir {
t.Error("Expected result to be `filepath.SkipDir`")
}
})
t.Run("random directory (recursive)", func(t *testing.T) {
result := skipDir("./directory", true)
if result != nil {
t.Error("Expected result to be `nil`")
}
})
t.Run("directories always excluded (recursive)", func(t *testing.T) {
result := skipDir("./.git", true)
if result != filepath.SkipDir {
t.Error("Expected result to be `filepath.SkipDir`")
}
result = skipDir("./testdata", true)
if result != filepath.SkipDir {
t.Error("Expected result to be `filepath.SkipDir`")
}
result = skipDir("./vendor", true)
if result != filepath.SkipDir {
t.Error("Expected result to be `filepath.SkipDir`")
}
})
}
func TestSkipFile(t *testing.T) {
excludeTests := true
var noExcludePatterns []string
t.Run("non-.go file", func(t *testing.T) {
result := skipFile("file.txt", excludeTests, noExcludePatterns)
if result == false {
t.Error("Expected result to be true")
}
})
t.Run(".go file", func(t *testing.T) {
result := skipFile("file.go", excludeTests, noExcludePatterns)
if result == true {
t.Error("Expected result to be false")
}
})
t.Run("_test.go file", func(t *testing.T) {
result := skipFile("file_test.go", true, noExcludePatterns)
if result == false {
t.Error("Expected result to be true")
}
result = skipFile("file_test.go", false, noExcludePatterns)
if result == true {
t.Error("Expected result to be false")
}
})
t.Run("custom exclude pattern", func(t *testing.T) {
excludePatterns := []string{"foo*.go"}
result := skipFile("foobar.go", excludeTests, excludePatterns)
if result == false {
t.Error("Expected result to be true")
}
})
}