Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go-fuse
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go-fuse
Commits
060980b2
Commit
060980b2
authored
Feb 25, 2013
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Drop CheckSuccess from rest of tests too.
parent
ff72948e
Changes
18
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
764 additions
and
323 deletions
+764
-323
fuse/cache_test.go
fuse/cache_test.go
+38
-14
fuse/copy_test.go
fuse/copy_test.go
+12
-4
fuse/defaultread_test.go
fuse/defaultread_test.go
+9
-5
fuse/fsetattr_test.go
fuse/fsetattr_test.go
+30
-10
fuse/loopback_darwin_test.go
fuse/loopback_darwin_test.go
+2
-1
fuse/loopback_linux_test.go
fuse/loopback_linux_test.go
+9
-3
fuse/loopback_test.go
fuse/loopback_test.go
+11
-7
fuse/memnode_test.go
fuse/memnode_test.go
+21
-7
fuse/misc.go
fuse/misc.go
+0
-6
fuse/mount_test.go
fuse/mount_test.go
+30
-10
fuse/notify_test.go
fuse/notify_test.go
+21
-9
fuse/owner_test.go
fuse/owner_test.go
+16
-8
fuse/pressure_test.go
fuse/pressure_test.go
+3
-1
fuse/xattr_test.go
fuse/xattr_test.go
+6
-2
unionfs/autounion_test.go
unionfs/autounion_test.go
+81
-31
unionfs/unionfs_test.go
unionfs/unionfs_test.go
+427
-184
zipfs/multizip_test.go
zipfs/multizip_test.go
+27
-12
zipfs/zipfs_test.go
zipfs/zipfs_test.go
+21
-9
No files found.
fuse/cache_test.go
View file @
060980b2
...
...
@@ -28,9 +28,11 @@ func (fs *cacheFs) Open(name string, flags uint32, context *Context) (fuseFile F
}
func
setupCacheTest
()
(
string
,
*
PathNodeFs
,
func
())
{
func
setupCacheTest
(
t
*
testing
.
T
)
(
string
,
*
PathNodeFs
,
func
())
{
dir
,
err
:=
ioutil
.
TempDir
(
""
,
"go-fuse"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"TempDir failed: %v"
,
err
)
}
os
.
Mkdir
(
dir
+
"/mnt"
,
0755
)
os
.
Mkdir
(
dir
+
"/orig"
,
0755
)
...
...
@@ -39,7 +41,9 @@ func setupCacheTest() (string, *PathNodeFs, func()) {
}
pfs
:=
NewPathNodeFs
(
fs
,
nil
)
state
,
conn
,
err
:=
MountNodeFileSystem
(
dir
+
"/mnt"
,
pfs
,
nil
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"MountNodeFileSystem failed: %v"
,
err
)
}
state
.
Debug
=
VerboseTest
()
conn
.
Debug
=
VerboseTest
()
pfs
.
Debug
=
VerboseTest
()
...
...
@@ -54,26 +58,34 @@ func setupCacheTest() (string, *PathNodeFs, func()) {
}
func
TestCacheFs
(
t
*
testing
.
T
)
{
wd
,
pathfs
,
clean
:=
setupCacheTest
()
wd
,
pathfs
,
clean
:=
setupCacheTest
(
t
)
defer
clean
()
content1
:=
"hello"
content2
:=
"qqqq"
err
:=
ioutil
.
WriteFile
(
wd
+
"/orig/file.txt"
,
[]
byte
(
content1
),
0644
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"WriteFile failed: %v"
,
err
)
}
c
,
err
:=
ioutil
.
ReadFile
(
wd
+
"/mnt/file.txt"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"ReadFile failed: %v"
,
err
)
}
if
string
(
c
)
!=
"hello"
{
t
.
Fatalf
(
"expect 'hello' %q"
,
string
(
c
))
}
err
=
ioutil
.
WriteFile
(
wd
+
"/orig/file.txt"
,
[]
byte
(
content2
),
0644
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"WriteFile failed: %v"
,
err
)
}
c
,
err
=
ioutil
.
ReadFile
(
wd
+
"/mnt/file.txt"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"ReadFile failed: %v"
,
err
)
}
if
string
(
c
)
!=
"hello"
{
t
.
Fatalf
(
"Page cache skipped: expect 'hello' %q"
,
string
(
c
))
...
...
@@ -85,7 +97,9 @@ func TestCacheFs(t *testing.T) {
}
c
,
err
=
ioutil
.
ReadFile
(
wd
+
"/mnt/file.txt"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"ReadFile failed: %v"
,
err
)
}
if
string
(
c
)
!=
string
(
content2
)
{
t
.
Fatalf
(
"Mismatch after notify expect '%s' %q"
,
content2
,
string
(
c
))
}
...
...
@@ -121,18 +135,24 @@ func TestNonseekable(t *testing.T) {
fs
.
Length
=
200
*
1024
dir
,
err
:=
ioutil
.
TempDir
(
""
,
"go-fuse"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"failed: %v"
,
err
)
}
defer
os
.
RemoveAll
(
dir
)
nfs
:=
NewPathNodeFs
(
fs
,
nil
)
state
,
_
,
err
:=
MountNodeFileSystem
(
dir
,
nfs
,
nil
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"failed: %v"
,
err
)
}
state
.
Debug
=
VerboseTest
()
defer
state
.
Unmount
()
go
state
.
Loop
()
f
,
err
:=
os
.
Open
(
dir
+
"/file"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"failed: %v"
,
err
)
}
defer
f
.
Close
()
b
:=
make
([]
byte
,
200
)
...
...
@@ -144,7 +164,9 @@ func TestNonseekable(t *testing.T) {
func
TestGetAttrRace
(
t
*
testing
.
T
)
{
dir
,
err
:=
ioutil
.
TempDir
(
""
,
"go-fuse"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"failed: %v"
,
err
)
}
defer
os
.
RemoveAll
(
dir
)
os
.
Mkdir
(
dir
+
"/mnt"
,
0755
)
os
.
Mkdir
(
dir
+
"/orig"
,
0755
)
...
...
@@ -153,7 +175,9 @@ func TestGetAttrRace(t *testing.T) {
pfs
:=
NewPathNodeFs
(
fs
,
nil
)
state
,
conn
,
err
:=
MountNodeFileSystem
(
dir
+
"/mnt"
,
pfs
,
&
FileSystemOptions
{})
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"MountNodeFileSystem failed: %v"
,
err
)
}
state
.
Debug
=
VerboseTest
()
conn
.
Debug
=
VerboseTest
()
pfs
.
Debug
=
VerboseTest
()
...
...
fuse/copy_test.go
View file @
060980b2
...
...
@@ -8,10 +8,14 @@ import (
func
TestCopyFile
(
t
*
testing
.
T
)
{
d1
,
err
:=
ioutil
.
TempDir
(
""
,
"go-fuse"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"TempDir failed: %v"
,
err
)
}
defer
os
.
RemoveAll
(
d1
)
d2
,
err
:=
ioutil
.
TempDir
(
""
,
"go-fuse"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"TempDir failed: %v"
,
err
)
}
defer
os
.
RemoveAll
(
d2
)
fs1
:=
NewLoopbackFileSystem
(
d1
)
...
...
@@ -20,7 +24,9 @@ func TestCopyFile(t *testing.T) {
content1
:=
"blabla"
err
=
ioutil
.
WriteFile
(
d1
+
"/file"
,
[]
byte
(
content1
),
0644
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"WriteFile failed: %v"
,
err
)
}
code
:=
CopyFile
(
fs1
,
fs2
,
"file"
,
"file"
,
nil
)
if
!
code
.
Ok
()
{
...
...
@@ -35,7 +41,9 @@ func TestCopyFile(t *testing.T) {
content2
:=
"foobar"
err
=
ioutil
.
WriteFile
(
d2
+
"/file"
,
[]
byte
(
content2
),
0644
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"WriteFile failed: %v"
,
err
)
}
// Copy back: should overwrite.
code
=
CopyFile
(
fs2
,
fs1
,
"file"
,
"file"
,
nil
)
...
...
fuse/defaultread_test.go
View file @
060980b2
...
...
@@ -29,17 +29,21 @@ func (fs *DefaultReadFS) Open(name string, f uint32, context *Context) (File, St
return
&
DefaultFile
{},
OK
}
func
defaultReadTest
()
(
root
string
,
cleanup
func
())
{
func
defaultReadTest
(
t
*
testing
.
T
)
(
root
string
,
cleanup
func
())
{
fs
:=
&
DefaultReadFS
{}
var
err
error
dir
,
err
:=
ioutil
.
TempDir
(
""
,
"go-fuse"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"TempDir failed: %v"
,
err
)
}
pathfs
:=
NewPathNodeFs
(
fs
,
nil
)
state
,
_
,
err
:=
MountNodeFileSystem
(
dir
,
pathfs
,
nil
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"MountNodeFileSystem failed: %v"
,
err
)
}
state
.
Debug
=
VerboseTest
()
go
state
.
Loop
()
return
dir
,
func
()
{
state
.
Unmount
()
os
.
Remove
(
dir
)
...
...
@@ -47,7 +51,7 @@ func defaultReadTest() (root string, cleanup func()) {
}
func
TestDefaultRead
(
t
*
testing
.
T
)
{
root
,
clean
:=
defaultReadTest
()
root
,
clean
:=
defaultReadTest
(
t
)
defer
clean
()
_
,
err
:=
ioutil
.
ReadFile
(
root
+
"/file"
)
...
...
fuse/fsetattr_test.go
View file @
060980b2
...
...
@@ -132,10 +132,14 @@ func NewFile() *MutableDataFile {
func
setupFAttrTest
(
t
*
testing
.
T
,
fs
FileSystem
)
(
dir
string
,
clean
func
(),
sync
func
())
{
dir
,
err
:=
ioutil
.
TempDir
(
""
,
"go-fuse"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"TempDir failed: %v"
,
err
)
}
nfs
:=
NewPathNodeFs
(
fs
,
nil
)
state
,
_
,
err
:=
MountNodeFileSystem
(
dir
,
nfs
,
nil
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"MountNodeFileSystem failed: %v"
,
err
)
}
state
.
Debug
=
VerboseTest
()
go
state
.
Loop
()
...
...
@@ -163,10 +167,14 @@ func TestDataReadLarge(t *testing.T) {
content
:=
RandomData
(
385
*
1023
)
fn
:=
dir
+
"/file"
err
:=
ioutil
.
WriteFile
(
fn
,
[]
byte
(
content
),
0644
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"WriteFile failed: %v"
,
err
)
}
back
,
err
:=
ioutil
.
ReadFile
(
fn
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"ReadFile failed: %v"
,
err
)
}
CompareSlices
(
t
,
back
,
content
)
}
...
...
@@ -178,13 +186,19 @@ func TestFSetAttr(t *testing.T) {
fn
:=
dir
+
"/file"
f
,
err
:=
os
.
OpenFile
(
fn
,
os
.
O_CREATE
|
os
.
O_WRONLY
,
0755
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"OpenFile failed: %v"
,
err
)
}
defer
f
.
Close
()
fi
,
err
:=
f
.
Stat
()
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Stat failed: %v"
,
err
)
}
_
,
err
=
f
.
WriteString
(
"hello"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"WriteString failed: %v"
,
err
)
}
code
:=
syscall
.
Ftruncate
(
int
(
f
.
Fd
()),
3
)
if
code
!=
nil
{
...
...
@@ -197,14 +211,18 @@ func TestFSetAttr(t *testing.T) {
}
err
=
f
.
Chmod
(
024
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Chmod failed: %v"
,
err
)
}
sync
()
if
fs
.
file
.
Attr
.
Mode
&
07777
!=
024
{
t
.
Error
(
"chmod"
)
}
err
=
os
.
Chtimes
(
fn
,
time
.
Unix
(
0
,
100e3
),
time
.
Unix
(
0
,
101e3
))
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Chtimes failed: %v"
,
err
)
}
sync
()
if
fs
.
file
.
Attr
.
Atimensec
!=
100e3
||
fs
.
file
.
Attr
.
Mtimensec
!=
101e3
{
t
.
Errorf
(
"Utimens: atime %d != 100e3 mtime %d != 101e3"
,
...
...
@@ -212,7 +230,9 @@ func TestFSetAttr(t *testing.T) {
}
newFi
,
err
:=
f
.
Stat
()
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Stat failed: %v"
,
err
)
}
i1
:=
ToStatT
(
fi
)
.
Ino
i2
:=
ToStatT
(
newFi
)
.
Ino
if
i1
!=
i2
{
...
...
fuse/loopback_darwin_test.go
View file @
060980b2
package
fuse
import
(
"syscall"
"syscall"
)
func
clearStatfs
(
s
*
syscall
.
Statfs_t
)
{
...
...
fuse/loopback_linux_test.go
View file @
060980b2
...
...
@@ -14,13 +14,19 @@ func TestTouch(t *testing.T) {
contents
:=
[]
byte
{
1
,
2
,
3
}
err
:=
ioutil
.
WriteFile
(
ts
.
origFile
,
[]
byte
(
contents
),
0700
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"WriteFile failed: %v"
,
err
)
}
err
=
os
.
Chtimes
(
ts
.
mountFile
,
time
.
Unix
(
42
,
0
),
time
.
Unix
(
43
,
0
))
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Chtimes failed: %v"
,
err
)
}
var
stat
syscall
.
Stat_t
err
=
syscall
.
Lstat
(
ts
.
mountFile
,
&
stat
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Lstat failed: %v"
,
err
)
}
if
stat
.
Atim
.
Sec
!=
42
||
stat
.
Mtim
.
Sec
!=
43
{
t
.
Errorf
(
"Got wrong timestamps %v"
,
stat
)
}
...
...
fuse/loopback_test.go
View file @
060980b2
...
...
@@ -55,7 +55,9 @@ func NewTestCase(t *testing.T) *testCase {
var
err
error
me
.
tmpDir
,
err
=
ioutil
.
TempDir
(
""
,
"go-fuse"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"TempDir failed: %v"
,
err
)
}
me
.
orig
=
me
.
tmpDir
+
"/orig"
me
.
mnt
=
me
.
tmpDir
+
"/mnt"
...
...
@@ -99,7 +101,9 @@ func NewTestCase(t *testing.T) *testCase {
// Unmount and del.
func
(
tc
*
testCase
)
Cleanup
()
{
err
:=
tc
.
state
.
Unmount
()
CheckSuccess
(
err
)
if
err
!=
nil
{
tc
.
tester
.
Fatalf
(
"Unmount failed: %v"
,
err
)
}
os
.
RemoveAll
(
tc
.
tmpDir
)
}
...
...
@@ -126,17 +130,17 @@ func TestReadThrough(t *testing.T) {
content
:=
RandomData
(
125
)
err
:=
ioutil
.
WriteFile
(
ts
.
origFile
,
content
,
0700
)
if
err
!=
nil
{
t
.
Fatalf
(
" failed: %v"
,
err
)
t
.
Fatalf
(
"
WriteFile
failed: %v"
,
err
)
}
err
=
os
.
Chmod
(
ts
.
mountFile
,
os
.
FileMode
(
mode
))
if
err
!=
nil
{
t
.
Fatalf
(
" failed: %v"
,
err
)
t
.
Fatalf
(
"
Chmod
failed: %v"
,
err
)
}
fi
,
err
:=
os
.
Lstat
(
ts
.
mountFile
)
if
err
!=
nil
{
t
.
Fatalf
(
" failed: %v"
,
err
)
t
.
Fatalf
(
"
Lstat
failed: %v"
,
err
)
}
if
uint32
(
fi
.
Mode
()
.
Perm
())
!=
mode
{
t
.
Errorf
(
"Wrong mode %o != %o"
,
int
(
fi
.
Mode
()
.
Perm
()),
mode
)
...
...
@@ -145,7 +149,7 @@ func TestReadThrough(t *testing.T) {
// Open (for read), read.
f
,
err
:=
os
.
Open
(
ts
.
mountFile
)
if
err
!=
nil
{
t
.
Fatalf
(
" failed: %v"
,
err
)
t
.
Fatalf
(
"
Open
failed: %v"
,
err
)
}
defer
f
.
Close
()
...
...
@@ -992,7 +996,7 @@ func TestFallocate(t *testing.T) {
if
err
!=
nil
{
t
.
Fatalf
(
"Lstat failed: %v"
,
err
)
}
if
fi
.
Size
()
<
(
1024
+
4096
)
{
if
fi
.
Size
()
<
(
1024
+
4096
)
{
t
.
Fatalf
(
"fallocate should have changed file size. Got %d bytes"
,
fi
.
Size
())
}
...
...
fuse/memnode_test.go
View file @
060980b2
...
...
@@ -11,7 +11,9 @@ var _ = log.Println
func
setupMemNodeTest
(
t
*
testing
.
T
)
(
wd
string
,
fs
*
MemNodeFs
,
clean
func
())
{
tmp
,
err
:=
ioutil
.
TempDir
(
""
,
"go-fuse"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"TempDir failed: %v"
,
err
)
}
back
:=
tmp
+
"/backing"
os
.
Mkdir
(
back
,
0700
)
fs
=
NewMemNodeFs
(
back
)
...
...
@@ -46,7 +48,9 @@ func TestMemNodeFsWrite(t *testing.T) {
want
:=
"hello"
err
:=
ioutil
.
WriteFile
(
wd
+
"/test"
,
[]
byte
(
want
),
0644
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"WriteFile failed: %v"
,
err
)
}
content
,
err
:=
ioutil
.
ReadFile
(
wd
+
"/test"
)
if
string
(
content
)
!=
want
{
...
...
@@ -59,10 +63,14 @@ func TestMemNodeFs(t *testing.T) {
defer
clean
()
err
:=
ioutil
.
WriteFile
(
wd
+
"/test"
,
[]
byte
{
42
},
0644
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"WriteFile failed: %v"
,
err
)
}
fi
,
err
:=
os
.
Lstat
(
wd
+
"/test"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Lstat failed: %v"
,
err
)
}
if
fi
.
Size
()
!=
1
{
t
.
Errorf
(
"Size after write incorrect: got %d want 1"
,
fi
.
Size
())
}
...
...
@@ -78,14 +86,20 @@ func TestMemNodeSetattr(t *testing.T) {
defer
clean
()
f
,
err
:=
os
.
OpenFile
(
wd
+
"/test"
,
os
.
O_CREATE
|
os
.
O_WRONLY
,
0644
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"OpenFile failed: %v"
,
err
)
}
defer
f
.
Close
()
err
=
f
.
Truncate
(
4096
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Truncate failed: %v"
,
err
)
}
fi
,
err
:=
f
.
Stat
()
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Stat failed: %v"
,
err
)
}
if
fi
.
Size
()
!=
4096
{
t
.
Errorf
(
"Size should be 4096 after Truncate: %d"
,
fi
.
Size
())
}
...
...
fuse/misc.go
View file @
060980b2
...
...
@@ -71,12 +71,6 @@ func ModeToType(mode uint32) uint32 {
return
(
mode
&
0170000
)
>>
12
}
func
CheckSuccess
(
e
error
)
{
if
e
!=
nil
{
log
.
Panicf
(
"Unexpected error: %v"
,
e
)
}
}
// Thanks to Andrew Gerrand for this hack.
func
toSlice
(
dest
*
[]
byte
,
ptr
unsafe
.
Pointer
,
byteCount
uintptr
)
{
h
:=
(
*
reflect
.
SliceHeader
)(
unsafe
.
Pointer
(
dest
))
...
...
fuse/mount_test.go
View file @
060980b2
...
...
@@ -13,7 +13,9 @@ func TestMountOnExisting(t *testing.T) {
defer
ts
.
Cleanup
()
err
:=
os
.
Mkdir
(
ts
.
mnt
+
"/mnt"
,
0777
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Mkdir failed: %v"
,
err
)
}
nfs
:=
&
DefaultNodeFileSystem
{}
code
:=
ts
.
connector
.
Mount
(
ts
.
rootNode
(),
"mnt"
,
nfs
,
nil
)
if
code
!=
EBUSY
{
...
...
@@ -21,7 +23,9 @@ func TestMountOnExisting(t *testing.T) {
}
err
=
os
.
Remove
(
ts
.
mnt
+
"/mnt"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Remove failed: %v"
,
err
)
}
code
=
ts
.
connector
.
Mount
(
ts
.
rootNode
(),
"mnt"
,
nfs
,
nil
)
if
!
code
.
Ok
()
{
t
.
Fatal
(
"expect OK:"
,
code
)
...
...
@@ -60,7 +64,9 @@ func TestMountReaddir(t *testing.T) {
}
entries
,
err
:=
ioutil
.
ReadDir
(
ts
.
mnt
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"ReadDir failed: %v"
,
err
)
}
if
len
(
entries
)
!=
1
||
entries
[
0
]
.
Name
()
!=
"mnt"
{
t
.
Error
(
"wrong readdir result"
,
entries
)
}
...
...
@@ -72,7 +78,9 @@ func TestRecursiveMount(t *testing.T) {
defer
ts
.
Cleanup
()
err
:=
ioutil
.
WriteFile
(
ts
.
orig
+
"/hello.txt"
,
[]
byte
(
"blabla"
),
0644
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"WriteFile failed: %v"
,
err
)
}
fs
:=
NewPathNodeFs
(
NewLoopbackFileSystem
(
ts
.
orig
),
nil
)
code
:=
ts
.
connector
.
Mount
(
ts
.
rootNode
(),
"mnt"
,
fs
,
nil
)
...
...
@@ -82,12 +90,18 @@ func TestRecursiveMount(t *testing.T) {
submnt
:=
ts
.
mnt
+
"/mnt"
_
,
err
=
os
.
Lstat
(
submnt
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Lstat failed: %v"
,
err
)
}
_
,
err
=
os
.
Lstat
(
filepath
.
Join
(
submnt
,
"hello.txt"
))
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Lstat failed: %v"
,
err
)
}
f
,
err
:=
os
.
Open
(
filepath
.
Join
(
submnt
,
"hello.txt"
))
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Open failed: %v"
,
err
)
}
t
.
Log
(
"Attempting unmount, should fail"
)
code
=
ts
.
pathFs
.
Unmount
(
"mnt"
)
if
code
!=
EBUSY
{
...
...
@@ -116,15 +130,21 @@ func TestDeletedUnmount(t *testing.T) {
t
.
Fatal
(
"Mount error"
,
code
)
}
f
,
err
:=
os
.
Create
(
filepath
.
Join
(
submnt
,
"hello.txt"
))
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Create failed: %v"
,
err
)
}
t
.
Log
(
"Removing"
)
err
=
os
.
Remove
(
filepath
.
Join
(
submnt
,
"hello.txt"
))
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Remove failed: %v"
,
err
)
}
t
.
Log
(
"Removing"
)
_
,
err
=
f
.
Write
([]
byte
(
"bla"
))
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Write failed: %v"
,
err
)
}
code
=
ts
.
pathFs
.
Unmount
(
"mnt"
)
if
code
!=
EBUSY
{
...
...
fuse/notify_test.go
View file @
060980b2
...
...
@@ -41,12 +41,14 @@ type NotifyTest struct {
state
*
MountState
}
func
NewNotifyTest
()
*
NotifyTest
{
func
NewNotifyTest
(
t
*
testing
.
T
)
*
NotifyTest
{
me
:=
&
NotifyTest
{}
me
.
fs
=
&
NotifyFs
{}
var
err
error
me
.
dir
,
err
=
ioutil
.
TempDir
(
""
,
"go-fuse"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"TempDir failed: %v"
,
err
)
}
entryTtl
:=
100
*
time
.
Millisecond
opts
:=
&
FileSystemOptions
{
EntryTimeout
:
entryTtl
,
...
...
@@ -56,7 +58,9 @@ func NewNotifyTest() *NotifyTest {
me
.
pathfs
=
NewPathNodeFs
(
me
.
fs
,
nil
)
me
.
state
,
me
.
connector
,
err
=
MountNodeFileSystem
(
me
.
dir
,
me
.
pathfs
,
opts
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"MountNodeFileSystem failed: %v"
,
err
)
}
me
.
state
.
Debug
=
VerboseTest
()
go
me
.
state
.
Loop
()
...
...
@@ -71,7 +75,7 @@ func (t *NotifyTest) Clean() {
}
func
TestInodeNotify
(
t
*
testing
.
T
)
{
test
:=
NewNotifyTest
()
test
:=
NewNotifyTest
(
t
)
defer
test
.
Clean
()
fs
:=
test
.
fs
...
...
@@ -81,7 +85,9 @@ func TestInodeNotify(t *testing.T) {
test
.
state
.
ThreadSanitizerSync
()
fi
,
err
:=
os
.
Lstat
(
dir
+
"/file"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Lstat failed: %v"
,
err
)
}
if
fi
.
Mode
()
&
os
.
ModeType
!=
0
||
fi
.
Size
()
!=
42
{
t
.
Error
(
fi
)
}
...
...
@@ -90,7 +96,9 @@ func TestInodeNotify(t *testing.T) {
fs
.
size
=
666
fi
,
err
=
os
.
Lstat
(
dir
+
"/file"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Lstat failed: %v"
,
err
)
}
if
fi
.
Mode
()
&
os
.
ModeType
!=
0
||
fi
.
Size
()
==
666
{
t
.
Error
(
fi
)
}
...
...
@@ -101,14 +109,16 @@ func TestInodeNotify(t *testing.T) {
}
fi
,
err
=
os
.
Lstat
(
dir
+
"/file"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Lstat failed: %v"
,
err
)
}
if
fi
.
Mode
()
&
os
.
ModeType
!=
0
||
fi
.
Size
()
!=
666
{
t
.
Error
(
fi
)
}
}
func
TestEntryNotify
(
t
*
testing
.
T
)
{
test
:=
NewNotifyTest
()
test
:=
NewNotifyTest
(
t
)
defer
test
.
Clean
()
dir
:=
test
.
dir
...
...
@@ -135,5 +145,7 @@ func TestEntryNotify(t *testing.T) {
}
fi
,
err
:=
os
.
Lstat
(
fn
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Lstat failed: %v"
,
err
)
}
}
fuse/owner_test.go
View file @
060980b2
...
...
@@ -27,13 +27,15 @@ func (fs *ownerFs) GetAttr(name string, context *Context) (*Attr, Status) {
return
a
,
OK
}
func
setupOwnerTest
(
opts
*
FileSystemOptions
)
(
workdir
string
,
cleanup
func
())
{
func
setupOwnerTest
(
t
*
testing
.
T
,
opts
*
FileSystemOptions
)
(
workdir
string
,
cleanup
func
())
{
wd
,
err
:=
ioutil
.
TempDir
(
""
,
"go-fuse"
)
fs
:=
&
ownerFs
{}
nfs
:=
NewPathNodeFs
(
fs
,
nil
)
state
,
_
,
err
:=
MountNodeFileSystem
(
wd
,
nfs
,
opts
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"MountNodeFileSystem failed: %v"
,
err
)
}
go
state
.
Loop
()
return
wd
,
func
()
{
state
.
Unmount
()
...
...
@@ -42,12 +44,14 @@ func setupOwnerTest(opts *FileSystemOptions) (workdir string, cleanup func()) {
}
func
TestOwnerDefault
(
t
*
testing
.
T
)
{
wd
,
cleanup
:=
setupOwnerTest
(
NewFileSystemOptions
())
wd
,
cleanup
:=
setupOwnerTest
(
t
,
NewFileSystemOptions
())
defer
cleanup
()
var
stat
syscall
.
Stat_t
err
:=
syscall
.
Lstat
(
wd
+
"/foo"
,
&
stat
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Lstat failed: %v"
,
err
)
}
if
int
(
stat
.
Uid
)
!=
os
.
Getuid
()
||
int
(
stat
.
Gid
)
!=
os
.
Getgid
()
{
t
.
Fatal
(
"Should use current uid for mount"
)
...
...
@@ -55,12 +59,14 @@ func TestOwnerDefault(t *testing.T) {
}
func
TestOwnerRoot
(
t
*
testing
.
T
)
{
wd
,
cleanup
:=
setupOwnerTest
(
&
FileSystemOptions
{})
wd
,
cleanup
:=
setupOwnerTest
(
t
,
&
FileSystemOptions
{})
defer
cleanup
()
var
st
syscall
.
Stat_t
err
:=
syscall
.
Lstat
(
wd
+
"/foo"
,
&
st
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Lstat failed: %v"
,
err
)
}
if
st
.
Uid
!=
_RANDOM_OWNER
||
st
.
Gid
!=
_RANDOM_OWNER
{
t
.
Fatal
(
"Should use FS owner uid"
)
...
...
@@ -68,12 +74,14 @@ func TestOwnerRoot(t *testing.T) {
}
func
TestOwnerOverride
(
t
*
testing
.
T
)
{
wd
,
cleanup
:=
setupOwnerTest
(
&
FileSystemOptions
{
Owner
:
&
Owner
{
42
,
43
}})
wd
,
cleanup
:=
setupOwnerTest
(
t
,
&
FileSystemOptions
{
Owner
:
&
Owner
{
42
,
43
}})
defer
cleanup
()
var
stat
syscall
.
Stat_t
err
:=
syscall
.
Lstat
(
wd
+
"/foo"
,
&
stat
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Lstat failed: %v"
,
err
)
}
if
stat
.
Uid
!=
42
||
stat
.
Gid
!=
43
{
t
.
Fatal
(
"Should use current uid for mount"
)
...
...
fuse/pressure_test.go
View file @
060980b2
...
...
@@ -42,7 +42,9 @@ func TestMemoryPressure(t *testing.T) {
}
dir
,
err
:=
ioutil
.
TempDir
(
""
,
"go-fuse"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"TempDir failed: %v"
,
err
)
}
nfs
:=
NewPathNodeFs
(
fs
,
nil
)
o
:=
&
FileSystemOptions
{
PortableInodes
:
true
}
...
...
fuse/xattr_test.go
View file @
060980b2
...
...
@@ -104,12 +104,16 @@ func xattrTestCase(t *testing.T, nm string) (mountPoint string, cleanup func())
xfs
:=
NewXAttrFs
(
nm
,
xattrGolden
)
xfs
.
tester
=
t
mountPoint
,
err
:=
ioutil
.
TempDir
(
""
,
"go-fuse"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"TempDir failed: %v"
,
err
)
}
defer
os
.
RemoveAll
(
mountPoint
)
nfs
:=
NewPathNodeFs
(
xfs
,
nil
)
state
,
_
,
err
:=
MountNodeFileSystem
(
mountPoint
,
nfs
,
nil
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"TempDir failed: %v"
,
err
)
}
state
.
Debug
=
VerboseTest
()
go
state
.
Loop
()
...
...
unionfs/autounion_test.go
View file @
060980b2
...
...
@@ -13,8 +13,6 @@ import (
var
_
=
fmt
.
Print
var
_
=
log
.
Print
var
CheckSuccess
=
fuse
.
CheckSuccess
const
entryTtl
=
100
*
time
.
Millisecond
var
testAOpts
=
AutoUnionFsOptions
{
...
...
@@ -27,29 +25,39 @@ var testAOpts = AutoUnionFsOptions{
HideReadonly
:
true
,
}
func
WriteFile
(
name
string
,
contents
string
)
{
func
WriteFile
(
t
*
testing
.
T
,
name
string
,
contents
string
)
{
err
:=
ioutil
.
WriteFile
(
name
,
[]
byte
(
contents
),
0644
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"WriteFile failed: %v"
,
err
)
}
}
func
setup
(
t
*
testing
.
T
)
(
workdir
string
,
cleanup
func
())
{
wd
,
_
:=
ioutil
.
TempDir
(
""
,
""
)
err
:=
os
.
Mkdir
(
wd
+
"/mnt"
,
0700
)
fuse
.
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Mkdir failed: %v"
,
err
)
}
err
=
os
.
Mkdir
(
wd
+
"/store"
,
0700
)
fuse
.
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Mkdir failed: %v"
,
err
)
}
os
.
Mkdir
(
wd
+
"/ro"
,
0700
)
fuse
.
CheckSuccess
(
err
)
WriteFile
(
wd
+
"/ro/file1"
,
"file1"
)
WriteFile
(
wd
+
"/ro/file2"
,
"file2"
)
if
err
!=
nil
{
t
.
Fatalf
(
"Mkdir failed: %v"
,
err
)
}
WriteFile
(
t
,
wd
+
"/ro/file1"
,
"file1"
)
WriteFile
(
t
,
wd
+
"/ro/file2"
,
"file2"
)
fs
:=
NewAutoUnionFs
(
wd
+
"/store"
,
testAOpts
)
nfs
:=
fuse
.
NewPathNodeFs
(
fs
,
nil
)
state
,
conn
,
err
:=
fuse
.
MountNodeFileSystem
(
wd
+
"/mnt"
,
nfs
,
&
testAOpts
.
FileSystemOptions
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"MountNodeFileSystem failed: %v"
,
err
)
}
state
.
Debug
=
fuse
.
VerboseTest
()
conn
.
Debug
=
fuse
.
VerboseTest
()
go
state
.
Loop
()
...
...
@@ -65,7 +73,9 @@ func TestDebug(t *testing.T) {
defer
clean
()
c
,
err
:=
ioutil
.
ReadFile
(
wd
+
"/mnt/status/debug"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"ReadFile failed: %v"
,
err
)
}
if
len
(
c
)
==
0
{
t
.
Fatal
(
"No debug found."
)
}
...
...
@@ -77,7 +87,9 @@ func TestVersion(t *testing.T) {
defer
clean
()
c
,
err
:=
ioutil
.
ReadFile
(
wd
+
"/mnt/status/gounionfs_version"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"ReadFile failed: %v"
,
err
)
}
if
len
(
c
)
==
0
{
t
.
Fatal
(
"No version found."
)
}
...
...
@@ -89,25 +101,37 @@ func TestAutoFsSymlink(t *testing.T) {
defer
clean
()
err
:=
os
.
Mkdir
(
wd
+
"/store/backing1"
,
0755
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Mkdir failed: %v"
,
err
)
}
err
=
os
.
Symlink
(
wd
+
"/ro"
,
wd
+
"/store/backing1/READONLY"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Symlink failed: %v"
,
err
)
}
err
=
os
.
Symlink
(
wd
+
"/store/backing1"
,
wd
+
"/mnt/config/manual1"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Symlink failed: %v"
,
err
)
}
fi
,
err
:=
os
.
Lstat
(
wd
+
"/mnt/manual1/file1"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Lstat failed: %v"
,
err
)
}
entries
,
err
:=
ioutil
.
ReadDir
(
wd
+
"/mnt"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"ReadDir failed: %v"
,
err
)
}
if
len
(
entries
)
!=
3
{
t
.
Error
(
"readdir mismatch"
,
entries
)
}
err
=
os
.
Remove
(
wd
+
"/mnt/config/manual1"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Remove failed: %v"
,
err
)
}
scan
:=
wd
+
"/mnt/config/"
+
_SCAN_CONFIG
err
=
ioutil
.
WriteFile
(
scan
,
[]
byte
(
"something"
),
0644
)
...
...
@@ -121,10 +145,14 @@ func TestAutoFsSymlink(t *testing.T) {
}
_
,
err
=
ioutil
.
ReadDir
(
wd
+
"/mnt/config"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"ReadDir failed: %v"
,
err
)
}
_
,
err
=
os
.
Lstat
(
wd
+
"/mnt/backing1/file1"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Lstat failed: %v"
,
err
)
}
}
func
TestDetectSymlinkedDirectories
(
t
*
testing
.
T
)
{
...
...
@@ -132,13 +160,19 @@ func TestDetectSymlinkedDirectories(t *testing.T) {
defer
clean
()
err
:=
os
.
Mkdir
(
wd
+
"/backing1"
,
0755
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Mkdir failed: %v"
,
err
)
}
err
=
os
.
Symlink
(
wd
+
"/ro"
,
wd
+
"/backing1/READONLY"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Symlink failed: %v"
,
err
)
}
err
=
os
.
Symlink
(
wd
+
"/backing1"
,
wd
+
"/store/backing1"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Symlink failed: %v"
,
err
)
}
scan
:=
wd
+
"/mnt/config/"
+
_SCAN_CONFIG
err
=
ioutil
.
WriteFile
(
scan
,
[]
byte
(
"something"
),
0644
)
...
...
@@ -147,7 +181,9 @@ func TestDetectSymlinkedDirectories(t *testing.T) {
}
_
,
err
=
os
.
Lstat
(
wd
+
"/mnt/backing1"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Lstat failed: %v"
,
err
)
}
}
func
TestExplicitScan
(
t
*
testing
.
T
)
{
...
...
@@ -155,9 +191,13 @@ func TestExplicitScan(t *testing.T) {
defer
clean
()
err
:=
os
.
Mkdir
(
wd
+
"/store/backing1"
,
0755
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Mkdir failed: %v"
,
err
)
}
os
.
Symlink
(
wd
+
"/ro"
,
wd
+
"/store/backing1/READONLY"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Symlink failed: %v"
,
err
)
}
fi
,
_
:=
os
.
Lstat
(
wd
+
"/mnt/backing1"
)
if
fi
!=
nil
{
...
...
@@ -186,17 +226,27 @@ func TestCreationChecks(t *testing.T) {
defer
clean
()
err
:=
os
.
Mkdir
(
wd
+
"/store/foo"
,
0755
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Mkdir failed: %v"
,
err
)
}
os
.
Symlink
(
wd
+
"/ro"
,
wd
+
"/store/foo/READONLY"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Symlink failed: %v"
,
err
)
}
err
=
os
.
Mkdir
(
wd
+
"/store/ws2"
,
0755
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Mkdir failed: %v"
,
err
)
}
os
.
Symlink
(
wd
+
"/ro"
,
wd
+
"/store/ws2/READONLY"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Symlink failed: %v"
,
err
)
}
err
=
os
.
Symlink
(
wd
+
"/store/foo"
,
wd
+
"/mnt/config/bar"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Symlink failed: %v"
,
err
)
}
err
=
os
.
Symlink
(
wd
+
"/store/foo"
,
wd
+
"/mnt/config/foo"
)
code
:=
fuse
.
ToStatus
(
err
)
...
...
unionfs/unionfs_test.go
View file @
060980b2
...
...
@@ -31,14 +31,16 @@ var testOpts = UnionFsOptions{
HiddenFiles
:
[]
string
{
"hidden"
},
}
func
freezeRo
(
dir
string
)
{
func
freezeRo
(
t
*
testing
.
T
,
dir
string
)
{
err
:=
filepath
.
Walk
(
dir
,
func
(
path
string
,
fi
os
.
FileInfo
,
err
error
)
error
{
newMode
:=
uint32
(
fi
.
Mode
()
.
Perm
())
&^
0222
return
os
.
Chmod
(
path
,
os
.
FileMode
(
newMode
))
})
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Walk failed: %v"
,
err
)
}
}
// Creates 3 directories on a temporary dir: /mnt with the overlayed
...
...
@@ -49,13 +51,19 @@ func setupUfs(t *testing.T) (workdir string, cleanup func()) {
wd
,
_
:=
ioutil
.
TempDir
(
""
,
""
)
err
:=
os
.
Mkdir
(
wd
+
"/mnt"
,
0700
)
fuse
.
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Mkdir failed: %v"
,
err
)
}
err
=
os
.
Mkdir
(
wd
+
"/rw"
,
0700
)
fuse
.
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Mkdir failed: %v"
,
err
)
}
os
.
Mkdir
(
wd
+
"/ro"
,
0700
)
fuse
.
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Mkdir failed: %v"
,
err
)
}
var
fses
[]
fuse
.
FileSystem
fses
=
append
(
fses
,
fuse
.
NewLoopbackFileSystem
(
wd
+
"/rw"
))
...
...
@@ -74,7 +82,9 @@ func setupUfs(t *testing.T) (workdir string, cleanup func()) {
pathfs
:=
fuse
.
NewPathNodeFs
(
ufs
,
&
fuse
.
PathNodeFsOptions
{
ClientInodes
:
true
})
state
,
conn
,
err
:=
fuse
.
MountNodeFileSystem
(
wd
+
"/mnt"
,
pathfs
,
opts
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"MountNodeFileSystem failed: %v"
,
err
)
}
conn
.
Debug
=
fuse
.
VerboseTest
()
state
.
Debug
=
fuse
.
VerboseTest
()
go
state
.
Loop
()
...
...
@@ -85,26 +95,29 @@ func setupUfs(t *testing.T) (workdir string, cleanup func()) {
}
}
func
writeToFile
(
path
string
,
contents
string
)
{
err
:=
ioutil
.
WriteFile
(
path
,
[]
byte
(
contents
),
0644
)
CheckSuccess
(
err
)
}
func
readFromFile
(
path
string
)
string
{
func
readFromFile
(
t
*
testing
.
T
,
path
string
)
string
{
b
,
err
:=
ioutil
.
ReadFile
(
path
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"ReadFile failed: %v"
,
err
)
}
return
string
(
b
)
}
func
dirNames
(
path
string
)
map
[
string
]
bool
{
func
dirNames
(
t
*
testing
.
T
,
path
string
)
map
[
string
]
bool
{
f
,
err
:=
os
.
Open
(
path
)
fuse
.
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Open failed: %v"
,
err
)
}
result
:=
make
(
map
[
string
]
bool
)
names
,
err
:=
f
.
Readdirnames
(
-
1
)
fuse
.
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Readdirnames failed: %v"
,
err
)
}
err
=
f
.
Close
()
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Close failed: %v"
,
err
)
}
for
_
,
nm
:=
range
names
{
result
[
nm
]
=
true
...
...
@@ -138,23 +151,24 @@ func fileExists(path string) bool {
return
err
==
nil
&&
f
!=
nil
}
func
remove
(
path
string
)
{
err
:=
os
.
Remove
(
path
)
fuse
.
CheckSuccess
(
err
)
}
func
TestUnionFsAutocreateDeletionDir
(
t
*
testing
.
T
)
{
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
err
:=
os
.
Remove
(
wd
+
"/rw/DELETIONS"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Remove failed: %v"
,
err
)
}
err
=
os
.
Mkdir
(
wd
+
"/mnt/dir"
,
0755
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Mkdir failed: %v"
,
err
)
}
_
,
err
=
ioutil
.
ReadDir
(
wd
+
"/mnt/dir"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"ReadDir failed: %v"
,
err
)
}
}
func
TestUnionFsSymlink
(
t
*
testing
.
T
)
{
...
...
@@ -162,10 +176,14 @@ func TestUnionFsSymlink(t *testing.T) {
defer
clean
()
err
:=
os
.
Symlink
(
"/foobar"
,
wd
+
"/mnt/link"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Symlink failed: %v"
,
err
)
}
val
,
err
:=
os
.
Readlink
(
wd
+
"/mnt/link"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Readlink failed: %v"
,
err
)
}
if
val
!=
"/foobar"
{
t
.
Errorf
(
"symlink mismatch: %v"
,
val
)
...
...
@@ -177,22 +195,30 @@ func TestUnionFsSymlinkPromote(t *testing.T) {
defer
clean
()
err
:=
os
.
Mkdir
(
wd
+
"/ro/subdir"
,
0755
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Mkdir failed: %v"
,
err
)
}
err
=
os
.
Symlink
(
"/foobar"
,
wd
+
"/mnt/subdir/link"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Symlink failed: %v"
,
err
)
}
}
func
TestUnionFsChtimes
(
t
*
testing
.
T
)
{
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
writeToFile
(
wd
+
"/ro/file"
,
"a"
)
WriteFile
(
t
,
wd
+
"/ro/file"
,
"a"
)
err
:=
os
.
Chtimes
(
wd
+
"/ro/file"
,
time
.
Unix
(
42
,
0
),
time
.
Unix
(
43
,
0
))
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Chtimes failed: %v"
,
err
)
}
err
=
os
.
Chtimes
(
wd
+
"/mnt/file"
,
time
.
Unix
(
82
,
0
),
time
.
Unix
(
83
,
0
))
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Chtimes failed: %v"
,
err
)
}
fi
,
err
:=
os
.
Lstat
(
wd
+
"/mnt/file"
)
stat
:=
fuse
.
ToStatT
(
fi
)
...
...
@@ -207,12 +233,16 @@ func TestUnionFsChmod(t *testing.T) {
ro_fn
:=
wd
+
"/ro/file"
m_fn
:=
wd
+
"/mnt/file"
writeToFile
(
ro_fn
,
"a"
)
WriteFile
(
t
,
ro_fn
,
"a"
)
err
:=
os
.
Chmod
(
m_fn
,
00070
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Chmod failed: %v"
,
err
)
}
fi
,
err
:=
os
.
Lstat
(
m_fn
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Lstat failed: %v"
,
err
)
}
if
fi
.
Mode
()
&
07777
!=
00270
{
t
.
Errorf
(
"Unexpected mode found: %o"
,
uint32
(
fi
.
Mode
()
.
Perm
()))
}
...
...
@@ -228,7 +258,7 @@ func TestUnionFsChown(t *testing.T) {
ro_fn
:=
wd
+
"/ro/file"
m_fn
:=
wd
+
"/mnt/file"
writeToFile
(
ro_fn
,
"a"
)
WriteFile
(
t
,
ro_fn
,
"a"
)
err
:=
os
.
Chown
(
m_fn
,
0
,
0
)
code
:=
fuse
.
ToStatus
(
err
)
...
...
@@ -241,26 +271,32 @@ func TestUnionFsDelete(t *testing.T) {
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
writeToFile
(
wd
+
"/ro/file"
,
"a"
)
WriteFile
(
t
,
wd
+
"/ro/file"
,
"a"
)
_
,
err
:=
os
.
Lstat
(
wd
+
"/mnt/file"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Lstat failed: %v"
,
err
)
}
err
=
os
.
Remove
(
wd
+
"/mnt/file"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Remove failed: %v"
,
err
)
}
_
,
err
=
os
.
Lstat
(
wd
+
"/mnt/file"
)
if
err
==
nil
{
t
.
Fatal
(
"should have disappeared."
)
}
delPath
:=
wd
+
"/rw/"
+
testOpts
.
DeletionDirName
names
:=
dirNames
(
delPath
)
names
:=
dirNames
(
t
,
delPath
)
if
len
(
names
)
!=
1
{
t
.
Fatal
(
"Should have 1 deletion"
,
names
)
}
for
k
:=
range
names
{
c
,
err
:=
ioutil
.
ReadFile
(
delPath
+
"/"
+
k
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"ReadFile failed: %v"
,
err
)
}
if
string
(
c
)
!=
"file"
{
t
.
Fatal
(
"content mismatch"
,
string
(
c
))
}
...
...
@@ -271,58 +307,65 @@ func TestUnionFsBasic(t *testing.T) {
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
writeToFile
(
wd
+
"/rw/rw"
,
"a"
)
writeToFile
(
wd
+
"/ro/ro1"
,
"a"
)
writeToFile
(
wd
+
"/ro/ro2"
,
"b"
)
WriteFile
(
t
,
wd
+
"/rw/rw"
,
"a"
)
WriteFile
(
t
,
wd
+
"/ro/ro1"
,
"a"
)
WriteFile
(
t
,
wd
+
"/ro/ro2"
,
"b"
)
names
:=
dirNames
(
wd
+
"/mnt"
)
names
:=
dirNames
(
t
,
wd
+
"/mnt"
)
expected
:=
map
[
string
]
bool
{
"rw"
:
true
,
"ro1"
:
true
,
"ro2"
:
true
,
}
checkMapEq
(
t
,
names
,
expected
)
writeToFile
(
wd
+
"/mnt/new"
,
"new contents"
)
WriteFile
(
t
,
wd
+
"/mnt/new"
,
"new contents"
)
if
!
fileExists
(
wd
+
"/rw/new"
)
{
t
.
Errorf
(
"missing file in rw layer"
,
names
)
}
contents
:=
readFromFile
(
wd
+
"/mnt/new"
)
contents
:=
readFromFile
(
t
,
wd
+
"/mnt/new"
)
if
contents
!=
"new contents"
{
t
.
Errorf
(
"read mismatch: '%v'"
,
contents
)
}
writeToFile
(
wd
+
"/mnt/ro1"
,
"promote me"
)
WriteFile
(
t
,
wd
+
"/mnt/ro1"
,
"promote me"
)
if
!
fileExists
(
wd
+
"/rw/ro1"
)
{
t
.
Errorf
(
"missing file in rw layer"
,
names
)
}
remove
(
wd
+
"/mnt/new"
)
names
=
dirNames
(
wd
+
"/mnt"
)
err
:=
os
.
Remove
(
wd
+
"/mnt/new"
)
if
err
!=
nil
{
t
.
Fatalf
(
"Remove failed: %v"
,
err
)
}
names
=
dirNames
(
t
,
wd
+
"/mnt"
)
checkMapEq
(
t
,
names
,
map
[
string
]
bool
{
"rw"
:
true
,
"ro1"
:
true
,
"ro2"
:
true
,
})
names
=
dirNames
(
wd
+
"/rw"
)
names
=
dirNames
(
t
,
wd
+
"/rw"
)
checkMapEq
(
t
,
names
,
map
[
string
]
bool
{
testOpts
.
DeletionDirName
:
true
,
"rw"
:
true
,
"ro1"
:
true
,
})
names
=
dirNames
(
wd
+
"/rw/"
+
testOpts
.
DeletionDirName
)
names
=
dirNames
(
t
,
wd
+
"/rw/"
+
testOpts
.
DeletionDirName
)
if
len
(
names
)
!=
0
{
t
.
Errorf
(
"Expected 0 entry in %v"
,
names
)
}
remove
(
wd
+
"/mnt/ro1"
)
names
=
dirNames
(
wd
+
"/mnt"
)
err
=
os
.
Remove
(
wd
+
"/mnt/ro1"
)
if
err
!=
nil
{
t
.
Fatalf
(
"Remove failed: %v"
,
err
)
}
names
=
dirNames
(
t
,
wd
+
"/mnt"
)
checkMapEq
(
t
,
names
,
map
[
string
]
bool
{
"rw"
:
true
,
"ro2"
:
true
,
})
names
=
dirNames
(
wd
+
"/rw"
)
names
=
dirNames
(
t
,
wd
+
"/rw"
)
checkMapEq
(
t
,
names
,
map
[
string
]
bool
{
"rw"
:
true
,
testOpts
.
DeletionDirName
:
true
,
})
names
=
dirNames
(
wd
+
"/rw/"
+
testOpts
.
DeletionDirName
)
names
=
dirNames
(
t
,
wd
+
"/rw/"
+
testOpts
.
DeletionDirName
)
if
len
(
names
)
!=
1
{
t
.
Errorf
(
"Expected 1 entry in %v"
,
names
)
}
...
...
@@ -333,9 +376,11 @@ func TestUnionFsPromote(t *testing.T) {
defer
clean
()
err
:=
os
.
Mkdir
(
wd
+
"/ro/subdir"
,
0755
)
CheckSuccess
(
err
)
writeToFile
(
wd
+
"/ro/subdir/file"
,
"content"
)
writeToFile
(
wd
+
"/mnt/subdir/file"
,
"other-content"
)
if
err
!=
nil
{
t
.
Fatalf
(
"Mkdir failed: %v"
,
err
)
}
WriteFile
(
t
,
wd
+
"/ro/subdir/file"
,
"content"
)
WriteFile
(
t
,
wd
+
"/mnt/subdir/file"
,
"other-content"
)
}
func
TestUnionFsCreate
(
t
*
testing
.
T
)
{
...
...
@@ -343,22 +388,30 @@ func TestUnionFsCreate(t *testing.T) {
defer
clean
()
err
:=
os
.
MkdirAll
(
wd
+
"/ro/subdir/sub2"
,
0755
)
CheckSuccess
(
err
)
writeToFile
(
wd
+
"/mnt/subdir/sub2/file"
,
"other-content"
)
if
err
!=
nil
{
t
.
Fatalf
(
"MkdirAll failed: %v"
,
err
)
}
WriteFile
(
t
,
wd
+
"/mnt/subdir/sub2/file"
,
"other-content"
)
_
,
err
=
os
.
Lstat
(
wd
+
"/mnt/subdir/sub2/file"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Lstat failed: %v"
,
err
)
}
}
func
TestUnionFsOpenUndeletes
(
t
*
testing
.
T
)
{
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
writeToFile
(
wd
+
"/ro/file"
,
"X"
)
WriteFile
(
t
,
wd
+
"/ro/file"
,
"X"
)
err
:=
os
.
Remove
(
wd
+
"/mnt/file"
)
CheckSuccess
(
err
)
writeToFile
(
wd
+
"/mnt/file"
,
"X"
)
if
err
!=
nil
{
t
.
Fatalf
(
"Remove failed: %v"
,
err
)
}
WriteFile
(
t
,
wd
+
"/mnt/file"
,
"X"
)
_
,
err
=
os
.
Lstat
(
wd
+
"/mnt/file"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Lstat failed: %v"
,
err
)
}
}
func
TestUnionFsMkdir
(
t
*
testing
.
T
)
{
...
...
@@ -367,10 +420,14 @@ func TestUnionFsMkdir(t *testing.T) {
dirname
:=
wd
+
"/mnt/subdir"
err
:=
os
.
Mkdir
(
dirname
,
0755
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Mkdir failed: %v"
,
err
)
}
err
=
os
.
Remove
(
dirname
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Remove failed: %v"
,
err
)
}
}
func
TestUnionFsMkdirPromote
(
t
*
testing
.
T
)
{
...
...
@@ -379,12 +436,18 @@ func TestUnionFsMkdirPromote(t *testing.T) {
dirname
:=
wd
+
"/ro/subdir/subdir2"
err
:=
os
.
MkdirAll
(
dirname
,
0755
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"MkdirAll failed: %v"
,
err
)
}
err
=
os
.
Mkdir
(
wd
+
"/mnt/subdir/subdir2/dir3"
,
0755
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Mkdir failed: %v"
,
err
)
}
fi
,
_
:=
os
.
Lstat
(
wd
+
"/rw/subdir/subdir2/dir3"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Lstat failed: %v"
,
err
)
}
if
fi
==
nil
||
!
fi
.
IsDir
()
{
t
.
Error
(
"is not a directory: "
,
fi
)
}
...
...
@@ -395,14 +458,20 @@ func TestUnionFsRmdirMkdir(t *testing.T) {
defer
clean
()
err
:=
os
.
Mkdir
(
wd
+
"/ro/subdir"
,
0755
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Mkdir failed: %v"
,
err
)
}
dirname
:=
wd
+
"/mnt/subdir"
err
=
os
.
Remove
(
dirname
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Remove failed: %v"
,
err
)
}
err
=
os
.
Mkdir
(
dirname
,
0755
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Mkdir failed: %v"
,
err
)
}
}
func
TestUnionFsRename
(
t
*
testing
.
T
)
{
...
...
@@ -427,20 +496,22 @@ func TestUnionFsRename(t *testing.T) {
t
.
Log
(
"Config"
,
i
,
c
)
wd
,
clean
:=
setupUfs
(
t
)
if
c
.
f1_ro
{
writeToFile
(
wd
+
"/ro/file1"
,
"c1"
)
WriteFile
(
t
,
wd
+
"/ro/file1"
,
"c1"
)
}
if
c
.
f1_rw
{
writeToFile
(
wd
+
"/rw/file1"
,
"c2"
)
WriteFile
(
t
,
wd
+
"/rw/file1"
,
"c2"
)
}
if
c
.
f2_ro
{
writeToFile
(
wd
+
"/ro/file2"
,
"c3"
)
WriteFile
(
t
,
wd
+
"/ro/file2"
,
"c3"
)
}
if
c
.
f2_rw
{
writeToFile
(
wd
+
"/rw/file2"
,
"c4"
)
WriteFile
(
t
,
wd
+
"/rw/file2"
,
"c4"
)
}
err
:=
os
.
Rename
(
wd
+
"/mnt/file1"
,
wd
+
"/mnt/file2"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Rename failed: %v"
,
err
)
}
_
,
err
=
os
.
Lstat
(
wd
+
"/mnt/file1"
)
if
err
==
nil
{
...
...
@@ -451,7 +522,9 @@ func TestUnionFsRename(t *testing.T) {
t
.
Errorf
(
"Should have gotten file2: %v"
,
err
)
}
err
=
os
.
Rename
(
wd
+
"/mnt/file2"
,
wd
+
"/mnt/file1"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Rename failed: %v"
,
err
)
}
_
,
err
=
os
.
Lstat
(
wd
+
"/mnt/file2"
)
if
err
==
nil
{
...
...
@@ -470,10 +543,14 @@ func TestUnionFsRenameDirBasic(t *testing.T) {
defer
clean
()
err
:=
os
.
MkdirAll
(
wd
+
"/ro/dir/subdir"
,
0755
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"MkdirAll failed: %v"
,
err
)
}
err
=
os
.
Rename
(
wd
+
"/mnt/dir"
,
wd
+
"/mnt/renamed"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Rename failed: %v"
,
err
)
}
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/mnt/dir"
);
fi
!=
nil
{
t
.
Fatalf
(
"%s/mnt/dir should have disappeared: %v"
,
wd
,
fi
)
...
...
@@ -498,16 +575,22 @@ func TestUnionFsRenameDirAllSourcesGone(t *testing.T) {
defer
clean
()
err
:=
os
.
MkdirAll
(
wd
+
"/ro/dir"
,
0755
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"MkdirAll failed: %v"
,
err
)
}
err
=
ioutil
.
WriteFile
(
wd
+
"/ro/dir/file.txt"
,
[]
byte
{
42
},
0644
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"WriteFile failed: %v"
,
err
)
}
freezeRo
(
wd
+
"/ro"
)
freezeRo
(
t
,
wd
+
"/ro"
)
err
=
os
.
Rename
(
wd
+
"/mnt/dir"
,
wd
+
"/mnt/renamed"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Rename failed: %v"
,
err
)
}
names
:=
dirNames
(
wd
+
"/rw/"
+
testOpts
.
DeletionDirName
)
names
:=
dirNames
(
t
,
wd
+
"/rw/"
+
testOpts
.
DeletionDirName
)
if
len
(
names
)
!=
2
{
t
.
Errorf
(
"Expected 2 entries in %v"
,
names
)
}
...
...
@@ -518,24 +601,34 @@ func TestUnionFsRenameDirWithDeletions(t *testing.T) {
defer
clean
()
err
:=
os
.
MkdirAll
(
wd
+
"/ro/dir/subdir"
,
0755
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"MkdirAll failed: %v"
,
err
)
}
err
=
ioutil
.
WriteFile
(
wd
+
"/ro/dir/file.txt"
,
[]
byte
{
42
},
0644
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"WriteFile failed: %v"
,
err
)
}
err
=
ioutil
.
WriteFile
(
wd
+
"/ro/dir/subdir/file.txt"
,
[]
byte
{
42
},
0644
)
CheckSuccess
(
err
)
freezeRo
(
wd
+
"/ro"
)
if
err
!=
nil
{
t
.
Fatalf
(
"WriteFile failed: %v"
,
err
)
}
freezeRo
(
t
,
wd
+
"/ro"
)
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/mnt/dir/subdir/file.txt"
);
fi
==
nil
||
fi
.
Mode
()
&
os
.
ModeType
!=
0
{
t
.
Fatalf
(
"%s/mnt/dir/subdir/file.txt should be file: %v"
,
wd
,
fi
)
}
err
=
os
.
Remove
(
wd
+
"/mnt/dir/file.txt"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Remove failed: %v"
,
err
)
}
err
=
os
.
Rename
(
wd
+
"/mnt/dir"
,
wd
+
"/mnt/renamed"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Rename failed: %v"
,
err
)
}
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/mnt/dir/subdir/file.txt"
);
fi
!=
nil
{
t
.
Fatalf
(
"%s/mnt/dir/subdir/file.txt should have disappeared: %v"
,
wd
,
fi
)
...
...
@@ -567,10 +660,14 @@ func TestUnionFsRenameSymlink(t *testing.T) {
defer
clean
()
err
:=
os
.
Symlink
(
"linktarget"
,
wd
+
"/ro/link"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Symlink failed: %v"
,
err
)
}
err
=
os
.
Rename
(
wd
+
"/mnt/link"
,
wd
+
"/mnt/renamed"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Rename failed: %v"
,
err
)
}
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/mnt/link"
);
fi
!=
nil
{
t
.
Fatalf
(
"%s/mnt/link should have disappeared: %v"
,
wd
,
fi
)
...
...
@@ -591,11 +688,15 @@ func TestUnionFsWritableDir(t *testing.T) {
dirname
:=
wd
+
"/ro/subdir"
err
:=
os
.
Mkdir
(
dirname
,
0555
)
CheckSuccess
(
err
)
freezeRo
(
wd
+
"/ro"
)
if
err
!=
nil
{
t
.
Fatalf
(
"Mkdir failed: %v"
,
err
)
}
freezeRo
(
t
,
wd
+
"/ro"
)
fi
,
err
:=
os
.
Lstat
(
wd
+
"/mnt/subdir"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Lstat failed: %v"
,
err
)
}
if
fi
.
Mode
()
.
Perm
()
&
0222
==
0
{
t
.
Errorf
(
"unexpected permission %o"
,
fi
.
Mode
()
.
Perm
())
}
...
...
@@ -608,12 +709,16 @@ func TestUnionFsWriteAccess(t *testing.T) {
fn
:=
wd
+
"/ro/file"
// No write perms.
err
:=
ioutil
.
WriteFile
(
fn
,
[]
byte
(
"foo"
),
0444
)
CheckSuccess
(
err
)
freezeRo
(
wd
+
"/ro"
)
if
err
!=
nil
{
t
.
Fatalf
(
"WriteFile failed: %v"
,
err
)
}
freezeRo
(
t
,
wd
+
"/ro"
)
err
=
syscall
.
Access
(
wd
+
"/mnt/file"
,
raw
.
W_OK
)
if
err
!=
nil
{
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Access failed: %v"
,
err
)
}
}
}
...
...
@@ -624,17 +729,25 @@ func TestUnionFsLink(t *testing.T) {
content
:=
"blabla"
fn
:=
wd
+
"/ro/file"
err
:=
ioutil
.
WriteFile
(
fn
,
[]
byte
(
content
),
0666
)
CheckSuccess
(
err
)
freezeRo
(
wd
+
"/ro"
)
if
err
!=
nil
{
t
.
Fatalf
(
"WriteFile failed: %v"
,
err
)
}
freezeRo
(
t
,
wd
+
"/ro"
)
err
=
os
.
Link
(
wd
+
"/mnt/file"
,
wd
+
"/mnt/linked"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Link failed: %v"
,
err
)
}
fi2
,
err
:=
os
.
Lstat
(
wd
+
"/mnt/linked"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Lstat failed: %v"
,
err
)
}
fi1
,
err
:=
os
.
Lstat
(
wd
+
"/mnt/file"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Lstat failed: %v"
,
err
)
}
s1
:=
fuse
.
ToStatT
(
fi1
)
s2
:=
fuse
.
ToStatT
(
fi2
)
...
...
@@ -651,15 +764,15 @@ func TestUnionFsTruncate(t *testing.T) {
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
writeToFile
(
wd
+
"/ro/file"
,
"hello"
)
freezeRo
(
wd
+
"/ro"
)
WriteFile
(
t
,
wd
+
"/ro/file"
,
"hello"
)
freezeRo
(
t
,
wd
+
"/ro"
)
os
.
Truncate
(
wd
+
"/mnt/file"
,
2
)
content
:=
readFromFile
(
wd
+
"/mnt/file"
)
content
:=
readFromFile
(
t
,
wd
+
"/mnt/file"
)
if
content
!=
"he"
{
t
.
Errorf
(
"unexpected content %v"
,
content
)
}
content2
:=
readFromFile
(
wd
+
"/rw/file"
)
content2
:=
readFromFile
(
t
,
wd
+
"/rw/file"
)
if
content2
!=
content
{
t
.
Errorf
(
"unexpected rw content %v"
,
content2
)
}
...
...
@@ -672,19 +785,27 @@ func TestUnionFsCopyChmod(t *testing.T) {
contents
:=
"hello"
fn
:=
wd
+
"/mnt/y"
err
:=
ioutil
.
WriteFile
(
fn
,
[]
byte
(
contents
),
0644
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"WriteFile failed: %v"
,
err
)
}
err
=
os
.
Chmod
(
fn
,
0755
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Chmod failed: %v"
,
err
)
}
fi
,
err
:=
os
.
Lstat
(
fn
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Lstat failed: %v"
,
err
)
}
if
fi
.
Mode
()
&
0111
==
0
{
t
.
Errorf
(
"1st attr error %o"
,
fi
.
Mode
())
}
time
.
Sleep
(
entryTtl
)
fi
,
err
=
os
.
Lstat
(
fn
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Lstat failed: %v"
,
err
)
}
if
fi
.
Mode
()
&
0111
==
0
{
t
.
Errorf
(
"uncached attr error %o"
,
fi
.
Mode
())
}
...
...
@@ -704,15 +825,21 @@ func TestUnionFsTruncateTimestamp(t *testing.T) {
contents
:=
"hello"
fn
:=
wd
+
"/mnt/y"
err
:=
ioutil
.
WriteFile
(
fn
,
[]
byte
(
contents
),
0644
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"WriteFile failed: %v"
,
err
)
}
time
.
Sleep
(
200
*
time
.
Millisecond
)
truncTs
:=
time
.
Now
()
err
=
os
.
Truncate
(
fn
,
3
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Truncate failed: %v"
,
err
)
}
fi
,
err
:=
os
.
Lstat
(
fn
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Lstat failed: %v"
,
err
)
}
if
truncTs
.
Sub
(
fi
.
ModTime
())
>
100
*
time
.
Millisecond
{
t
.
Error
(
"timestamp drift"
,
truncTs
,
fi
.
ModTime
())
...
...
@@ -724,13 +851,17 @@ func TestUnionFsRemoveAll(t *testing.T) {
defer
clean
()
err
:=
os
.
MkdirAll
(
wd
+
"/ro/dir/subdir"
,
0755
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"MkdirAll failed: %v"
,
err
)
}
contents
:=
"hello"
fn
:=
wd
+
"/ro/dir/subdir/y"
err
=
ioutil
.
WriteFile
(
fn
,
[]
byte
(
contents
),
0644
)
CheckSuccess
(
err
)
freezeRo
(
wd
+
"/ro"
)
if
err
!=
nil
{
t
.
Fatalf
(
"WriteFile failed: %v"
,
err
)
}
freezeRo
(
t
,
wd
+
"/ro"
)
err
=
os
.
RemoveAll
(
wd
+
"/mnt/dir"
)
if
err
!=
nil
{
...
...
@@ -744,7 +875,9 @@ func TestUnionFsRemoveAll(t *testing.T) {
}
names
,
err
:=
Readdirnames
(
wd
+
"/rw/DELETIONS"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Readdirnames failed: %v"
,
err
)
}
if
len
(
names
)
!=
3
{
t
.
Fatal
(
"unexpected names"
,
names
)
}
...
...
@@ -757,16 +890,22 @@ func TestUnionFsRmRf(t *testing.T) {
defer
clean
()
err
:=
os
.
MkdirAll
(
wd
+
"/ro/dir/subdir"
,
0755
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"MkdirAll failed: %v"
,
err
)
}
contents
:=
"hello"
fn
:=
wd
+
"/ro/dir/subdir/y"
err
=
ioutil
.
WriteFile
(
fn
,
[]
byte
(
contents
),
0644
)
CheckSuccess
(
err
)
freezeRo
(
wd
+
"/ro"
)
if
err
!=
nil
{
t
.
Fatalf
(
"WriteFile failed: %v"
,
err
)
}
freezeRo
(
t
,
wd
+
"/ro"
)
bin
,
err
:=
exec
.
LookPath
(
"rm"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"LookPath failed: %v"
,
err
)
}
command
:=
fmt
.
Sprintf
(
"%s -f %s/mnt/dir"
,
bin
,
wd
)
log
.
Printf
(
"Command: %s"
,
command
)
names
,
_
:=
Readdirnames
(
wd
+
"/mnt/dir"
)
...
...
@@ -784,7 +923,9 @@ func TestUnionFsRmRf(t *testing.T) {
}
names
,
err
=
Readdirnames
(
wd
+
"/rw/DELETIONS"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Readdirnames failed: %v"
,
err
)
}
if
len
(
names
)
!=
3
{
t
.
Fatal
(
"unexpected names"
,
names
)
}
...
...
@@ -805,20 +946,28 @@ func TestUnionFsDropDeletionCache(t *testing.T) {
defer
clean
()
err
:=
ioutil
.
WriteFile
(
wd
+
"/ro/file"
,
[]
byte
(
"bla"
),
0644
)
CheckSuccess
(
err
)
freezeRo
(
wd
+
"/ro"
)
if
err
!=
nil
{
t
.
Fatalf
(
"WriteFile failed: %v"
,
err
)
}
freezeRo
(
t
,
wd
+
"/ro"
)
_
,
err
=
os
.
Lstat
(
wd
+
"/mnt/file"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Lstat failed: %v"
,
err
)
}
err
=
os
.
Remove
(
wd
+
"/mnt/file"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Remove failed: %v"
,
err
)
}
fi
,
_
:=
os
.
Lstat
(
wd
+
"/mnt/file"
)
if
fi
!=
nil
{
t
.
Fatal
(
"Lstat() should have failed"
,
fi
)
}
names
,
err
:=
Readdirnames
(
wd
+
"/rw/DELETIONS"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Readdirnames failed: %v"
,
err
)
}
if
len
(
names
)
!=
1
{
t
.
Fatal
(
"unexpected names"
,
names
)
}
...
...
@@ -831,7 +980,9 @@ func TestUnionFsDropDeletionCache(t *testing.T) {
// Expire kernel entry.
time
.
Sleep
((
6
*
entryTtl
)
/
10
)
err
=
ioutil
.
WriteFile
(
wd
+
"/mnt/.drop_cache"
,
[]
byte
(
""
),
0644
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"WriteFile failed: %v"
,
err
)
}
_
,
err
=
os
.
Lstat
(
wd
+
"/mnt/file"
)
if
err
!=
nil
{
t
.
Fatal
(
"Lstat() should have succeeded"
,
err
)
...
...
@@ -843,26 +994,36 @@ func TestUnionFsDropCache(t *testing.T) {
defer
clean
()
err
:=
ioutil
.
WriteFile
(
wd
+
"/ro/file"
,
[]
byte
(
"bla"
),
0644
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"WriteFile failed: %v"
,
err
)
}
_
,
err
=
os
.
Lstat
(
wd
+
"/mnt/.drop_cache"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Lstat failed: %v"
,
err
)
}
names
,
err
:=
Readdirnames
(
wd
+
"/mnt"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Readdirnames failed: %v"
,
err
)
}
if
len
(
names
)
!=
1
||
names
[
0
]
!=
"file"
{
t
.
Fatal
(
"unexpected names"
,
names
)
}
err
=
ioutil
.
WriteFile
(
wd
+
"/ro/file2"
,
[]
byte
(
"blabla"
),
0644
)
names2
,
err
:=
Readdirnames
(
wd
+
"/mnt"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Readdirnames failed: %v"
,
err
)
}
if
len
(
names2
)
!=
len
(
names
)
{
t
.
Fatal
(
"mismatch"
,
names2
)
}
err
=
ioutil
.
WriteFile
(
wd
+
"/mnt/.drop_cache"
,
[]
byte
(
"does not matter"
),
0644
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"WriteFile failed: %v"
,
err
)
}
names2
,
err
=
Readdirnames
(
wd
+
"/mnt"
)
if
len
(
names2
)
!=
2
{
t
.
Fatal
(
"mismatch 2"
,
names2
)
...
...
@@ -875,13 +1036,19 @@ func TestUnionFsDisappearing(t *testing.T) {
wd
,
_
:=
ioutil
.
TempDir
(
""
,
""
)
defer
os
.
RemoveAll
(
wd
)
err
:=
os
.
Mkdir
(
wd
+
"/mnt"
,
0700
)
fuse
.
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Mkdir failed: %v"
,
err
)
}
err
=
os
.
Mkdir
(
wd
+
"/rw"
,
0700
)
fuse
.
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Mkdir failed: %v"
,
err
)
}
os
.
Mkdir
(
wd
+
"/ro"
,
0700
)
fuse
.
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Mkdir failed: %v"
,
err
)
}
wrFs
:=
fuse
.
NewLoopbackFileSystem
(
wd
+
"/rw"
)
var
fses
[]
fuse
.
FileSystem
...
...
@@ -897,7 +1064,9 @@ func TestUnionFsDisappearing(t *testing.T) {
nfs
:=
fuse
.
NewPathNodeFs
(
ufs
,
nil
)
state
,
_
,
err
:=
fuse
.
MountNodeFileSystem
(
wd
+
"/mnt"
,
nfs
,
opts
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"MountNodeFileSystem failed: %v"
,
err
)
}
defer
state
.
Unmount
()
state
.
Debug
=
fuse
.
VerboseTest
()
go
state
.
Loop
()
...
...
@@ -905,11 +1074,15 @@ func TestUnionFsDisappearing(t *testing.T) {
log
.
Println
(
"TestUnionFsDisappearing2"
)
err
=
ioutil
.
WriteFile
(
wd
+
"/ro/file"
,
[]
byte
(
"blabla"
),
0644
)
CheckSuccess
(
err
)
freezeRo
(
wd
+
"/ro"
)
if
err
!=
nil
{
t
.
Fatalf
(
"WriteFile failed: %v"
,
err
)
}
freezeRo
(
t
,
wd
+
"/ro"
)
err
=
os
.
Remove
(
wd
+
"/mnt/file"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Remove failed: %v"
,
err
)
}
state
.
ThreadSanitizerSync
()
oldRoot
:=
wrFs
.
Root
...
...
@@ -949,15 +1122,21 @@ func TestUnionFsDeletedGetAttr(t *testing.T) {
defer
clean
()
err
:=
ioutil
.
WriteFile
(
wd
+
"/ro/file"
,
[]
byte
(
"blabla"
),
0644
)
CheckSuccess
(
err
)
freezeRo
(
wd
+
"/ro"
)
if
err
!=
nil
{
t
.
Fatalf
(
"WriteFile failed: %v"
,
err
)
}
freezeRo
(
t
,
wd
+
"/ro"
)
f
,
err
:=
os
.
Open
(
wd
+
"/mnt/file"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Open failed: %v"
,
err
)
}
defer
f
.
Close
()
err
=
os
.
Remove
(
wd
+
"/mnt/file"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Remove failed: %v"
,
err
)
}
if
fi
,
err
:=
f
.
Stat
();
err
!=
nil
||
fi
.
Mode
()
&
os
.
ModeType
!=
0
{
t
.
Fatalf
(
"stat returned error or non-file: %v %v"
,
err
,
fi
)
...
...
@@ -968,31 +1147,43 @@ func TestUnionFsDoubleOpen(t *testing.T) {
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
err
:=
ioutil
.
WriteFile
(
wd
+
"/ro/file"
,
[]
byte
(
"blablabla"
),
0644
)
CheckSuccess
(
err
)
freezeRo
(
wd
+
"/ro"
)
if
err
!=
nil
{
t
.
Fatalf
(
"WriteFile failed: %v"
,
err
)
}
freezeRo
(
t
,
wd
+
"/ro"
)
roFile
,
err
:=
os
.
Open
(
wd
+
"/mnt/file"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Open failed: %v"
,
err
)
}
defer
roFile
.
Close
()
rwFile
,
err
:=
os
.
OpenFile
(
wd
+
"/mnt/file"
,
os
.
O_WRONLY
|
os
.
O_TRUNC
,
0666
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"OpenFile failed: %v"
,
err
)
}
defer
rwFile
.
Close
()
output
,
err
:=
ioutil
.
ReadAll
(
roFile
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"ReadAll failed: %v"
,
err
)
}
if
len
(
output
)
!=
0
{
t
.
Errorf
(
"After r/w truncation, r/o file should be empty too: %q"
,
string
(
output
))
}
want
:=
"hello"
_
,
err
=
rwFile
.
Write
([]
byte
(
want
))
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Write failed: %v"
,
err
)
}
b
:=
make
([]
byte
,
100
)
roFile
.
Seek
(
0
,
0
)
n
,
err
:=
roFile
.
Read
(
b
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Read failed: %v"
,
err
)
}
b
=
b
[
:
n
]
if
string
(
b
)
!=
"hello"
{
...
...
@@ -1002,23 +1193,33 @@ func TestUnionFsDoubleOpen(t *testing.T) {
func
TestUnionFsFdLeak
(
t
*
testing
.
T
)
{
beforeEntries
,
err
:=
ioutil
.
ReadDir
(
"/proc/self/fd"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"ReadDir failed: %v"
,
err
)
}
wd
,
clean
:=
setupUfs
(
t
)
err
=
ioutil
.
WriteFile
(
wd
+
"/ro/file"
,
[]
byte
(
"blablabla"
),
0644
)
CheckSuccess
(
err
)
freezeRo
(
wd
+
"/ro"
)
if
err
!=
nil
{
t
.
Fatalf
(
"WriteFile failed: %v"
,
err
)
}
freezeRo
(
t
,
wd
+
"/ro"
)
contents
,
err
:=
ioutil
.
ReadFile
(
wd
+
"/mnt/file"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"ReadFile failed: %v"
,
err
)
}
err
=
ioutil
.
WriteFile
(
wd
+
"/mnt/file"
,
contents
,
0644
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"WriteFile failed: %v"
,
err
)
}
clean
()
afterEntries
,
err
:=
ioutil
.
ReadDir
(
"/proc/self/fd"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"ReadDir failed: %v"
,
err
)
}
if
len
(
afterEntries
)
!=
len
(
beforeEntries
)
{
t
.
Errorf
(
"/proc/self/fd changed size: after %v before %v"
,
len
(
beforeEntries
),
len
(
afterEntries
))
...
...
@@ -1045,16 +1246,24 @@ func TestUnionFsFlushSize(t *testing.T) {
fn
:=
wd
+
"/mnt/file"
f
,
err
:=
os
.
OpenFile
(
fn
,
os
.
O_WRONLY
|
os
.
O_CREATE
,
0644
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"OpenFile failed: %v"
,
err
)
}
fi
,
err
:=
f
.
Stat
()
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Stat failed: %v"
,
err
)
}
n
,
err
:=
f
.
Write
([]
byte
(
"hello"
))
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Write failed: %v"
,
err
)
}
f
.
Close
()
fi
,
err
=
os
.
Lstat
(
fn
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Lstat failed: %v"
,
err
)
}
if
fi
.
Size
()
!=
int64
(
n
)
{
t
.
Errorf
(
"got %d from Stat().Size, want %d"
,
fi
.
Size
(),
n
)
}
...
...
@@ -1068,20 +1277,30 @@ func TestUnionFsFlushRename(t *testing.T) {
fn
:=
wd
+
"/mnt/tmp"
f
,
err
:=
os
.
OpenFile
(
fn
,
os
.
O_WRONLY
|
os
.
O_CREATE
,
0644
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"OpenFile failed: %v"
,
err
)
}
fi
,
err
:=
f
.
Stat
()
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Stat failed: %v"
,
err
)
}
n
,
err
:=
f
.
Write
([]
byte
(
"hello"
))
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Write failed: %v"
,
err
)
}
f
.
Close
()
dst
:=
wd
+
"/mnt/file"
err
=
os
.
Rename
(
fn
,
dst
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Rename failed: %v"
,
err
)
}
fi
,
err
=
os
.
Lstat
(
dst
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Lstat failed: %v"
,
err
)
}
if
fi
.
Size
()
!=
int64
(
n
)
{
t
.
Errorf
(
"got %d from Stat().Size, want %d"
,
fi
.
Size
(),
n
)
}
...
...
@@ -1093,11 +1312,17 @@ func TestUnionFsTruncGetAttr(t *testing.T) {
c
:=
[]
byte
(
"hello"
)
f
,
err
:=
os
.
OpenFile
(
wd
+
"/mnt/file"
,
os
.
O_CREATE
|
os
.
O_RDWR
|
os
.
O_TRUNC
,
0644
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"OpenFile failed: %v"
,
err
)
}
_
,
err
=
f
.
Write
(
c
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Write failed: %v"
,
err
)
}
err
=
f
.
Close
()
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Close failed: %v"
,
err
)
}
fi
,
err
:=
os
.
Lstat
(
wd
+
"/mnt/file"
)
if
fi
.
Size
()
!=
int64
(
len
(
c
))
{
...
...
@@ -1110,18 +1335,28 @@ func TestUnionFsPromoteDirTimeStamp(t *testing.T) {
defer
clean
()
err
:=
os
.
Mkdir
(
wd
+
"/ro/subdir"
,
0750
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Mkdir failed: %v"
,
err
)
}
err
=
ioutil
.
WriteFile
(
wd
+
"/ro/subdir/file"
,
[]
byte
(
"hello"
),
0644
)
CheckSuccess
(
err
)
freezeRo
(
wd
+
"/ro"
)
if
err
!=
nil
{
t
.
Fatalf
(
"WriteFile failed: %v"
,
err
)
}
freezeRo
(
t
,
wd
+
"/ro"
)
err
=
os
.
Chmod
(
wd
+
"/mnt/subdir/file"
,
0060
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Chmod failed: %v"
,
err
)
}
fRo
,
err
:=
os
.
Lstat
(
wd
+
"/ro/subdir"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Lstat failed: %v"
,
err
)
}
fRw
,
err
:=
os
.
Lstat
(
wd
+
"/rw/subdir"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Lstat failed: %v"
,
err
)
}
// TODO - need to update timestamps after promoteDirsTo calls,
// not during.
...
...
@@ -1139,20 +1374,28 @@ func TestUnionFsCheckHiddenFiles(t *testing.T) {
defer
clean
()
err
:=
ioutil
.
WriteFile
(
wd
+
"/ro/hidden"
,
[]
byte
(
"bla"
),
0644
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"WriteFile failed: %v"
,
err
)
}
err
=
ioutil
.
WriteFile
(
wd
+
"/ro/not_hidden"
,
[]
byte
(
"bla"
),
0644
)
CheckSuccess
(
err
)
freezeRo
(
wd
+
"/ro"
)
if
err
!=
nil
{
t
.
Fatalf
(
"WriteFile failed: %v"
,
err
)
}
freezeRo
(
t
,
wd
+
"/ro"
)
fi
,
_
:=
os
.
Lstat
(
wd
+
"/mnt/hidden"
)
if
fi
!=
nil
{
t
.
Fatal
(
"Lstat() should have failed"
,
fi
)
}
_
,
err
=
os
.
Lstat
(
wd
+
"/mnt/not_hidden"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Lstat failed: %v"
,
err
)
}
names
,
err
:=
Readdirnames
(
wd
+
"/mnt"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Readdirnames failed: %v"
,
err
)
}
if
len
(
names
)
!=
1
||
names
[
0
]
!=
"not_hidden"
{
t
.
Fatal
(
"unexpected names"
,
names
)
}
...
...
zipfs/multizip_test.go
View file @
060980b2
...
...
@@ -10,11 +10,10 @@ import (
)
var
_
=
log
.
Printf
var
CheckSuccess
=
fuse
.
CheckSuccess
const
testTtl
=
100
*
time
.
Millisecond
func
setupMzfs
()
(
mountPoint
string
,
cleanup
func
())
{
func
setupMzfs
(
t
*
testing
.
T
)
(
mountPoint
string
,
cleanup
func
())
{
fs
:=
NewMultiZipFs
()
mountPoint
,
_
=
ioutil
.
TempDir
(
""
,
""
)
nfs
:=
fuse
.
NewPathNodeFs
(
fs
,
nil
)
...
...
@@ -23,7 +22,9 @@ func setupMzfs() (mountPoint string, cleanup func()) {
AttrTimeout
:
testTtl
,
NegativeTimeout
:
0.0
,
})
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"MountNodeFileSystem failed: %v"
,
err
)
}
state
.
Debug
=
fuse
.
VerboseTest
()
go
state
.
Loop
()
...
...
@@ -34,7 +35,7 @@ func setupMzfs() (mountPoint string, cleanup func()) {
}
func
TestMultiZipReadonly
(
t
*
testing
.
T
)
{
mountPoint
,
cleanup
:=
setupMzfs
()
mountPoint
,
cleanup
:=
setupMzfs
(
t
)
defer
cleanup
()
_
,
err
:=
os
.
Create
(
mountPoint
+
"/random"
)
...
...
@@ -49,19 +50,23 @@ func TestMultiZipReadonly(t *testing.T) {
}
func
TestMultiZipFs
(
t
*
testing
.
T
)
{
mountPoint
,
cleanup
:=
setupMzfs
()
mountPoint
,
cleanup
:=
setupMzfs
(
t
)
defer
cleanup
()
zipFile
:=
testZipFile
()
entries
,
err
:=
ioutil
.
ReadDir
(
mountPoint
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"ReadDir failed: %v"
,
err
)
}
if
len
(
entries
)
!=
1
||
string
(
entries
[
0
]
.
Name
())
!=
"config"
{
t
.
Errorf
(
"wrong names return. %v"
,
entries
)
}
err
=
os
.
Symlink
(
zipFile
,
mountPoint
+
"/config/zipmount"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Symlink failed: %v"
,
err
)
}
fi
,
err
:=
os
.
Lstat
(
mountPoint
+
"/zipmount"
)
if
!
fi
.
IsDir
()
{
...
...
@@ -69,33 +74,43 @@ func TestMultiZipFs(t *testing.T) {
}
entries
,
err
=
ioutil
.
ReadDir
(
mountPoint
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"ReadDir failed: %v"
,
err
)
}
if
len
(
entries
)
!=
2
{
t
.
Error
(
"Expect 2 entries"
,
entries
)
}
val
,
err
:=
os
.
Readlink
(
mountPoint
+
"/config/zipmount"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Readlink failed: %v"
,
err
)
}
if
val
!=
zipFile
{
t
.
Errorf
(
"expected %v got %v"
,
zipFile
,
val
)
}
fi
,
err
=
os
.
Lstat
(
mountPoint
+
"/zipmount"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Lstat failed: %v"
,
err
)
}
if
!
fi
.
IsDir
()
{
t
.
Fatal
(
"expect directory for /zipmount, got %v"
,
fi
)
}
// Check that zipfs itself works.
fi
,
err
=
os
.
Stat
(
mountPoint
+
"/zipmount/subdir"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Stat failed: %v"
,
err
)
}
if
!
fi
.
IsDir
()
{
t
.
Error
(
"directory type"
,
fi
)
}
// Removing the config dir unmount
err
=
os
.
Remove
(
mountPoint
+
"/config/zipmount"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Remove failed: %v"
,
err
)
}
fi
,
err
=
os
.
Stat
(
mountPoint
+
"/zipmount"
)
if
err
==
nil
{
...
...
zipfs/zipfs_test.go
View file @
060980b2
...
...
@@ -18,9 +18,11 @@ func testZipFile() string {
return
filepath
.
Join
(
dir
,
"test.zip"
)
}
func
setupZipfs
()
(
mountPoint
string
,
cleanup
func
())
{
func
setupZipfs
(
t
*
testing
.
T
)
(
mountPoint
string
,
cleanup
func
())
{
zfs
,
err
:=
NewArchiveFileSystem
(
testZipFile
())
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"NewArchiveFileSystem failed: %v"
,
err
)
}
mountPoint
,
_
=
ioutil
.
TempDir
(
""
,
""
)
state
,
_
,
err
:=
fuse
.
MountNodeFileSystem
(
mountPoint
,
zfs
,
nil
)
...
...
@@ -35,29 +37,37 @@ func setupZipfs() (mountPoint string, cleanup func()) {
}
func
TestZipFs
(
t
*
testing
.
T
)
{
mountPoint
,
clean
:=
setupZipfs
()
mountPoint
,
clean
:=
setupZipfs
(
t
)
defer
clean
()
entries
,
err
:=
ioutil
.
ReadDir
(
mountPoint
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"ReadDir failed: %v"
,
err
)
}
if
len
(
entries
)
!=
2
{
t
.
Error
(
"wrong length"
,
entries
)
}
fi
,
err
:=
os
.
Stat
(
mountPoint
+
"/subdir"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Stat failed: %v"
,
err
)
}
if
!
fi
.
IsDir
()
{
t
.
Error
(
"directory type"
,
fi
)
}
fi
,
err
=
os
.
Stat
(
mountPoint
+
"/file.txt"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Stat failed: %v"
,
err
)
}
if
fi
.
IsDir
()
{
t
.
Error
(
"file type"
,
fi
)
}
f
,
err
:=
os
.
Open
(
mountPoint
+
"/file.txt"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Open failed: %v"
,
err
)
}
b
:=
make
([]
byte
,
1024
)
n
,
err
:=
f
.
Read
(
b
)
...
...
@@ -70,11 +80,13 @@ func TestZipFs(t *testing.T) {
}
func
TestLinkCount
(
t
*
testing
.
T
)
{
mp
,
clean
:=
setupZipfs
()
mp
,
clean
:=
setupZipfs
(
t
)
defer
clean
()
fi
,
err
:=
os
.
Stat
(
mp
+
"/file.txt"
)
CheckSuccess
(
err
)
if
err
!=
nil
{
t
.
Fatalf
(
"Stat failed: %v"
,
err
)
}
if
fuse
.
ToStatT
(
fi
)
.
Nlink
!=
1
{
t
.
Fatal
(
"wrong link count"
,
fuse
.
ToStatT
(
fi
)
.
Nlink
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment