Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-ds-flatfs
Commits
3ee8720e
Commit
3ee8720e
authored
Mar 12, 2015
by
Tommi Virtanen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement flatfs Delete
parent
d71ec5d6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
1 deletion
+49
-1
flatfs.go
flatfs.go
+9
-1
flatfs_test.go
flatfs_test.go
+40
-0
No files found.
flatfs.go
View file @
3ee8720e
...
...
@@ -129,7 +129,15 @@ func (fs *Datastore) Has(key datastore.Key) (exists bool, err error) {
}
func
(
fs
*
Datastore
)
Delete
(
key
datastore
.
Key
)
error
{
return
errors
.
New
(
"TODO"
)
_
,
path
:=
fs
.
encode
(
key
)
switch
err
:=
os
.
Remove
(
path
);
{
case
err
==
nil
:
return
nil
case
os
.
IsNotExist
(
err
)
:
return
datastore
.
ErrNotFound
default
:
return
err
}
}
func
(
fs
*
Datastore
)
Query
(
q
query
.
Query
)
(
query
.
Results
,
error
)
{
...
...
flatfs_test.go
View file @
3ee8720e
...
...
@@ -236,3 +236,43 @@ func TestHasFound(t *testing.T) {
t
.
Fatalf
(
"wrong Has: %v != %v"
,
g
,
e
)
}
}
func
TestDeleteNotFound
(
t
*
testing
.
T
)
{
temp
,
cleanup
:=
tempdir
(
t
)
defer
cleanup
()
fs
,
err
:=
flatfs
.
New
(
temp
,
2
)
if
err
!=
nil
{
t
.
Fatalf
(
"New fail: %v
\n
"
,
err
)
}
err
=
fs
.
Delete
(
datastore
.
NewKey
(
"quux"
))
if
g
,
e
:=
err
,
datastore
.
ErrNotFound
;
g
!=
e
{
t
.
Fatalf
(
"expected ErrNotFound, got: %v
\n
"
,
g
)
}
}
func
TestDeleteFound
(
t
*
testing
.
T
)
{
temp
,
cleanup
:=
tempdir
(
t
)
defer
cleanup
()
fs
,
err
:=
flatfs
.
New
(
temp
,
2
)
if
err
!=
nil
{
t
.
Fatalf
(
"New fail: %v
\n
"
,
err
)
}
err
=
fs
.
Put
(
datastore
.
NewKey
(
"quux"
),
[]
byte
(
"foobar"
))
if
err
!=
nil
{
t
.
Fatalf
(
"Put fail: %v
\n
"
,
err
)
}
err
=
fs
.
Delete
(
datastore
.
NewKey
(
"quux"
))
if
err
!=
nil
{
t
.
Fatalf
(
"Delete fail: %v
\n
"
,
err
)
}
// check that it's gone
_
,
err
=
fs
.
Get
(
datastore
.
NewKey
(
"quux"
))
if
g
,
e
:=
err
,
datastore
.
ErrNotFound
;
g
!=
e
{
t
.
Fatalf
(
"expected Get after Delete to give ErrNotFound, got: %v
\n
"
,
g
)
}
}
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