-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscope_test.go
54 lines (42 loc) · 1.12 KB
/
scope_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
package vfs_test
import (
"testing"
"time"
"github.com/textmodes/vfs"
"github.com/textmodes/vfs/mapfs"
)
func TestNewScope(t *testing.T) {
// We will mount this filesystem under /fs1
mount := mapfs.New(map[string]string{"fs1file": "abcdefgh"})
// Existing process. This should give error on Stat("/")
t1 := vfs.Scope{}
t1.Bind("/fs1", "/", mount, vfs.BindReplace)
// using NewNameSpace. This should work fine.
t2 := vfs.NewScope()
t2.Bind("/fs1", "/", mount, vfs.BindReplace)
testcases := map[string][]bool{
"/": {false, true},
"/fs1": {true, true},
"/fs1/fs1file": {true, true},
}
fss := []vfs.FileSystem{t1, t2}
for j, fs := range fss {
for k, v := range testcases {
_, err := fs.Stat(k)
result := err == nil
if result != v[j] {
t.Errorf("fs: %d, testcase: %s, want: %v, got: %v, err: %s", j, k, v[j], result, err)
}
}
}
fi, err := t2.Stat("/")
if err != nil {
t.Fatal(err)
}
if fi.Name() != "/" {
t.Errorf("t2.Name() : want:%s got:%s", "/", fi.Name())
}
if !fi.ModTime().IsZero() {
t.Errorf("t2.Modime() : want:%v got:%v", time.Time{}, fi.ModTime())
}
}