This repository has been archived by the owner on Mar 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemfile_test.go
90 lines (78 loc) · 1.83 KB
/
memfile_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
package cafs
import (
"testing"
)
func TestMemfile(t *testing.T) {
a := NewMemdir("/a",
NewMemfileBytes("a.txt", []byte("foo")),
NewMemfileBytes("b.txt", []byte("bar")),
NewMemdir("/c",
NewMemfileBytes("d.txt", []byte("baz")),
NewMemdir("/e",
NewMemfileBytes("f.txt", []byte("bat")),
),
),
NewMemfileBytes("h.txt", []byte("bong")),
NewMemfileBytes("/i/j.txt", []byte("boink")),
)
a.AddChildren(NewMemfileBytes("g.txt", []byte("kazam")))
expectPaths := []string{
"/a",
"/a/a.txt",
"/a/b.txt",
"/a/c",
"/a/c/d.txt",
"/a/c/e",
"/a/c/e/f.txt",
"/a/h.txt",
"/a/i/j.txt",
"/a/g.txt",
}
paths := []string{}
err := Walk(a, 0, func(f File, depth int) error {
paths = append(paths, f.FullPath())
return nil
})
if err != nil {
t.Errorf("unexpected error: %s", err.Error())
}
if len(paths) != len(expectPaths) {
t.Errorf("path length mismatch. expected: %d, got %d", len(expectPaths), len(paths))
return
}
for i, p := range expectPaths {
if paths[i] != p {
t.Errorf("path %d mismatch expected: %s, got: %s", i, p, paths[i])
}
}
}
func TestMemdirMakeDirP(t *testing.T) {
dir := NewMemdir("/")
dir.MakeDirP(NewMemfileBytes("./a/b/c/d/file.txt", []byte("foo")))
dir.MakeDirP(NewMemfileBytes("./a/b/file.txt", []byte("foo")))
expectPaths := []string{
"/",
"/a",
"/a/b",
"/a/b/c",
"/a/b/c/d",
// "/a/b/c/d/file.txt",
}
paths := []string{}
err := Walk(dir, 0, func(f File, depth int) error {
paths = append(paths, f.FullPath())
return nil
})
if err != nil {
t.Errorf("unexpected error: %s", err.Error())
}
if len(paths) != len(expectPaths) {
t.Errorf("path length mismatch. expected: %d, got %d", len(expectPaths), len(paths))
return
}
for i, p := range expectPaths {
if paths[i] != p {
t.Errorf("path %d mismatch expected: %s, got: %s", i, p, paths[i])
}
}
}