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
ba6e6956
Commit
ba6e6956
authored
Apr 29, 2011
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
UnionFs: use ioutil.WriteFile in tests.
parent
844c2d15
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
30 deletions
+20
-30
unionfs/unionfs.go
unionfs/unionfs.go
+1
-1
unionfs/unionfs_test.go
unionfs/unionfs_test.go
+19
-29
No files found.
unionfs/unionfs.go
View file @
ba6e6956
...
...
@@ -44,7 +44,7 @@ func filePathHash(path string) string {
Implementation notes.
* It piggybacks on the existing LoopbackFileSystem in Go-
fuse
, so we
* It piggybacks on the existing LoopbackFileSystem in Go-
FUSE
, so we
don't have to translate back and forth between Go's and FUSE's API.
* Deleting a file will put a file named
...
...
unionfs/unionfs_test.go
View file @
ba6e6956
...
...
@@ -3,6 +3,7 @@ package unionfs
import
(
"os"
"github.com/hanwen/go-fuse/fuse"
"io/ioutil"
"fmt"
"log"
"testing"
...
...
@@ -48,20 +49,9 @@ func setup(t *testing.T) (workdir string, state *fuse.MountState) {
return
wd
,
state
}
func
writeToFile
(
path
string
,
contents
string
,
create
bool
)
{
var
flags
int
=
os
.
O_WRONLY
if
create
{
flags
|=
os
.
O_CREATE
}
f
,
err
:=
os
.
OpenFile
(
path
,
flags
,
0644
)
fuse
.
CheckSuccess
(
err
)
_
,
err
=
f
.
Write
([]
byte
(
contents
))
fuse
.
CheckSuccess
(
err
)
err
=
f
.
Close
()
fuse
.
CheckSuccess
(
err
)
func
writeToFile
(
path
string
,
contents
string
)
{
err
:=
ioutil
.
WriteFile
(
path
,
[]
byte
(
contents
),
0644
)
CheckSuccess
(
err
)
}
func
readFromFile
(
path
string
)
string
{
...
...
@@ -150,7 +140,7 @@ func TestChmod(t *testing.T) {
ro_fn
:=
wd
+
"/ro/file"
m_fn
:=
wd
+
"/mount/file"
writeToFile
(
ro_fn
,
"a"
,
true
)
writeToFile
(
ro_fn
,
"a"
)
err
:=
os
.
Chmod
(
m_fn
,
07070
)
CheckSuccess
(
err
)
...
...
@@ -169,9 +159,9 @@ func TestBasic(t *testing.T) {
wd
,
state
:=
setup
(
t
)
defer
state
.
Unmount
()
writeToFile
(
wd
+
"/rw/rw"
,
"a"
,
true
)
writeToFile
(
wd
+
"/ro/ro1"
,
"a"
,
true
)
writeToFile
(
wd
+
"/ro/ro2"
,
"b"
,
true
)
writeToFile
(
wd
+
"/rw/rw"
,
"a"
)
writeToFile
(
wd
+
"/ro/ro1"
,
"a"
)
writeToFile
(
wd
+
"/ro/ro2"
,
"b"
)
names
:=
dirNames
(
wd
+
"/mount"
)
expected
:=
map
[
string
]
bool
{
...
...
@@ -179,7 +169,7 @@ func TestBasic(t *testing.T) {
}
checkMapEq
(
t
,
names
,
expected
)
writeToFile
(
wd
+
"/mount/new"
,
"new contents"
,
true
)
writeToFile
(
wd
+
"/mount/new"
,
"new contents"
)
if
!
fileExists
(
wd
+
"/rw/new"
)
{
t
.
Errorf
(
"missing file in rw layer"
,
names
)
}
...
...
@@ -188,7 +178,7 @@ func TestBasic(t *testing.T) {
t
.
Errorf
(
"read mismatch."
)
}
writeToFile
(
wd
+
"/mount/ro1"
,
"promote me"
,
false
)
writeToFile
(
wd
+
"/mount/ro1"
,
"promote me"
)
if
!
fileExists
(
wd
+
"/rw/ro1"
)
{
t
.
Errorf
(
"missing file in rw layer"
,
names
)
}
...
...
@@ -232,8 +222,8 @@ func TestPromote(t *testing.T) {
err
:=
os
.
Mkdir
(
wd
+
"/ro/subdir"
,
0755
)
CheckSuccess
(
err
)
writeToFile
(
wd
+
"/ro/subdir/file"
,
"content"
,
true
)
writeToFile
(
wd
+
"/mount/subdir/file"
,
"other-content"
,
false
)
writeToFile
(
wd
+
"/ro/subdir/file"
,
"content"
)
writeToFile
(
wd
+
"/mount/subdir/file"
,
"other-content"
)
}
func
TestCreate
(
t
*
testing
.
T
)
{
...
...
@@ -242,7 +232,7 @@ func TestCreate(t *testing.T) {
err
:=
os
.
MkdirAll
(
wd
+
"/ro/subdir/sub2"
,
0755
)
CheckSuccess
(
err
)
writeToFile
(
wd
+
"/mount/subdir/sub2/file"
,
"other-content"
,
true
)
writeToFile
(
wd
+
"/mount/subdir/sub2/file"
,
"other-content"
)
_
,
err
=
os
.
Lstat
(
wd
+
"/mount/subdir/sub2/file"
)
CheckSuccess
(
err
)
}
...
...
@@ -251,10 +241,10 @@ func TestOpenUndeletes(t *testing.T) {
wd
,
state
:=
setup
(
t
)
defer
state
.
Unmount
()
writeToFile
(
wd
+
"/ro/file"
,
"X"
,
true
)
writeToFile
(
wd
+
"/ro/file"
,
"X"
)
err
:=
os
.
Remove
(
wd
+
"/mount/file"
)
CheckSuccess
(
err
)
writeToFile
(
wd
+
"/mount/file"
,
"X"
,
true
)
writeToFile
(
wd
+
"/mount/file"
,
"X"
)
_
,
err
=
os
.
Lstat
(
wd
+
"/mount/file"
)
CheckSuccess
(
err
)
}
...
...
@@ -292,16 +282,16 @@ func TestRename(t *testing.T) {
t
.
Log
(
"Config"
,
i
,
c
)
wd
,
state
:=
setup
(
t
)
if
c
.
f1_ro
{
writeToFile
(
wd
+
"/ro/file1"
,
"c1"
,
true
)
writeToFile
(
wd
+
"/ro/file1"
,
"c1"
)
}
if
c
.
f1_rw
{
writeToFile
(
wd
+
"/rw/file1"
,
"c2"
,
true
)
writeToFile
(
wd
+
"/rw/file1"
,
"c2"
)
}
if
c
.
f2_ro
{
writeToFile
(
wd
+
"/ro/file2"
,
"c3"
,
true
)
writeToFile
(
wd
+
"/ro/file2"
,
"c3"
)
}
if
c
.
f2_rw
{
writeToFile
(
wd
+
"/rw/file2"
,
"c4"
,
true
)
writeToFile
(
wd
+
"/rw/file2"
,
"c4"
)
}
err
:=
os
.
Rename
(
wd
+
"/mount/file1"
,
wd
+
"/mount/file2"
)
...
...
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