forked from hanwen/go-fuse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
autounion_test.go
170 lines (135 loc) · 3.63 KB
/
autounion_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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package unionfs
import (
"os"
"github.com/hanwen/go-fuse/fuse"
"io/ioutil"
"fmt"
"log"
"testing"
"time"
)
var _ = fmt.Print
var _ = log.Print
const entryTtl = 0.1
var testAOpts = AutoUnionFsOptions{
UnionFsOptions: testOpts,
FileSystemOptions: fuse.FileSystemOptions{
EntryTimeout: entryTtl,
AttrTimeout: entryTtl,
NegativeTimeout: 0,
},
}
func WriteFile(name string, contents string) {
err := ioutil.WriteFile(name, []byte(contents), 0644)
CheckSuccess(err)
}
func setup(t *testing.T) (workdir string, cleanup func()) {
wd := fuse.MakeTempDir()
err := os.Mkdir(wd+"/mount", 0700)
fuse.CheckSuccess(err)
err = os.Mkdir(wd+"/store", 0700)
fuse.CheckSuccess(err)
os.Mkdir(wd+"/ro", 0700)
fuse.CheckSuccess(err)
WriteFile(wd+"/ro/file1", "file1")
WriteFile(wd+"/ro/file2", "file2")
fs := NewAutoUnionFs(wd+"/store", testAOpts)
state, conn, err := fuse.MountFileSystem(wd + "/mount", fs, &testAOpts.FileSystemOptions)
CheckSuccess(err)
state.Debug = true
conn.Debug = true
go state.Loop(false)
return wd, func() {
state.Unmount()
os.RemoveAll(wd)
}
}
func TestVersion(t *testing.T) {
wd, clean := setup(t)
defer clean()
c, err := ioutil.ReadFile(wd+"/mount/status/gounionfs_version")
CheckSuccess(err)
if len(c) == 0 {
t.Fatal("No version found.")
}
log.Println("Found version:", string(c))
}
func TestAutoFsSymlink(t *testing.T) {
wd, clean := setup(t)
defer clean()
err := os.Mkdir(wd+"/store/backing1", 0755)
CheckSuccess(err)
os.Symlink(wd+"/ro", wd+"/store/backing1/READONLY")
CheckSuccess(err)
err = os.Symlink(wd+"/store/backing1", wd+"/mount/config/manual1")
CheckSuccess(err)
fi, err := os.Lstat(wd + "/mount/manual1/file1")
CheckSuccess(err)
err = os.Remove(wd + "/mount/config/manual1")
CheckSuccess(err)
// Need time for the unmount to be noticed.
log.Println("sleeping...")
time.Sleep(2 * entryTtl * 1e9)
scan := wd + "/mount/config/" + _SCAN_CONFIG
err = ioutil.WriteFile(scan, []byte("something"), 0644 )
if err != nil {
t.Error("error writing:", err)
}
fi, _ = os.Lstat(wd + "/mount/manual1")
if fi != nil {
t.Error("Should not have file:", fi)
}
_, err = ioutil.ReadDir(wd + "/mount/config")
CheckSuccess(err)
_, err = os.Lstat(wd + "/mount/backing1/file1")
CheckSuccess(err)
}
func TestExplicitScan(t *testing.T) {
wd, clean := setup(t)
defer clean()
err := os.Mkdir(wd+"/store/backing1", 0755)
CheckSuccess(err)
os.Symlink(wd+"/ro", wd+"/store/backing1/READONLY")
CheckSuccess(err)
fi, _ := os.Lstat(wd + "/mount/backing1")
if fi != nil {
t.Error("Should not have file:", fi)
}
scan := wd + "/mount/config/" + _SCAN_CONFIG
_, err = os.Lstat(scan)
if err != nil {
t.Error(".scan_config missing:", err)
}
err = ioutil.WriteFile(scan, []byte("something"), 0644 )
if err != nil {
t.Error("error writing:", err)
}
_, err = os.Lstat(wd + "/mount/backing1")
if err != nil {
t.Error("Should have workspace backing1:", err)
}
}
func TestCreationChecks(t *testing.T) {
wd, clean := setup(t)
defer clean()
err := os.Mkdir(wd+"/store/foo", 0755)
CheckSuccess(err)
os.Symlink(wd+"/ro", wd+"/store/foo/READONLY")
CheckSuccess(err)
err = os.Mkdir(wd+"/store/ws2", 0755)
CheckSuccess(err)
os.Symlink(wd+"/ro", wd+"/store/ws2/READONLY")
CheckSuccess(err)
err = os.Symlink(wd+"/store/foo", wd+"/mount/config/bar")
CheckSuccess(err)
err = os.Symlink(wd+"/store/foo", wd+"/mount/config/foo")
code := fuse.OsErrorToErrno(err)
if code != fuse.EBUSY {
t.Error("Should return EBUSY", err)
}
err = os.Symlink(wd+"/store/ws2", wd+"/mount/config/config")
code = fuse.OsErrorToErrno(err)
if code != fuse.EINVAL {
t.Error("Should return EINVAL", err)
}
}