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
Expand all
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
This diff is collapsed.
Click to expand it.
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