Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jacobsa-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
jacobsa-fuse
Commits
4db81d44
Commit
4db81d44
authored
Dec 14, 2015
by
Aaron Jacobs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pasted MknodTest from googlecloudplatform/gcsfuse@ff8a3f0.
parent
1dcc6791
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
98 additions
and
5 deletions
+98
-5
samples/memfs/memfs_test.go
samples/memfs/memfs_test.go
+98
-5
No files found.
samples/memfs/memfs_test.go
View file @
4db81d44
...
...
@@ -21,6 +21,7 @@ import (
"os"
"os/user"
"path"
"runtime"
"strconv"
"syscall"
"testing"
...
...
@@ -87,21 +88,25 @@ func applyUmask(m os.FileMode) os.FileMode {
// Boilerplate
////////////////////////////////////////////////////////////////////////
type
M
emFSTest
struct
{
type
m
emFSTest
struct
{
samples
.
SampleTest
}
func
init
()
{
RegisterTestSuite
(
&
MemFSTest
{})
}
func
(
t
*
MemFSTest
)
SetUp
(
ti
*
TestInfo
)
{
func
(
t
*
memFSTest
)
SetUp
(
ti
*
TestInfo
)
{
t
.
Server
=
memfs
.
NewMemFS
(
currentUid
(),
currentGid
())
t
.
SampleTest
.
SetUp
(
ti
)
}
////////////////////////////////////////////////////////////////////////
//
Test function
s
//
Basic
s
////////////////////////////////////////////////////////////////////////
type
MemFSTest
struct
{
memFSTest
}
func
init
()
{
RegisterTestSuite
(
&
MemFSTest
{})
}
func
(
t
*
MemFSTest
)
ContentsOfEmptyFileSystem
()
{
entries
,
err
:=
fusetesting
.
ReadDirPicky
(
t
.
Dir
)
...
...
@@ -1614,3 +1619,91 @@ func (t *MemFSTest) RenameNonExistentFile() {
err
=
os
.
Rename
(
path
.
Join
(
t
.
Dir
,
"foo"
),
path
.
Join
(
t
.
Dir
,
"bar"
))
ExpectThat
(
err
,
Error
(
HasSubstr
(
"no such file"
)))
}
////////////////////////////////////////////////////////////////////////
// Mknod
////////////////////////////////////////////////////////////////////////
type
MknodTest
struct
{
memFSTest
}
func
init
()
{
RegisterTestSuite
(
&
MknodTest
{})
}
func
(
t
*
MknodTest
)
File
()
{
// mknod(2) only works for root on OS X.
if
runtime
.
GOOS
==
"darwin"
{
return
}
var
err
error
p
:=
path
.
Join
(
t
.
mfs
.
Dir
(),
"foo"
)
// Create
err
=
syscall
.
Mknod
(
p
,
syscall
.
S_IFREG
|
0600
,
0
)
AssertEq
(
nil
,
err
)
// Stat
fi
,
err
:=
os
.
Stat
(
p
)
AssertEq
(
nil
,
err
)
ExpectEq
(
path
.
Base
(
p
),
fi
.
Name
())
ExpectEq
(
0
,
fi
.
Size
())
ExpectEq
(
filePerms
,
fi
.
Mode
())
// Read
contents
,
err
:=
ioutil
.
ReadFile
(
p
)
AssertEq
(
nil
,
err
)
ExpectEq
(
""
,
string
(
contents
))
}
func
(
t
*
MknodTest
)
Directory
()
{
// mknod(2) only works for root on OS X.
if
runtime
.
GOOS
==
"darwin"
{
return
}
var
err
error
p
:=
path
.
Join
(
t
.
mfs
.
Dir
(),
"foo"
)
// Quoth `man 2 mknod`: "Under Linux, this call cannot be used to create
// directories."
err
=
syscall
.
Mknod
(
p
,
syscall
.
S_IFDIR
|
0700
,
0
)
ExpectEq
(
syscall
.
EPERM
,
err
)
}
func
(
t
*
MknodTest
)
AlreadyExists
()
{
// mknod(2) only works for root on OS X.
if
runtime
.
GOOS
==
"darwin"
{
return
}
var
err
error
p
:=
path
.
Join
(
t
.
mfs
.
Dir
(),
"foo"
)
// Create (first)
err
=
ioutil
.
WriteFile
(
p
,
[]
byte
(
"taco"
),
0600
)
AssertEq
(
nil
,
err
)
// Create (second)
err
=
syscall
.
Mknod
(
p
,
syscall
.
S_IFREG
|
0600
,
0
)
ExpectEq
(
syscall
.
EEXIST
,
err
)
// Read
contents
,
err
:=
ioutil
.
ReadFile
(
p
)
AssertEq
(
nil
,
err
)
ExpectEq
(
"taco"
,
string
(
contents
))
}
func
(
t
*
MknodTest
)
NonExistentParent
()
{
// mknod(2) only works for root on OS X.
if
runtime
.
GOOS
==
"darwin"
{
return
}
var
err
error
p
:=
path
.
Join
(
t
.
mfs
.
Dir
(),
"foo/bar"
)
err
=
syscall
.
Mknod
(
p
,
syscall
.
S_IFREG
|
0600
,
0
)
ExpectEq
(
syscall
.
ENOENT
,
err
)
}
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