forked from stretchr/powerwalk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
modwalk_test.go
51 lines (41 loc) · 964 Bytes
/
modwalk_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
package symwalk
import (
"os"
"path"
"runtime"
"sync"
"testing"
"github.com/stretchr/testify/assert"
)
func TestSymWalk(t *testing.T) {
// max concurrency out
runtime.GOMAXPROCS(runtime.NumCPU())
var seenLock sync.Mutex
seen := make(map[string]bool)
walkFunc := func(p string, info os.FileInfo, err error) error {
if !info.IsDir() {
filename := path.Base(p)
seenLock.Lock()
defer seenLock.Unlock()
seen[filename] = true
}
return nil
}
assert.NoError(t, Walk("testdata/root", walkFunc))
// Check if "found.txt" was found, starting from "testdata/root", then following the symlink to "testdata/other"
followedSymlink := false
for fn := range seen {
if fn == "found.txt" {
followedSymlink = true
}
}
if !followedSymlink {
t.FailNow()
}
// make sure everything was seen
if assert.NotEqual(t, len(seen), 0, "Walker should visit at least one file.") {
for k, v := range seen {
assert.True(t, v, k)
}
}
}