-
Notifications
You must be signed in to change notification settings - Fork 0
/
tree_test.go
90 lines (69 loc) · 1.7 KB
/
tree_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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// -*- tab-width: 2 -*-
package treewalk
import (
"fmt"
"io/fs"
"os"
"strings"
"testing"
count "github.com/jayalane/go-counter"
timeout "github.com/jayalane/go-syscalls-timeout"
)
// had trouble with get //root/.bashrc////////// style from this.
func TestMyJoin(t *testing.T) {
a := [5]string{"", "", "", "", "."}
b := myJoin(a[:], "/")
if b != "." {
fmt.Println("Got {", b, "} expected { . }")
t.Fatal()
}
}
// even after that passed is was doing dedup.. not ../dedup.
func TestMyJoin2(t *testing.T) {
a := [5]string{"..", "dedup", "", "", ""}
b := myJoin(a[:], "/")
if b != "../dedup" {
fmt.Println("Got {", b, "} expected { ../dedup }")
t.Fatal()
}
}
// a full run of the simple app on ../
// no validation.
func TestPrint(_ *testing.T) {
count.InitCounters()
app := New("/home/jayalane/go/src", 2)
gNum := [2]int64{1, 5}
app.SetNumWorkers(gNum[:])
app.SetLogLevel("state")
testDir := []string{".git"} // skips .git
app.SetSkipDirs(testDir)
app.SetHandler(1, // files
func(sp StringPath) {
fullPath := append(sp.Path, sp.Name) //nolint:gocritic
fn := strings.Join(fullPath, "/")
var fi fs.FileInfo
var err error
de, ok := sp.Value.(fs.DirEntry)
if ok {
fi, err = de.Info()
count.Incr("Used de")
} else {
count.Incr("Used Lstat")
fi, err = timeout.Lstat(fn)
}
if err != nil {
app.log.La("Stat error on", fn, err)
count.Incr("file-handler-stat-error")
return
}
isSymLink := fi.Mode()&os.ModeSymlink == os.ModeSymlink
if isSymLink { // the logic specific to this app
fmt.Println("Is Symlink")
}
fmt.Println(fn, fi.ModTime())
count.Incr("file-handler-ok")
})
app.Start()
app.Wait()
count.LogCounters()
}