-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfspath_test.go
78 lines (68 loc) · 1.57 KB
/
fspath_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
package fspath_test
import (
"io/fs"
"reflect"
"testing"
"github.com/stealthrocket/fspath"
"github.com/stealthrocket/fstest"
)
func TestWalk(t *testing.T) {
for _, test := range [...]struct {
name string
walk []string
}{
{
name: ".",
walk: []string{"."},
},
{
name: "a",
walk: []string{"a"},
},
{
name: "a/b",
walk: []string{"a", "a/b"},
},
{
name: "a/b/c",
walk: []string{"a", "a/b", "a/b/c"},
},
} {
var walk []string
if err := fspath.Walk(test.name, func(path string) error {
walk = append(walk, path)
return nil
}); err != nil {
t.Error(err)
}
if !reflect.DeepEqual(walk, test.walk) {
t.Errorf("mismatch: want=%q got=%q", walk, test.walk)
}
}
}
func TestLookup(t *testing.T) {
fsys := fstest.MapFS{
"a": &fstest.MapFile{Mode: 0755 | fs.ModeDir},
"a/b": &fstest.MapFile{Mode: 0666 | fs.ModeSymlink, Data: []byte("../../c")},
"a/c": &fstest.MapFile{Mode: 0755 | fs.ModeDir},
"c/d": &fstest.MapFile{Mode: 0644, Data: []byte("Hello World!")},
}
b, err := fspath.ReadFile(fsys, "a/b/d")
if err != nil {
t.Error(err)
}
if string(b) != "Hello World!" {
t.Errorf("wong file content: %q", b)
}
}
func TestRootFS(t *testing.T) {
fsys := fstest.MapFS{
"a": &fstest.MapFile{Mode: 0755 | fs.ModeDir},
"a/b": &fstest.MapFile{Mode: 0666 | fs.ModeSymlink, Data: []byte("../c/d")},
"a/c": &fstest.MapFile{Mode: 0755 | fs.ModeDir},
"c/d": &fstest.MapFile{Mode: 0644, Data: []byte("Hello World!")},
}
if err := fstest.TestFS(fspath.RootFS(fsys), "a", "a/b", "a/c", "c/d"); err != nil {
t.Error(err)
}
}