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
d71ec5d6
Commit
d71ec5d6
authored
Mar 12, 2015
by
Tommi Virtanen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement flatfs Has
parent
f7b3cf7c
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 @
d71ec5d6
...
...
@@ -117,7 +117,15 @@ func (fs *Datastore) Get(key datastore.Key) (value interface{}, err error) {
}
func
(
fs
*
Datastore
)
Has
(
key
datastore
.
Key
)
(
exists
bool
,
err
error
)
{
return
false
,
errors
.
New
(
"TODO"
)
_
,
path
:=
fs
.
encode
(
key
)
switch
_
,
err
:=
os
.
Stat
(
path
);
{
case
err
==
nil
:
return
true
,
nil
case
os
.
IsNotExist
(
err
)
:
return
false
,
nil
default
:
return
false
,
err
}
}
func
(
fs
*
Datastore
)
Delete
(
key
datastore
.
Key
)
error
{
...
...
flatfs_test.go
View file @
d71ec5d6
...
...
@@ -196,3 +196,43 @@ func TestStorage(t *testing.T) {
t
.
Error
(
"did not see the data file"
)
}
}
func
TestHasNotFound
(
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
)
}
found
,
err
:=
fs
.
Has
(
datastore
.
NewKey
(
"quux"
))
if
err
!=
nil
{
t
.
Fatalf
(
"Has fail: %v
\n
"
,
err
)
}
if
g
,
e
:=
found
,
false
;
g
!=
e
{
t
.
Fatalf
(
"wrong Has: %v != %v"
,
g
,
e
)
}
}
func
TestHasFound
(
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
)
}
found
,
err
:=
fs
.
Has
(
datastore
.
NewKey
(
"quux"
))
if
err
!=
nil
{
t
.
Fatalf
(
"Has fail: %v
\n
"
,
err
)
}
if
g
,
e
:=
found
,
true
;
g
!=
e
{
t
.
Fatalf
(
"wrong Has: %v != %v"
,
g
,
e
)
}
}
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