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 {
return
"MutableDataFile"
}
func
(
f
*
MutableDataFile
)
Read
(
buf
[]
byte
,
off
int64
)
(
r
ReadResult
)
{
r
.
Data
=
f
.
data
[
off
:
off
+
int64
(
len
(
buf
))]
return
r
func
(
f
*
MutableDataFile
)
Read
(
buf
[]
byte
,
off
int64
)
ReadResult
{
end
:=
int
(
off
)
+
len
(
buf
)
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
)
{
...
...
@@ -32,9 +36,11 @@ func (f *MutableDataFile) Write(d []byte, off int64) (uint32, Status) {
if
int
(
end
)
>
len
(
f
.
data
)
{
data
:=
make
([]
byte
,
len
(
f
.
data
),
end
)
copy
(
data
,
f
.
data
)
f
.
data
=
data
f
.
data
=
data
[
:
end
]
}
copy
(
f
.
data
[
off
:
end
],
d
)
f
.
Attr
.
Size
=
uint64
(
len
(
f
.
data
))
return
uint32
(
end
-
off
),
OK
}
...
...
@@ -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
{
DefaultFileSystem
file
*
MutableDataFile
...
...
@@ -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
)
{
fs
:=
&
FSetAttrFs
{}
dir
,
clean
:=
setupFAttrTest
(
t
,
fs
)
...
...
@@ -192,3 +215,4 @@ func TestFSetAttr(t *testing.T) {
}
// TODO - test chown if run as root.
}
fuse/loopback_test.go
View file @
62082623
...
...
@@ -21,7 +21,6 @@ var _ = log.Println
////////////////
// state for our testcase, mostly constants
const
contents
string
=
"ABC"
const
mode
uint32
=
0757
type
testCase
struct
{
...
...
@@ -121,6 +120,7 @@ func TestTouch(t *testing.T) {
ts
:=
NewTestCase
(
t
)
defer
ts
.
Cleanup
()
contents
:=
[]
byte
{
1
,
2
,
3
}
err
:=
ioutil
.
WriteFile
(
ts
.
origFile
,
[]
byte
(
contents
),
0700
)
CheckSuccess
(
err
)
err
=
os
.
Chtimes
(
ts
.
mountFile
,
time
.
Unix
(
42
,
0
),
time
.
Unix
(
43
,
0
))
...
...
@@ -138,7 +138,8 @@ func TestReadThrough(t *testing.T) {
ts
:=
NewTestCase
(
t
)
defer
ts
.
Cleanup
()
err
:=
ioutil
.
WriteFile
(
ts
.
origFile
,
[]
byte
(
contents
),
0700
)
content
:=
RandomData
(
125
)
err
:=
ioutil
.
WriteFile
(
ts
.
origFile
,
content
,
0700
)
CheckSuccess
(
err
)
err
=
os
.
Chmod
(
ts
.
mountFile
,
os
.
FileMode
(
mode
))
...
...
@@ -158,16 +159,14 @@ func TestReadThrough(t *testing.T) {
var
buf
[
1024
]
byte
slice
:=
buf
[
:
]
n
,
err
:=
f
.
Read
(
slice
)
if
len
(
slice
[
:
n
])
!=
len
(
contents
)
{
t
.
Errorf
(
"Content error %v"
,
slice
)
}
CompareSlices
(
t
,
slice
[
:
n
],
content
)
}
func
TestRemove
(
t
*
testing
.
T
)
{
tc
:=
NewTestCase
(
t
)
defer
tc
.
Cleanup
()
contents
:=
[]
byte
{
1
,
2
,
3
}
err
:=
ioutil
.
WriteFile
(
tc
.
origFile
,
[]
byte
(
contents
),
0700
)
CheckSuccess
(
err
)
...
...
@@ -188,10 +187,11 @@ func TestWriteThrough(t *testing.T) {
CheckSuccess
(
err
)
defer
f
.
Close
()
n
,
err
:=
f
.
WriteString
(
contents
)
content
:=
RandomData
(
125
)
n
,
err
:=
f
.
Write
(
content
)
CheckSuccess
(
err
)
if
n
!=
len
(
content
s
)
{
t
.
Errorf
(
"Write mismatch: %v of %v"
,
n
,
len
(
content
s
))
if
n
!=
len
(
content
)
{
t
.
Errorf
(
"Write mismatch: %v of %v"
,
n
,
len
(
content
))
}
fi
,
err
:=
os
.
Lstat
(
tc
.
origFile
)
...
...
@@ -207,9 +207,7 @@ func TestWriteThrough(t *testing.T) {
slice
:=
buf
[
:
]
n
,
err
=
f
.
Read
(
slice
)
CheckSuccess
(
err
)
if
string
(
slice
[
:
n
])
!=
contents
{
t
.
Errorf
(
"write contents error. Got: %v, expect: %v"
,
string
(
slice
[
:
n
]),
contents
)
}
CompareSlices
(
t
,
slice
[
:
n
],
content
)
}
func
TestMkdirRmdir
(
t
*
testing
.
T
)
{
...
...
@@ -232,7 +230,8 @@ func TestLinkCreate(t *testing.T) {
tc
:=
NewTestCase
(
t
)
defer
tc
.
Cleanup
()
err
:=
ioutil
.
WriteFile
(
tc
.
origFile
,
[]
byte
(
contents
),
0700
)
content
:=
RandomData
(
125
)
err
:=
ioutil
.
WriteFile
(
tc
.
origFile
,
content
,
0700
)
CheckSuccess
(
err
)
err
=
os
.
Mkdir
(
tc
.
origSubdir
,
0777
)
CheckSuccess
(
err
)
...
...
@@ -256,10 +255,7 @@ func TestLinkCreate(t *testing.T) {
}
readback
,
err
:=
ioutil
.
ReadFile
(
mountSubfile
)
CheckSuccess
(
err
)
if
string
(
readback
)
!=
contents
{
t
.
Errorf
(
"Content error: got %q want %q"
,
string
(
readback
),
contents
)
}
CompareSlices
(
t
,
readback
,
content
)
err
=
os
.
Remove
(
tc
.
mountFile
)
CheckSuccess
(
err
)
...
...
@@ -274,9 +270,9 @@ func TestLinkExisting(t *testing.T) {
tc
:=
NewTestCase
(
t
)
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
)
err
=
os
.
Link
(
tc
.
orig
+
"/file1"
,
tc
.
orig
+
"/file2"
)
CheckSuccess
(
err
)
...
...
@@ -291,11 +287,9 @@ func TestLinkExisting(t *testing.T) {
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
)
if
string
(
c1
)
!=
c
{
t
.
Errorf
(
"Content mismatch relative to original."
)
}
CompareSlices
(
t
,
back
,
c
)
}
// Deal correctly with hard links implied by matching client inode
...
...
@@ -329,6 +323,7 @@ func TestSymlink(t *testing.T) {
defer
tc
.
Cleanup
()
t
.
Log
(
"testing symlink/readlink."
)
contents
:=
[]
byte
{
1
,
2
,
3
}
err
:=
ioutil
.
WriteFile
(
tc
.
origFile
,
[]
byte
(
contents
),
0700
)
CheckSuccess
(
err
)
...
...
@@ -359,7 +354,7 @@ func TestRename(t *testing.T) {
tc
:=
NewTestCase
(
t
)
defer
tc
.
Cleanup
()
t
.
Log
(
"Testing rename."
)
contents
:=
[]
byte
{
1
,
2
,
3
}
err
:=
ioutil
.
WriteFile
(
tc
.
origFile
,
[]
byte
(
contents
),
0700
)
CheckSuccess
(
err
)
sd
:=
tc
.
mnt
+
"/testRename"
...
...
@@ -438,6 +433,7 @@ func TestAccess(t *testing.T) {
tc
:=
NewTestCase
(
t
)
defer
tc
.
Cleanup
()
contents
:=
[]
byte
{
1
,
2
,
3
}
err
:=
ioutil
.
WriteFile
(
tc
.
origFile
,
[]
byte
(
contents
),
0700
)
CheckSuccess
(
err
)
err
=
os
.
Chmod
(
tc
.
origFile
,
0
)
...
...
@@ -476,7 +472,7 @@ func TestReaddir(t *testing.T) {
tc
:=
NewTestCase
(
t
)
defer
tc
.
Cleanup
()
t
.
Log
(
"Testing readdir."
)
contents
:=
[]
byte
{
1
,
2
,
3
}
err
:=
ioutil
.
WriteFile
(
tc
.
origFile
,
[]
byte
(
contents
),
0700
)
CheckSuccess
(
err
)
err
=
os
.
Mkdir
(
tc
.
origSubdir
,
0777
)
...
...
@@ -509,7 +505,7 @@ func TestFSync(t *testing.T) {
tc
:=
NewTestCase
(
t
)
defer
tc
.
Cleanup
()
t
.
Log
(
"Testing fsync."
)
contents
:=
[]
byte
{
1
,
2
,
3
}
err
:=
ioutil
.
WriteFile
(
tc
.
origFile
,
[]
byte
(
contents
),
0700
)
CheckSuccess
(
err
)
...
...
@@ -518,9 +514,9 @@ func TestFSync(t *testing.T) {
CheckSuccess
(
err
)
// How to really test fsync ?
err
No
:
=
syscall
.
Fsync
(
int
(
f
.
Fd
()))
if
err
No
!=
nil
{
t
.
Errorf
(
"fsync returned
%v"
,
errNo
)
err
=
syscall
.
Fsync
(
int
(
f
.
Fd
()))
if
err
!=
nil
{
t
.
Errorf
(
"fsync returned
: %v"
,
err
)
}
f
.
Close
()
}
...
...
@@ -538,14 +534,11 @@ func TestReadZero(t *testing.T) {
}
}
func
TestReadLarge
(
t
*
testing
.
T
)
{
ts
:=
NewTestCase
(
t
)
defer
ts
.
Cleanup
()
func
RandomData
(
size
int
)
[]
byte
{
// Make blocks that are not period on 1024 bytes, so we can
// catch errors due to misalignments.
block
:=
make
([]
byte
,
1023
)
content
:=
make
([]
byte
,
385
*
1023
)
content
:=
make
([]
byte
,
size
)
for
i
:=
range
block
{
block
[
i
]
=
byte
(
i
)
}
...
...
@@ -559,24 +552,37 @@ func TestReadLarge(t *testing.T) {
copy
(
content
[
start
:
],
block
)
start
+=
len
(
block
)
}
err
:=
ioutil
.
WriteFile
(
ts
.
origFile
,
[]
byte
(
content
),
0644
)
CheckSuccess
(
err
)
return
content
}
back
,
err
:=
ioutil
.
ReadFile
(
ts
.
mountFile
)
CheckSuccess
(
err
)
if
len
(
back
)
!=
len
(
content
)
{
t
.
Errorf
(
"content length: got %d want %d"
,
len
(
back
),
len
(
content
))
func
CompareSlices
(
t
*
testing
.
T
,
got
,
want
[]
byte
)
{
if
len
(
got
)
!=
len
(
want
)
{
t
.
Errorf
(
"content length: got %d want %d"
,
len
(
got
),
len
(
want
))
}
for
i
:=
range
content
{
if
content
[
i
]
!=
back
[
i
]
{
t
.
Errorf
(
"content mismatch byte %d, got %d want %d."
,
i
,
back
[
i
],
content
[
i
])
for
i
:=
range
want
{
if
i
>=
len
(
got
)
{
break
}
if
want
[
i
]
!=
got
[
i
]
{
t
.
Errorf
(
"content mismatch byte %d, got %d want %d."
,
i
,
got
[
i
],
want
[
i
])
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
{
r
:=
rand
.
Intn
(
length
)
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