-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
walk_test.go
53 lines (47 loc) · 1.11 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
package mtree
import (
"os"
"testing"
)
func TestWalk(t *testing.T) {
dh, err := Walk(".", nil, append(DefaultKeywords, "sha1"), nil)
if err != nil {
t.Fatal(err)
}
numEntries := countTypes(dh)
fh, err := os.CreateTemp("", "walk.")
if err != nil {
t.Fatal(err)
}
defer os.Remove(fh.Name())
defer fh.Close()
if _, err = dh.WriteTo(fh); err != nil {
t.Fatal(err)
}
if _, err := fh.Seek(0, 0); err != nil {
t.Fatal(err)
}
if dh, err = ParseSpec(fh); err != nil {
t.Fatal(err)
}
for k, v := range countTypes(dh) {
if numEntries[k] != v {
t.Errorf("for type %s: expected %d, got %d", k, numEntries[k], v)
}
}
}
func TestWalkDirectory(t *testing.T) {
dh, err := Walk(".", []ExcludeFunc{ExcludeNonDirectories}, []Keyword{"type"}, nil)
if err != nil {
t.Fatal(err)
}
for i := range dh.Entries {
for _, keyval := range dh.Entries[i].AllKeys() {
if dh.Entries[i].Type == FullType || dh.Entries[i].Type == RelativeType {
if keyval.Keyword() == "type" && keyval.Value() != "dir" {
t.Errorf("expected only directories, but %q is a %q", dh.Entries[i].Name, keyval.Value())
}
}
}
}
}