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
Levin Zimmermann
go-fuse
Commits
a393c5e2
Commit
a393c5e2
authored
Jun 20, 2013
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move loopback test and friends to separate package test/
parent
66031878
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
135 additions
and
127 deletions
+135
-127
fuse/memnode_test.go
fuse/memnode_test.go
+3
-0
fuse/syscall_darwin.go
fuse/syscall_darwin.go
+0
-7
fuse/syscall_linux.go
fuse/syscall_linux.go
+0
-7
fuse/test/defaultread_test.go
fuse/test/defaultread_test.go
+13
-11
fuse/test/delete_test.go
fuse/test/delete_test.go
+14
-12
fuse/test/fsetattr_test.go
fuse/test/fsetattr_test.go
+42
-41
fuse/test/loopback_darwin_test.go
fuse/test/loopback_darwin_test.go
+1
-1
fuse/test/loopback_linux_test.go
fuse/test/loopback_linux_test.go
+2
-1
fuse/test/loopback_test.go
fuse/test/loopback_test.go
+29
-20
fuse/test/mount_test.go
fuse/test/mount_test.go
+13
-11
fuse/test/notify_test.go
fuse/test/notify_test.go
+18
-16
No files found.
fuse/memnode_test.go
View file @
a393c5e2
...
...
@@ -5,10 +5,13 @@ import (
"log"
"os"
"testing"
"time"
)
var
_
=
log
.
Println
const
testTtl
=
100
*
time
.
Millisecond
func
setupMemNodeTest
(
t
*
testing
.
T
)
(
wd
string
,
fs
*
MemNodeFs
,
clean
func
())
{
tmp
,
err
:=
ioutil
.
TempDir
(
""
,
"go-fuse-memnode_test"
)
if
err
!=
nil
{
...
...
fuse/syscall_darwin.go
View file @
a393c5e2
...
...
@@ -126,10 +126,3 @@ func Removexattr(path string, attr string) (errno int) {
return
int
(
errNo
)
}
func
ioctl
(
fd
int
,
cmd
int
,
arg
uintptr
)
(
int
,
int
)
{
r0
,
_
,
e1
:=
syscall
.
Syscall
(
syscall
.
SYS_IOCTL
,
uintptr
(
fd
),
uintptr
(
cmd
),
uintptr
(
arg
))
val
:=
int
(
r0
)
errno
:=
int
(
e1
)
return
val
,
errno
}
fuse/syscall_linux.go
View file @
a393c5e2
...
...
@@ -126,13 +126,6 @@ func Removexattr(path string, attr string) (errno int) {
return
int
(
errNo
)
}
func
ioctl
(
fd
int
,
cmd
int
,
arg
uintptr
)
(
int
,
int
)
{
r0
,
_
,
e1
:=
syscall
.
Syscall
(
syscall
.
SYS_IOCTL
,
uintptr
(
fd
),
uintptr
(
cmd
),
uintptr
(
arg
))
val
:=
int
(
r0
)
errno
:=
int
(
e1
)
return
val
,
errno
}
const
AT_FDCWD
=
-
100
...
...
fuse/defaultread_test.go
→
fuse/
test/
defaultread_test.go
View file @
a393c5e2
package
fuse
package
test
import
(
"io/ioutil"
"log"
"os"
"testing"
"github.com/hanwen/go-fuse/fuse"
)
var
_
=
log
.
Println
type
DefaultReadFS
struct
{
DefaultFileSystem
fuse
.
DefaultFileSystem
size
uint64
exist
bool
}
func
(
fs
*
DefaultReadFS
)
GetAttr
(
name
string
,
context
*
Context
)
(
*
Attr
,
Status
)
{
func
(
fs
*
DefaultReadFS
)
GetAttr
(
name
string
,
context
*
fuse
.
Context
)
(
*
fuse
.
Attr
,
fuse
.
Status
)
{
if
name
==
""
{
return
&
Attr
{
Mode
:
S_IFDIR
|
0755
},
OK
return
&
fuse
.
Attr
{
Mode
:
fuse
.
S_IFDIR
|
0755
},
fuse
.
OK
}
if
name
==
"file"
{
return
&
Attr
{
Mode
:
S_IFREG
|
0644
,
Size
:
fs
.
size
},
OK
return
&
fuse
.
Attr
{
Mode
:
fuse
.
S_IFREG
|
0644
,
Size
:
fs
.
size
},
fuse
.
OK
}
return
nil
,
ENOENT
return
nil
,
fuse
.
ENOENT
}
func
(
fs
*
DefaultReadFS
)
Open
(
name
string
,
f
uint32
,
context
*
Context
)
(
File
,
Status
)
{
return
&
DefaultFile
{},
OK
func
(
fs
*
DefaultReadFS
)
Open
(
name
string
,
f
uint32
,
context
*
fuse
.
Context
)
(
fuse
.
File
,
fuse
.
Status
)
{
return
&
fuse
.
DefaultFile
{},
fuse
.
OK
}
func
defaultReadTest
(
t
*
testing
.
T
)
(
root
string
,
cleanup
func
())
{
...
...
@@ -36,12 +38,12 @@ func defaultReadTest(t *testing.T) (root string, cleanup func()) {
if
err
!=
nil
{
t
.
Fatalf
(
"TempDir failed: %v"
,
err
)
}
pathfs
:=
NewPathNodeFs
(
fs
,
nil
)
state
,
_
,
err
:=
MountNodeFileSystem
(
dir
,
pathfs
,
nil
)
pathfs
:=
fuse
.
NewPathNodeFs
(
fs
,
nil
)
state
,
_
,
err
:=
fuse
.
MountNodeFileSystem
(
dir
,
pathfs
,
nil
)
if
err
!=
nil
{
t
.
Fatalf
(
"MountNodeFileSystem failed: %v"
,
err
)
}
state
.
Debug
=
VerboseTest
()
state
.
Debug
=
fuse
.
VerboseTest
()
go
state
.
Loop
()
return
dir
,
func
()
{
...
...
fuse/delete_test.go
→
fuse/
test/
delete_test.go
View file @
a393c5e2
package
fuse
package
test
import
(
"bytes"
...
...
@@ -8,21 +8,23 @@ import (
"syscall"
"testing"
"time"
"github.com/hanwen/go-fuse/fuse"
)
type
flipNode
struct
{
*
mem
Node
fuse
.
Fs
Node
ok
chan
int
}
func
(
f
*
flipNode
)
GetAttr
(
out
*
Attr
,
file
File
,
c
*
Context
)
Status
{
func
(
f
*
flipNode
)
GetAttr
(
out
*
fuse
.
Attr
,
file
fuse
.
File
,
c
*
fuse
.
Context
)
fuse
.
Status
{
select
{
case
<-
f
.
ok
:
// use a status that is easily recognizable.
return
Status
(
syscall
.
EXDEV
)
return
fuse
.
Status
(
syscall
.
EXDEV
)
default
:
}
return
f
.
mem
Node
.
GetAttr
(
out
,
file
,
c
)
return
f
.
Fs
Node
.
GetAttr
(
out
,
file
,
c
)
}
func
TestDeleteNotify
(
t
*
testing
.
T
)
{
...
...
@@ -31,10 +33,10 @@ func TestDeleteNotify(t *testing.T) {
t
.
Fatalf
(
"TempDir failed %v"
,
err
)
}
defer
os
.
RemoveAll
(
dir
)
fs
:=
NewMemNodeFs
(
dir
+
"/backing"
)
conn
:=
NewFileSystemConnector
(
fs
,
&
FileSystemOptions
{
PortableInodes
:
true
})
state
:=
NewMountState
(
conn
)
fs
:=
fuse
.
NewMemNodeFs
(
dir
+
"/backing"
)
conn
:=
fuse
.
NewFileSystemConnector
(
fs
,
&
fuse
.
FileSystemOptions
{
PortableInodes
:
true
})
state
:=
fuse
.
NewMountState
(
conn
)
mnt
:=
dir
+
"/mnt"
err
=
os
.
Mkdir
(
mnt
,
0755
)
if
err
!=
nil
{
...
...
@@ -44,7 +46,7 @@ func TestDeleteNotify(t *testing.T) {
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
state
.
Debug
=
VerboseTest
()
state
.
Debug
=
fuse
.
VerboseTest
()
go
state
.
Loop
()
defer
state
.
Unmount
()
...
...
@@ -54,9 +56,9 @@ func TestDeleteNotify(t *testing.T) {
}
ch
:=
fs
.
Root
()
.
Inode
()
.
RmChild
(
"testdir"
)
ch
.
FsNode
()
.
(
*
memNode
)
.
SetInode
(
nil
)
ch
.
FsNode
()
.
SetInode
(
nil
)
flip
:=
flipNode
{
memNode
:
ch
.
FsNode
()
.
(
*
memNode
),
FsNode
:
ch
.
FsNode
(
),
ok
:
make
(
chan
int
),
}
newCh
:=
fs
.
Root
()
.
Inode
()
.
New
(
true
,
&
flip
)
...
...
fuse/fsetattr_test.go
→
fuse/
test/
fsetattr_test.go
View file @
a393c5e2
package
fuse
package
test
import
(
"io/ioutil"
...
...
@@ -8,13 +8,14 @@ import (
"time"
"github.com/hanwen/go-fuse/raw"
"github.com/hanwen/go-fuse/fuse"
)
type
MutableDataFile
struct
{
DefaultFile
fuse
.
DefaultFile
data
[]
byte
Attr
fuse
.
Attr
GetAttrCalled
bool
}
...
...
@@ -22,16 +23,16 @@ func (f *MutableDataFile) String() string {
return
"MutableDataFile"
}
func
(
f
*
MutableDataFile
)
Read
(
buf
[]
byte
,
off
int64
)
(
ReadResult
,
Status
)
{
func
(
f
*
MutableDataFile
)
Read
(
buf
[]
byte
,
off
int64
)
(
fuse
.
ReadResult
,
fuse
.
Status
)
{
end
:=
int
(
off
)
+
len
(
buf
)
if
end
>
len
(
f
.
data
)
{
end
=
len
(
f
.
data
)
}
return
&
ReadResultData
{
Data
:
f
.
data
[
off
:
end
]},
OK
return
&
fuse
.
ReadResultData
{
Data
:
f
.
data
[
off
:
end
]},
fuse
.
OK
}
func
(
f
*
MutableDataFile
)
Write
(
d
[]
byte
,
off
int64
)
(
uint32
,
Status
)
{
func
(
f
*
MutableDataFile
)
Write
(
d
[]
byte
,
off
int64
)
(
uint32
,
fuse
.
Status
)
{
end
:=
int64
(
len
(
d
))
+
off
if
int
(
end
)
>
len
(
f
.
data
)
{
data
:=
make
([]
byte
,
len
(
f
.
data
),
end
)
...
...
@@ -41,106 +42,106 @@ func (f *MutableDataFile) Write(d []byte, off int64) (uint32, Status) {
copy
(
f
.
data
[
off
:
end
],
d
)
f
.
Attr
.
Size
=
uint64
(
len
(
f
.
data
))
return
uint32
(
end
-
off
),
OK
return
uint32
(
end
-
off
),
fuse
.
OK
}
func
(
f
*
MutableDataFile
)
Flush
()
Status
{
return
OK
func
(
f
*
MutableDataFile
)
Flush
()
fuse
.
Status
{
return
fuse
.
OK
}
func
(
f
*
MutableDataFile
)
Release
()
{
}
func
(
f
*
MutableDataFile
)
getAttr
(
out
*
Attr
)
{
func
(
f
*
MutableDataFile
)
getAttr
(
out
*
fuse
.
Attr
)
{
*
out
=
f
.
Attr
out
.
Size
=
uint64
(
len
(
f
.
data
))
}
func
(
f
*
MutableDataFile
)
GetAttr
(
out
*
Attr
)
Status
{
func
(
f
*
MutableDataFile
)
GetAttr
(
out
*
fuse
.
Attr
)
fuse
.
Status
{
f
.
GetAttrCalled
=
true
f
.
getAttr
(
out
)
return
OK
return
fuse
.
OK
}
func
(
f
*
MutableDataFile
)
Utimens
(
atime
*
time
.
Time
,
mtime
*
time
.
Time
)
Status
{
func
(
f
*
MutableDataFile
)
Utimens
(
atime
*
time
.
Time
,
mtime
*
time
.
Time
)
fuse
.
Status
{
f
.
Attr
.
SetTimes
(
atime
,
mtime
,
nil
)
return
OK
return
fuse
.
OK
}
func
(
f
*
MutableDataFile
)
Truncate
(
size
uint64
)
Status
{
func
(
f
*
MutableDataFile
)
Truncate
(
size
uint64
)
fuse
.
Status
{
f
.
data
=
f
.
data
[
:
size
]
return
OK
return
fuse
.
OK
}
func
(
f
*
MutableDataFile
)
Chown
(
uid
uint32
,
gid
uint32
)
Status
{
func
(
f
*
MutableDataFile
)
Chown
(
uid
uint32
,
gid
uint32
)
fuse
.
Status
{
f
.
Attr
.
Uid
=
uid
f
.
Attr
.
Gid
=
gid
return
OK
return
fuse
.
OK
}
func
(
f
*
MutableDataFile
)
Chmod
(
perms
uint32
)
Status
{
func
(
f
*
MutableDataFile
)
Chmod
(
perms
uint32
)
fuse
.
Status
{
f
.
Attr
.
Mode
=
(
f
.
Attr
.
Mode
&^
07777
)
|
perms
return
OK
return
fuse
.
OK
}
////////////////
// This FS only supports a single r/w file called "/file".
type
FSetAttrFs
struct
{
DefaultFileSystem
fuse
.
DefaultFileSystem
file
*
MutableDataFile
}
func
(
fs
*
FSetAttrFs
)
GetXAttr
(
name
string
,
attr
string
,
context
*
Context
)
([]
byte
,
Status
)
{
return
nil
,
ENODATA
func
(
fs
*
FSetAttrFs
)
GetXAttr
(
name
string
,
attr
string
,
context
*
fuse
.
Context
)
([]
byte
,
fuse
.
Status
)
{
return
nil
,
fuse
.
ENODATA
}
func
(
fs
*
FSetAttrFs
)
GetAttr
(
name
string
,
context
*
Context
)
(
*
Attr
,
Status
)
{
func
(
fs
*
FSetAttrFs
)
GetAttr
(
name
string
,
context
*
fuse
.
Context
)
(
*
fuse
.
Attr
,
fuse
.
Status
)
{
if
name
==
""
{
return
&
Attr
{
Mode
:
S_IFDIR
|
0700
},
OK
return
&
fuse
.
Attr
{
Mode
:
fuse
.
S_IFDIR
|
0700
},
fuse
.
OK
}
if
name
==
"file"
&&
fs
.
file
!=
nil
{
var
a
Attr
var
a
fuse
.
Attr
fs
.
file
.
getAttr
(
&
a
)
a
.
Mode
|=
S_IFREG
return
&
a
,
OK
a
.
Mode
|=
fuse
.
S_IFREG
return
&
a
,
fuse
.
OK
}
return
nil
,
ENOENT
return
nil
,
fuse
.
ENOENT
}
func
(
fs
*
FSetAttrFs
)
Open
(
name
string
,
flags
uint32
,
context
*
Context
)
(
File
,
Status
)
{
func
(
fs
*
FSetAttrFs
)
Open
(
name
string
,
flags
uint32
,
context
*
fuse
.
Context
)
(
fuse
.
File
,
fuse
.
Status
)
{
if
name
==
"file"
{
return
fs
.
file
,
OK
return
fs
.
file
,
fuse
.
OK
}
return
nil
,
ENOENT
return
nil
,
fuse
.
ENOENT
}
func
(
fs
*
FSetAttrFs
)
Create
(
name
string
,
flags
uint32
,
mode
uint32
,
context
*
Context
)
(
File
,
Status
)
{
func
(
fs
*
FSetAttrFs
)
Create
(
name
string
,
flags
uint32
,
mode
uint32
,
context
*
fuse
.
Context
)
(
fuse
.
File
,
fuse
.
Status
)
{
if
name
==
"file"
{
f
:=
NewFile
()
fs
.
file
=
f
fs
.
file
.
Attr
.
Mode
=
mode
return
f
,
OK
return
f
,
fuse
.
OK
}
return
nil
,
ENOENT
return
nil
,
fuse
.
ENOENT
}
func
NewFile
()
*
MutableDataFile
{
return
&
MutableDataFile
{}
}
func
setupFAttrTest
(
t
*
testing
.
T
,
fs
FileSystem
)
(
dir
string
,
clean
func
(),
sync
func
())
{
func
setupFAttrTest
(
t
*
testing
.
T
,
fs
fuse
.
FileSystem
)
(
dir
string
,
clean
func
(),
sync
func
())
{
dir
,
err
:=
ioutil
.
TempDir
(
""
,
"go-fuse-fsetattr_test"
)
if
err
!=
nil
{
t
.
Fatalf
(
"TempDir failed: %v"
,
err
)
}
nfs
:=
NewPathNodeFs
(
fs
,
nil
)
state
,
_
,
err
:=
MountNodeFileSystem
(
dir
,
nfs
,
nil
)
nfs
:=
fuse
.
NewPathNodeFs
(
fs
,
nil
)
state
,
_
,
err
:=
fuse
.
MountNodeFileSystem
(
dir
,
nfs
,
nil
)
if
err
!=
nil
{
t
.
Fatalf
(
"MountNodeFileSystem failed: %v"
,
err
)
}
state
.
Debug
=
VerboseTest
()
state
.
Debug
=
fuse
.
VerboseTest
()
go
state
.
Loop
()
...
...
@@ -233,8 +234,8 @@ func TestFSetAttr(t *testing.T) {
if
err
!=
nil
{
t
.
Fatalf
(
"Stat failed: %v"
,
err
)
}
i1
:=
ToStatT
(
fi
)
.
Ino
i2
:=
ToStatT
(
newFi
)
.
Ino
i1
:=
fuse
.
ToStatT
(
fi
)
.
Ino
i2
:=
fuse
.
ToStatT
(
newFi
)
.
Ino
if
i1
!=
i2
{
t
.
Errorf
(
"f.Lstat().Ino = %d. Returned %d before."
,
i2
,
i1
)
}
...
...
fuse/loopback_darwin_test.go
→
fuse/
test/
loopback_darwin_test.go
View file @
a393c5e2
package
fuse
package
test
import
(
"syscall"
...
...
fuse/loopback_linux_test.go
→
fuse/
test/
loopback_linux_test.go
View file @
a393c5e2
package
fuse
package
test
import
(
"io/ioutil"
...
...
@@ -6,6 +6,7 @@ import (
"syscall"
"testing"
"time"
)
func
TestTouch
(
t
*
testing
.
T
)
{
...
...
fuse/loopback_test.go
→
fuse/
test/
loopback_test.go
View file @
a393c5e2
package
fuse
package
test
import
(
"fmt"
...
...
@@ -14,6 +14,8 @@ import (
"syscall"
"testing"
"time"
"github.com/hanwen/go-fuse/fuse"
)
var
_
=
strings
.
Join
...
...
@@ -34,9 +36,9 @@ type testCase struct {
origFile
string
origSubdir
string
tester
*
testing
.
T
state
*
MountState
pathFs
*
PathNodeFs
connector
*
FileSystemConnector
state
*
fuse
.
MountState
pathFs
*
fuse
.
PathNodeFs
connector
*
fuse
.
FileSystemConnector
}
const
testTtl
=
100
*
time
.
Millisecond
...
...
@@ -45,7 +47,6 @@ const testTtl = 100 * time.Millisecond
func
NewTestCase
(
t
*
testing
.
T
)
*
testCase
{
me
:=
&
testCase
{}
me
.
tester
=
t
paranoia
=
true
// Make sure system setting does not affect test.
syscall
.
Umask
(
0
)
...
...
@@ -69,27 +70,27 @@ func NewTestCase(t *testing.T) *testCase {
me
.
origFile
=
filepath
.
Join
(
me
.
orig
,
name
)
me
.
origSubdir
=
filepath
.
Join
(
me
.
orig
,
subdir
)
var
pfs
FileSystem
pfs
=
NewLoopbackFileSystem
(
me
.
orig
)
pfs
=
NewLockingFileSystem
(
pfs
)
var
pfs
fuse
.
FileSystem
pfs
=
fuse
.
NewLoopbackFileSystem
(
me
.
orig
)
pfs
=
fuse
.
NewLockingFileSystem
(
pfs
)
var
rfs
RawFileSystem
me
.
pathFs
=
NewPathNodeFs
(
pfs
,
&
PathNodeFsOptions
{
var
rfs
fuse
.
RawFileSystem
me
.
pathFs
=
fuse
.
NewPathNodeFs
(
pfs
,
&
fuse
.
PathNodeFsOptions
{
ClientInodes
:
true
})
me
.
connector
=
NewFileSystemConnector
(
me
.
pathFs
,
&
FileSystemOptions
{
me
.
connector
=
fuse
.
NewFileSystemConnector
(
me
.
pathFs
,
&
fuse
.
FileSystemOptions
{
EntryTimeout
:
testTtl
,
AttrTimeout
:
testTtl
,
NegativeTimeout
:
0.0
,
})
rfs
=
me
.
connector
rfs
=
NewLockingRawFileSystem
(
rfs
)
rfs
=
fuse
.
NewLockingRawFileSystem
(
rfs
)
me
.
connector
.
Debug
=
VerboseTest
()
me
.
state
=
NewMountState
(
rfs
)
me
.
connector
.
Debug
=
fuse
.
VerboseTest
()
me
.
state
=
fuse
.
NewMountState
(
rfs
)
me
.
state
.
Mount
(
me
.
mnt
,
nil
)
me
.
state
.
Debug
=
VerboseTest
()
me
.
state
.
Debug
=
fuse
.
VerboseTest
()
// Unthreaded, but in background.
go
me
.
state
.
Loop
()
...
...
@@ -107,7 +108,7 @@ func (tc *testCase) Cleanup() {
os
.
RemoveAll
(
tc
.
tmpDir
)
}
func
(
tc
*
testCase
)
rootNode
()
*
Inode
{
func
(
tc
*
testCase
)
rootNode
()
*
fuse
.
Inode
{
return
tc
.
pathFs
.
Root
()
.
Inode
()
}
...
...
@@ -821,6 +822,14 @@ func TestRootDir(t *testing.T) {
}
}
func
ioctl
(
fd
int
,
cmd
int
,
arg
uintptr
)
(
int
,
int
)
{
r0
,
_
,
e1
:=
syscall
.
Syscall
(
syscall
.
SYS_IOCTL
,
uintptr
(
fd
),
uintptr
(
cmd
),
uintptr
(
arg
))
val
:=
int
(
r0
)
errno
:=
int
(
e1
)
return
val
,
errno
}
func
TestIoctl
(
t
*
testing
.
T
)
{
ts
:=
NewTestCase
(
t
)
defer
ts
.
Cleanup
()
...
...
@@ -919,9 +928,9 @@ func TestOriginalIsSymlink(t *testing.T) {
t
.
Fatalf
(
"Symlink failed: %v"
,
err
)
}
fs
:=
NewLoopbackFileSystem
(
link
)
nfs
:=
NewPathNodeFs
(
fs
,
nil
)
state
,
_
,
err
:=
MountNodeFileSystem
(
mnt
,
nfs
,
nil
)
fs
:=
fuse
.
NewLoopbackFileSystem
(
link
)
nfs
:=
fuse
.
NewPathNodeFs
(
fs
,
nil
)
state
,
_
,
err
:=
fuse
.
MountNodeFileSystem
(
mnt
,
nfs
,
nil
)
if
err
!=
nil
{
t
.
Fatalf
(
"MountNodeFileSystem failed: %v"
,
err
)
}
...
...
fuse/mount_test.go
→
fuse/
test/
mount_test.go
View file @
a393c5e2
package
fuse
package
test
import
(
"io/ioutil"
...
...
@@ -6,6 +6,8 @@ import (
"path/filepath"
"testing"
"time"
"github.com/hanwen/go-fuse/fuse"
)
func
TestMountOnExisting
(
t
*
testing
.
T
)
{
...
...
@@ -16,9 +18,9 @@ func TestMountOnExisting(t *testing.T) {
if
err
!=
nil
{
t
.
Fatalf
(
"Mkdir failed: %v"
,
err
)
}
nfs
:=
&
DefaultNodeFileSystem
{}
nfs
:=
&
fuse
.
DefaultNodeFileSystem
{}
code
:=
ts
.
connector
.
Mount
(
ts
.
rootNode
(),
"mnt"
,
nfs
,
nil
)
if
code
!=
EBUSY
{
if
code
!=
fuse
.
EBUSY
{
t
.
Fatal
(
"expect EBUSY:"
,
code
)
}
...
...
@@ -41,13 +43,13 @@ func TestMountRename(t *testing.T) {
ts
:=
NewTestCase
(
t
)
defer
ts
.
Cleanup
()
fs
:=
NewPathNodeFs
(
NewLoopbackFileSystem
(
ts
.
orig
),
nil
)
fs
:=
fuse
.
NewPathNodeFs
(
fuse
.
NewLoopbackFileSystem
(
ts
.
orig
),
nil
)
code
:=
ts
.
connector
.
Mount
(
ts
.
rootNode
(),
"mnt"
,
fs
,
nil
)
if
!
code
.
Ok
()
{
t
.
Fatal
(
"mount should succeed"
)
}
err
:=
os
.
Rename
(
ts
.
mnt
+
"/mnt"
,
ts
.
mnt
+
"/foobar"
)
if
ToStatus
(
err
)
!=
EBUSY
{
if
fuse
.
ToStatus
(
err
)
!=
fuse
.
EBUSY
{
t
.
Fatal
(
"rename mount point should fail with EBUSY:"
,
err
)
}
ts
.
pathFs
.
Unmount
(
"mnt"
)
...
...
@@ -57,7 +59,7 @@ func TestMountReaddir(t *testing.T) {
ts
:=
NewTestCase
(
t
)
defer
ts
.
Cleanup
()
fs
:=
NewPathNodeFs
(
NewLoopbackFileSystem
(
ts
.
orig
),
nil
)
fs
:=
fuse
.
NewPathNodeFs
(
fuse
.
NewLoopbackFileSystem
(
ts
.
orig
),
nil
)
code
:=
ts
.
connector
.
Mount
(
ts
.
rootNode
(),
"mnt"
,
fs
,
nil
)
if
!
code
.
Ok
()
{
t
.
Fatal
(
"mount should succeed"
)
...
...
@@ -82,7 +84,7 @@ func TestRecursiveMount(t *testing.T) {
t
.
Fatalf
(
"WriteFile failed: %v"
,
err
)
}
fs
:=
NewPathNodeFs
(
NewLoopbackFileSystem
(
ts
.
orig
),
nil
)
fs
:=
fuse
.
NewPathNodeFs
(
fuse
.
NewLoopbackFileSystem
(
ts
.
orig
),
nil
)
code
:=
ts
.
connector
.
Mount
(
ts
.
rootNode
(),
"mnt"
,
fs
,
nil
)
if
!
code
.
Ok
()
{
t
.
Fatal
(
"mount should succeed"
)
...
...
@@ -104,7 +106,7 @@ func TestRecursiveMount(t *testing.T) {
}
t
.
Log
(
"Attempting unmount, should fail"
)
code
=
ts
.
pathFs
.
Unmount
(
"mnt"
)
if
code
!=
EBUSY
{
if
code
!=
fuse
.
EBUSY
{
t
.
Error
(
"expect EBUSY"
)
}
...
...
@@ -114,7 +116,7 @@ func TestRecursiveMount(t *testing.T) {
t
.
Log
(
"Attempting unmount, should succeed"
)
code
=
ts
.
pathFs
.
Unmount
(
"mnt"
)
if
code
!=
OK
{
if
code
!=
fuse
.
OK
{
t
.
Error
(
"umount failed."
,
code
)
}
}
...
...
@@ -124,7 +126,7 @@ func TestDeletedUnmount(t *testing.T) {
defer
ts
.
Cleanup
()
submnt
:=
filepath
.
Join
(
ts
.
mnt
,
"mnt"
)
pfs2
:=
NewPathNodeFs
(
NewLoopbackFileSystem
(
ts
.
orig
),
nil
)
pfs2
:=
fuse
.
NewPathNodeFs
(
fuse
.
NewLoopbackFileSystem
(
ts
.
orig
),
nil
)
code
:=
ts
.
connector
.
Mount
(
ts
.
rootNode
(),
"mnt"
,
pfs2
,
nil
)
if
!
code
.
Ok
()
{
t
.
Fatal
(
"Mount error"
,
code
)
...
...
@@ -147,7 +149,7 @@ func TestDeletedUnmount(t *testing.T) {
}
code
=
ts
.
pathFs
.
Unmount
(
"mnt"
)
if
code
!=
EBUSY
{
if
code
!=
fuse
.
EBUSY
{
t
.
Error
(
"expect EBUSY for unmount with open files"
,
code
)
}
...
...
fuse/notify_test.go
→
fuse/
test/
notify_test.go
View file @
a393c5e2
package
fuse
package
test
import
(
"io/ioutil"
...
...
@@ -6,39 +6,41 @@ import (
"os"
"testing"
"time"
"github.com/hanwen/go-fuse/fuse"
)
var
_
=
log
.
Println
type
NotifyFs
struct
{
DefaultFileSystem
fuse
.
DefaultFileSystem
size
uint64
exist
bool
}
func
(
fs
*
NotifyFs
)
GetAttr
(
name
string
,
context
*
Context
)
(
*
Attr
,
Status
)
{
func
(
fs
*
NotifyFs
)
GetAttr
(
name
string
,
context
*
fuse
.
Context
)
(
*
fuse
.
Attr
,
fuse
.
Status
)
{
if
name
==
""
{
return
&
Attr
{
Mode
:
S_IFDIR
|
0755
},
OK
return
&
fuse
.
Attr
{
Mode
:
fuse
.
S_IFDIR
|
0755
},
fuse
.
OK
}
if
name
==
"file"
||
(
name
==
"dir/file"
&&
fs
.
exist
)
{
return
&
Attr
{
Mode
:
S_IFREG
|
0644
,
Size
:
fs
.
size
},
OK
return
&
fuse
.
Attr
{
Mode
:
fuse
.
S_IFREG
|
0644
,
Size
:
fs
.
size
},
fuse
.
OK
}
if
name
==
"dir"
{
return
&
Attr
{
Mode
:
S_IFDIR
|
0755
},
OK
return
&
fuse
.
Attr
{
Mode
:
fuse
.
S_IFDIR
|
0755
},
fuse
.
OK
}
return
nil
,
ENOENT
return
nil
,
fuse
.
ENOENT
}
func
(
fs
*
NotifyFs
)
Open
(
name
string
,
f
uint32
,
context
*
Context
)
(
File
,
Status
)
{
return
NewDataFile
([]
byte
{
42
}),
OK
func
(
fs
*
NotifyFs
)
Open
(
name
string
,
f
uint32
,
context
*
fuse
.
Context
)
(
fuse
.
File
,
fuse
.
Status
)
{
return
fuse
.
NewDataFile
([]
byte
{
42
}),
fuse
.
OK
}
type
NotifyTest
struct
{
fs
*
NotifyFs
pathfs
*
PathNodeFs
connector
*
FileSystemConnector
pathfs
*
fuse
.
PathNodeFs
connector
*
fuse
.
FileSystemConnector
dir
string
state
*
MountState
state
*
fuse
.
MountState
}
func
NewNotifyTest
(
t
*
testing
.
T
)
*
NotifyTest
{
...
...
@@ -50,18 +52,18 @@ func NewNotifyTest(t *testing.T) *NotifyTest {
t
.
Fatalf
(
"TempDir failed: %v"
,
err
)
}
entryTtl
:=
100
*
time
.
Millisecond
opts
:=
&
FileSystemOptions
{
opts
:=
&
fuse
.
FileSystemOptions
{
EntryTimeout
:
entryTtl
,
AttrTimeout
:
entryTtl
,
NegativeTimeout
:
entryTtl
,
}
me
.
pathfs
=
NewPathNodeFs
(
me
.
fs
,
nil
)
me
.
state
,
me
.
connector
,
err
=
MountNodeFileSystem
(
me
.
dir
,
me
.
pathfs
,
opts
)
me
.
pathfs
=
fuse
.
NewPathNodeFs
(
me
.
fs
,
nil
)
me
.
state
,
me
.
connector
,
err
=
fuse
.
MountNodeFileSystem
(
me
.
dir
,
me
.
pathfs
,
opts
)
if
err
!=
nil
{
t
.
Fatalf
(
"MountNodeFileSystem failed: %v"
,
err
)
}
me
.
state
.
Debug
=
VerboseTest
()
me
.
state
.
Debug
=
fuse
.
VerboseTest
()
go
me
.
state
.
Loop
()
return
me
...
...
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