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
62082623
Commit
62082623
authored
May 26, 2012
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Testing tweaks.
parent
ca8d62a1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
79 additions
and
49 deletions
+79
-49
fuse/fsetattr_test.go
fuse/fsetattr_test.go
+28
-4
fuse/loopback_test.go
fuse/loopback_test.go
+51
-45
No files found.
fuse/fsetattr_test.go
View file @
62082623
...
@@ -22,9 +22,13 @@ func (f *MutableDataFile) String() string {
...
@@ -22,9 +22,13 @@ func (f *MutableDataFile) String() string {
return
"MutableDataFile"
return
"MutableDataFile"
}
}
func
(
f
*
MutableDataFile
)
Read
(
buf
[]
byte
,
off
int64
)
(
r
ReadResult
)
{
func
(
f
*
MutableDataFile
)
Read
(
buf
[]
byte
,
off
int64
)
ReadResult
{
r
.
Data
=
f
.
data
[
off
:
off
+
int64
(
len
(
buf
))]
end
:=
int
(
off
)
+
len
(
buf
)
return
r
if
end
>
len
(
f
.
data
)
{
end
=
len
(
f
.
data
)
}
return
ReadResult
{
Data
:
f
.
data
[
off
:
end
]}
}
}
func
(
f
*
MutableDataFile
)
Write
(
d
[]
byte
,
off
int64
)
(
uint32
,
Status
)
{
func
(
f
*
MutableDataFile
)
Write
(
d
[]
byte
,
off
int64
)
(
uint32
,
Status
)
{
...
@@ -32,9 +36,11 @@ func (f *MutableDataFile) Write(d []byte, off int64) (uint32, Status) {
...
@@ -32,9 +36,11 @@ func (f *MutableDataFile) Write(d []byte, off int64) (uint32, Status) {
if
int
(
end
)
>
len
(
f
.
data
)
{
if
int
(
end
)
>
len
(
f
.
data
)
{
data
:=
make
([]
byte
,
len
(
f
.
data
),
end
)
data
:=
make
([]
byte
,
len
(
f
.
data
),
end
)
copy
(
data
,
f
.
data
)
copy
(
data
,
f
.
data
)
f
.
data
=
data
f
.
data
=
data
[
:
end
]
}
}
copy
(
f
.
data
[
off
:
end
],
d
)
copy
(
f
.
data
[
off
:
end
],
d
)
f
.
Attr
.
Size
=
uint64
(
len
(
f
.
data
))
return
uint32
(
end
-
off
),
OK
return
uint32
(
end
-
off
),
OK
}
}
...
@@ -80,6 +86,7 @@ func (f *MutableDataFile) Chmod(perms uint32) Status {
...
@@ -80,6 +86,7 @@ func (f *MutableDataFile) Chmod(perms uint32) Status {
////////////////
////////////////
// This FS only supports a single r/w file called "/file".
type
FSetAttrFs
struct
{
type
FSetAttrFs
struct
{
DefaultFileSystem
DefaultFileSystem
file
*
MutableDataFile
file
*
MutableDataFile
...
@@ -146,6 +153,22 @@ func setupFAttrTest(t *testing.T, fs FileSystem) (dir string, clean func()) {
...
@@ -146,6 +153,22 @@ func setupFAttrTest(t *testing.T, fs FileSystem) (dir string, clean func()) {
}
}
}
}
func
TestDataReadLarge
(
t
*
testing
.
T
)
{
fs
:=
&
FSetAttrFs
{}
dir
,
clean
:=
setupFAttrTest
(
t
,
fs
)
defer
clean
()
content
:=
RandomData
(
385
*
1023
)
fn
:=
dir
+
"/file"
err
:=
ioutil
.
WriteFile
(
fn
,
[]
byte
(
content
),
0644
)
CheckSuccess
(
err
)
back
,
err
:=
ioutil
.
ReadFile
(
fn
)
CheckSuccess
(
err
)
CompareSlices
(
t
,
back
,
content
)
}
func
TestFSetAttr
(
t
*
testing
.
T
)
{
func
TestFSetAttr
(
t
*
testing
.
T
)
{
fs
:=
&
FSetAttrFs
{}
fs
:=
&
FSetAttrFs
{}
dir
,
clean
:=
setupFAttrTest
(
t
,
fs
)
dir
,
clean
:=
setupFAttrTest
(
t
,
fs
)
...
@@ -192,3 +215,4 @@ func TestFSetAttr(t *testing.T) {
...
@@ -192,3 +215,4 @@ func TestFSetAttr(t *testing.T) {
}
}
// TODO - test chown if run as root.
// TODO - test chown if run as root.
}
}
fuse/loopback_test.go
View file @
62082623
...
@@ -21,7 +21,6 @@ var _ = log.Println
...
@@ -21,7 +21,6 @@ var _ = log.Println
////////////////
////////////////
// state for our testcase, mostly constants
// state for our testcase, mostly constants
const
contents
string
=
"ABC"
const
mode
uint32
=
0757
const
mode
uint32
=
0757
type
testCase
struct
{
type
testCase
struct
{
...
@@ -121,6 +120,7 @@ func TestTouch(t *testing.T) {
...
@@ -121,6 +120,7 @@ func TestTouch(t *testing.T) {
ts
:=
NewTestCase
(
t
)
ts
:=
NewTestCase
(
t
)
defer
ts
.
Cleanup
()
defer
ts
.
Cleanup
()
contents
:=
[]
byte
{
1
,
2
,
3
}
err
:=
ioutil
.
WriteFile
(
ts
.
origFile
,
[]
byte
(
contents
),
0700
)
err
:=
ioutil
.
WriteFile
(
ts
.
origFile
,
[]
byte
(
contents
),
0700
)
CheckSuccess
(
err
)
CheckSuccess
(
err
)
err
=
os
.
Chtimes
(
ts
.
mountFile
,
time
.
Unix
(
42
,
0
),
time
.
Unix
(
43
,
0
))
err
=
os
.
Chtimes
(
ts
.
mountFile
,
time
.
Unix
(
42
,
0
),
time
.
Unix
(
43
,
0
))
...
@@ -138,7 +138,8 @@ func TestReadThrough(t *testing.T) {
...
@@ -138,7 +138,8 @@ func TestReadThrough(t *testing.T) {
ts
:=
NewTestCase
(
t
)
ts
:=
NewTestCase
(
t
)
defer
ts
.
Cleanup
()
defer
ts
.
Cleanup
()
err
:=
ioutil
.
WriteFile
(
ts
.
origFile
,
[]
byte
(
contents
),
0700
)
content
:=
RandomData
(
125
)
err
:=
ioutil
.
WriteFile
(
ts
.
origFile
,
content
,
0700
)
CheckSuccess
(
err
)
CheckSuccess
(
err
)
err
=
os
.
Chmod
(
ts
.
mountFile
,
os
.
FileMode
(
mode
))
err
=
os
.
Chmod
(
ts
.
mountFile
,
os
.
FileMode
(
mode
))
...
@@ -158,16 +159,14 @@ func TestReadThrough(t *testing.T) {
...
@@ -158,16 +159,14 @@ func TestReadThrough(t *testing.T) {
var
buf
[
1024
]
byte
var
buf
[
1024
]
byte
slice
:=
buf
[
:
]
slice
:=
buf
[
:
]
n
,
err
:=
f
.
Read
(
slice
)
n
,
err
:=
f
.
Read
(
slice
)
CompareSlices
(
t
,
slice
[
:
n
],
content
)
if
len
(
slice
[
:
n
])
!=
len
(
contents
)
{
t
.
Errorf
(
"Content error %v"
,
slice
)
}
}
}
func
TestRemove
(
t
*
testing
.
T
)
{
func
TestRemove
(
t
*
testing
.
T
)
{
tc
:=
NewTestCase
(
t
)
tc
:=
NewTestCase
(
t
)
defer
tc
.
Cleanup
()
defer
tc
.
Cleanup
()
contents
:=
[]
byte
{
1
,
2
,
3
}
err
:=
ioutil
.
WriteFile
(
tc
.
origFile
,
[]
byte
(
contents
),
0700
)
err
:=
ioutil
.
WriteFile
(
tc
.
origFile
,
[]
byte
(
contents
),
0700
)
CheckSuccess
(
err
)
CheckSuccess
(
err
)
...
@@ -188,10 +187,11 @@ func TestWriteThrough(t *testing.T) {
...
@@ -188,10 +187,11 @@ func TestWriteThrough(t *testing.T) {
CheckSuccess
(
err
)
CheckSuccess
(
err
)
defer
f
.
Close
()
defer
f
.
Close
()
n
,
err
:=
f
.
WriteString
(
contents
)
content
:=
RandomData
(
125
)
n
,
err
:=
f
.
Write
(
content
)
CheckSuccess
(
err
)
CheckSuccess
(
err
)
if
n
!=
len
(
content
s
)
{
if
n
!=
len
(
content
)
{
t
.
Errorf
(
"Write mismatch: %v of %v"
,
n
,
len
(
content
s
))
t
.
Errorf
(
"Write mismatch: %v of %v"
,
n
,
len
(
content
))
}
}
fi
,
err
:=
os
.
Lstat
(
tc
.
origFile
)
fi
,
err
:=
os
.
Lstat
(
tc
.
origFile
)
...
@@ -207,9 +207,7 @@ func TestWriteThrough(t *testing.T) {
...
@@ -207,9 +207,7 @@ func TestWriteThrough(t *testing.T) {
slice
:=
buf
[
:
]
slice
:=
buf
[
:
]
n
,
err
=
f
.
Read
(
slice
)
n
,
err
=
f
.
Read
(
slice
)
CheckSuccess
(
err
)
CheckSuccess
(
err
)
if
string
(
slice
[
:
n
])
!=
contents
{
CompareSlices
(
t
,
slice
[
:
n
],
content
)
t
.
Errorf
(
"write contents error. Got: %v, expect: %v"
,
string
(
slice
[
:
n
]),
contents
)
}
}
}
func
TestMkdirRmdir
(
t
*
testing
.
T
)
{
func
TestMkdirRmdir
(
t
*
testing
.
T
)
{
...
@@ -232,7 +230,8 @@ func TestLinkCreate(t *testing.T) {
...
@@ -232,7 +230,8 @@ func TestLinkCreate(t *testing.T) {
tc
:=
NewTestCase
(
t
)
tc
:=
NewTestCase
(
t
)
defer
tc
.
Cleanup
()
defer
tc
.
Cleanup
()
err
:=
ioutil
.
WriteFile
(
tc
.
origFile
,
[]
byte
(
contents
),
0700
)
content
:=
RandomData
(
125
)
err
:=
ioutil
.
WriteFile
(
tc
.
origFile
,
content
,
0700
)
CheckSuccess
(
err
)
CheckSuccess
(
err
)
err
=
os
.
Mkdir
(
tc
.
origSubdir
,
0777
)
err
=
os
.
Mkdir
(
tc
.
origSubdir
,
0777
)
CheckSuccess
(
err
)
CheckSuccess
(
err
)
...
@@ -256,10 +255,7 @@ func TestLinkCreate(t *testing.T) {
...
@@ -256,10 +255,7 @@ func TestLinkCreate(t *testing.T) {
}
}
readback
,
err
:=
ioutil
.
ReadFile
(
mountSubfile
)
readback
,
err
:=
ioutil
.
ReadFile
(
mountSubfile
)
CheckSuccess
(
err
)
CheckSuccess
(
err
)
CompareSlices
(
t
,
readback
,
content
)
if
string
(
readback
)
!=
contents
{
t
.
Errorf
(
"Content error: got %q want %q"
,
string
(
readback
),
contents
)
}
err
=
os
.
Remove
(
tc
.
mountFile
)
err
=
os
.
Remove
(
tc
.
mountFile
)
CheckSuccess
(
err
)
CheckSuccess
(
err
)
...
@@ -274,9 +270,9 @@ func TestLinkExisting(t *testing.T) {
...
@@ -274,9 +270,9 @@ func TestLinkExisting(t *testing.T) {
tc
:=
NewTestCase
(
t
)
tc
:=
NewTestCase
(
t
)
defer
tc
.
Cleanup
()
defer
tc
.
Cleanup
()
c
:=
"hello"
c
:=
RandomData
(
5
)
err
:=
ioutil
.
WriteFile
(
tc
.
orig
+
"/file1"
,
[]
byte
(
c
)
,
0644
)
err
:=
ioutil
.
WriteFile
(
tc
.
orig
+
"/file1"
,
c
,
0644
)
CheckSuccess
(
err
)
CheckSuccess
(
err
)
err
=
os
.
Link
(
tc
.
orig
+
"/file1"
,
tc
.
orig
+
"/file2"
)
err
=
os
.
Link
(
tc
.
orig
+
"/file1"
,
tc
.
orig
+
"/file2"
)
CheckSuccess
(
err
)
CheckSuccess
(
err
)
...
@@ -291,11 +287,9 @@ func TestLinkExisting(t *testing.T) {
...
@@ -291,11 +287,9 @@ func TestLinkExisting(t *testing.T) {
t
.
Errorf
(
"linked files should have identical inodes %v %v"
,
s1
.
Ino
,
s2
.
Ino
)
t
.
Errorf
(
"linked files should have identical inodes %v %v"
,
s1
.
Ino
,
s2
.
Ino
)
}
}
c1
,
err
:=
ioutil
.
ReadFile
(
tc
.
mnt
+
"/file1"
)
back
,
err
:=
ioutil
.
ReadFile
(
tc
.
mnt
+
"/file1"
)
CheckSuccess
(
err
)
CheckSuccess
(
err
)
if
string
(
c1
)
!=
c
{
CompareSlices
(
t
,
back
,
c
)
t
.
Errorf
(
"Content mismatch relative to original."
)
}
}
}
// Deal correctly with hard links implied by matching client inode
// Deal correctly with hard links implied by matching client inode
...
@@ -329,6 +323,7 @@ func TestSymlink(t *testing.T) {
...
@@ -329,6 +323,7 @@ func TestSymlink(t *testing.T) {
defer
tc
.
Cleanup
()
defer
tc
.
Cleanup
()
t
.
Log
(
"testing symlink/readlink."
)
t
.
Log
(
"testing symlink/readlink."
)
contents
:=
[]
byte
{
1
,
2
,
3
}
err
:=
ioutil
.
WriteFile
(
tc
.
origFile
,
[]
byte
(
contents
),
0700
)
err
:=
ioutil
.
WriteFile
(
tc
.
origFile
,
[]
byte
(
contents
),
0700
)
CheckSuccess
(
err
)
CheckSuccess
(
err
)
...
@@ -359,7 +354,7 @@ func TestRename(t *testing.T) {
...
@@ -359,7 +354,7 @@ func TestRename(t *testing.T) {
tc
:=
NewTestCase
(
t
)
tc
:=
NewTestCase
(
t
)
defer
tc
.
Cleanup
()
defer
tc
.
Cleanup
()
t
.
Log
(
"Testing rename."
)
contents
:=
[]
byte
{
1
,
2
,
3
}
err
:=
ioutil
.
WriteFile
(
tc
.
origFile
,
[]
byte
(
contents
),
0700
)
err
:=
ioutil
.
WriteFile
(
tc
.
origFile
,
[]
byte
(
contents
),
0700
)
CheckSuccess
(
err
)
CheckSuccess
(
err
)
sd
:=
tc
.
mnt
+
"/testRename"
sd
:=
tc
.
mnt
+
"/testRename"
...
@@ -438,6 +433,7 @@ func TestAccess(t *testing.T) {
...
@@ -438,6 +433,7 @@ func TestAccess(t *testing.T) {
tc
:=
NewTestCase
(
t
)
tc
:=
NewTestCase
(
t
)
defer
tc
.
Cleanup
()
defer
tc
.
Cleanup
()
contents
:=
[]
byte
{
1
,
2
,
3
}
err
:=
ioutil
.
WriteFile
(
tc
.
origFile
,
[]
byte
(
contents
),
0700
)
err
:=
ioutil
.
WriteFile
(
tc
.
origFile
,
[]
byte
(
contents
),
0700
)
CheckSuccess
(
err
)
CheckSuccess
(
err
)
err
=
os
.
Chmod
(
tc
.
origFile
,
0
)
err
=
os
.
Chmod
(
tc
.
origFile
,
0
)
...
@@ -476,7 +472,7 @@ func TestReaddir(t *testing.T) {
...
@@ -476,7 +472,7 @@ func TestReaddir(t *testing.T) {
tc
:=
NewTestCase
(
t
)
tc
:=
NewTestCase
(
t
)
defer
tc
.
Cleanup
()
defer
tc
.
Cleanup
()
t
.
Log
(
"Testing readdir."
)
contents
:=
[]
byte
{
1
,
2
,
3
}
err
:=
ioutil
.
WriteFile
(
tc
.
origFile
,
[]
byte
(
contents
),
0700
)
err
:=
ioutil
.
WriteFile
(
tc
.
origFile
,
[]
byte
(
contents
),
0700
)
CheckSuccess
(
err
)
CheckSuccess
(
err
)
err
=
os
.
Mkdir
(
tc
.
origSubdir
,
0777
)
err
=
os
.
Mkdir
(
tc
.
origSubdir
,
0777
)
...
@@ -509,7 +505,7 @@ func TestFSync(t *testing.T) {
...
@@ -509,7 +505,7 @@ func TestFSync(t *testing.T) {
tc
:=
NewTestCase
(
t
)
tc
:=
NewTestCase
(
t
)
defer
tc
.
Cleanup
()
defer
tc
.
Cleanup
()
t
.
Log
(
"Testing fsync."
)
contents
:=
[]
byte
{
1
,
2
,
3
}
err
:=
ioutil
.
WriteFile
(
tc
.
origFile
,
[]
byte
(
contents
),
0700
)
err
:=
ioutil
.
WriteFile
(
tc
.
origFile
,
[]
byte
(
contents
),
0700
)
CheckSuccess
(
err
)
CheckSuccess
(
err
)
...
@@ -518,9 +514,9 @@ func TestFSync(t *testing.T) {
...
@@ -518,9 +514,9 @@ func TestFSync(t *testing.T) {
CheckSuccess
(
err
)
CheckSuccess
(
err
)
// How to really test fsync ?
// How to really test fsync ?
err
No
:
=
syscall
.
Fsync
(
int
(
f
.
Fd
()))
err
=
syscall
.
Fsync
(
int
(
f
.
Fd
()))
if
err
No
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"fsync returned
%v"
,
errNo
)
t
.
Errorf
(
"fsync returned
: %v"
,
err
)
}
}
f
.
Close
()
f
.
Close
()
}
}
...
@@ -538,14 +534,11 @@ func TestReadZero(t *testing.T) {
...
@@ -538,14 +534,11 @@ func TestReadZero(t *testing.T) {
}
}
}
}
func
TestReadLarge
(
t
*
testing
.
T
)
{
func
RandomData
(
size
int
)
[]
byte
{
ts
:=
NewTestCase
(
t
)
defer
ts
.
Cleanup
()
// Make blocks that are not period on 1024 bytes, so we can
// Make blocks that are not period on 1024 bytes, so we can
// catch errors due to misalignments.
// catch errors due to misalignments.
block
:=
make
([]
byte
,
1023
)
block
:=
make
([]
byte
,
1023
)
content
:=
make
([]
byte
,
385
*
1023
)
content
:=
make
([]
byte
,
size
)
for
i
:=
range
block
{
for
i
:=
range
block
{
block
[
i
]
=
byte
(
i
)
block
[
i
]
=
byte
(
i
)
}
}
...
@@ -559,24 +552,37 @@ func TestReadLarge(t *testing.T) {
...
@@ -559,24 +552,37 @@ func TestReadLarge(t *testing.T) {
copy
(
content
[
start
:
],
block
)
copy
(
content
[
start
:
],
block
)
start
+=
len
(
block
)
start
+=
len
(
block
)
}
}
return
content
}
err
:=
ioutil
.
WriteFile
(
ts
.
origFile
,
[]
byte
(
content
),
0644
)
CheckSuccess
(
err
)
back
,
err
:=
ioutil
.
ReadFile
(
ts
.
mountFile
)
func
CompareSlices
(
t
*
testing
.
T
,
got
,
want
[]
byte
)
{
CheckSuccess
(
err
)
if
len
(
got
)
!=
len
(
want
)
{
if
len
(
back
)
!=
len
(
content
)
{
t
.
Errorf
(
"content length: got %d want %d"
,
len
(
got
),
len
(
want
))
t
.
Errorf
(
"content length: got %d want %d"
,
len
(
back
),
len
(
content
))
}
}
for
i
:=
range
content
{
for
i
:=
range
want
{
if
content
[
i
]
!=
back
[
i
]
{
if
i
>=
len
(
got
)
{
t
.
Errorf
(
"content mismatch byte %d, got %d want %d."
,
i
,
back
[
i
],
content
[
i
])
break
}
if
want
[
i
]
!=
got
[
i
]
{
t
.
Errorf
(
"content mismatch byte %d, got %d want %d."
,
i
,
got
[
i
],
want
[
i
])
break
break
}
}
}
}
}
}
func
TestReadLarge
(
t
*
testing
.
T
)
{
ts
:=
NewTestCase
(
t
)
defer
ts
.
Cleanup
()
content
:=
RandomData
(
385
*
1023
)
err
:=
ioutil
.
WriteFile
(
ts
.
origFile
,
[]
byte
(
content
),
0644
)
CheckSuccess
(
err
)
back
,
err
:=
ioutil
.
ReadFile
(
ts
.
mountFile
)
CheckSuccess
(
err
)
CompareSlices
(
t
,
back
,
content
)
}
func
randomLengthString
(
length
int
)
string
{
func
randomLengthString
(
length
int
)
string
{
r
:=
rand
.
Intn
(
length
)
r
:=
rand
.
Intn
(
length
)
j
:=
0
j
:=
0
...
...
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