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-datastore
Commits
aedf02b1
Commit
aedf02b1
authored
Mar 13, 2015
by
Tommi Virtanen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement mount Has
parent
cf78b943
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
1 deletion
+66
-1
mount/mount.go
mount/mount.go
+5
-1
mount/mount_test.go
mount/mount_test.go
+61
-0
No files found.
mount/mount.go
View file @
aedf02b1
...
@@ -62,7 +62,11 @@ func (d *Datastore) Get(key datastore.Key) (value interface{}, err error) {
...
@@ -62,7 +62,11 @@ func (d *Datastore) Get(key datastore.Key) (value interface{}, err error) {
}
}
func
(
d
*
Datastore
)
Has
(
key
datastore
.
Key
)
(
exists
bool
,
err
error
)
{
func
(
d
*
Datastore
)
Has
(
key
datastore
.
Key
)
(
exists
bool
,
err
error
)
{
return
false
,
errors
.
New
(
"TODO"
)
ds
,
k
:=
d
.
lookup
(
key
)
if
ds
==
nil
{
return
false
,
nil
}
return
ds
.
Has
(
k
)
}
}
func
(
d
*
Datastore
)
Delete
(
key
datastore
.
Key
)
error
{
func
(
d
*
Datastore
)
Delete
(
key
datastore
.
Key
)
error
{
...
...
mount/mount_test.go
View file @
aedf02b1
...
@@ -107,3 +107,64 @@ func TestGet(t *testing.T) {
...
@@ -107,3 +107,64 @@ func TestGet(t *testing.T) {
t
.
Errorf
(
"wrong value: %q != %q"
,
g
,
e
)
t
.
Errorf
(
"wrong value: %q != %q"
,
g
,
e
)
}
}
}
}
func
TestHasBadNothing
(
t
*
testing
.
T
)
{
m
:=
mount
.
New
([]
mount
.
Mount
{})
found
,
err
:=
m
.
Has
(
datastore
.
NewKey
(
"/quux/thud"
))
if
err
!=
nil
{
t
.
Fatalf
(
"Has error: %v"
,
err
)
}
if
g
,
e
:=
found
,
false
;
g
!=
e
{
t
.
Fatalf
(
"wrong value: %v != %v"
,
g
,
e
)
}
}
func
TestHasBadNoMount
(
t
*
testing
.
T
)
{
mapds
:=
datastore
.
NewMapDatastore
()
m
:=
mount
.
New
([]
mount
.
Mount
{
{
Prefix
:
datastore
.
NewKey
(
"/redherring"
),
Datastore
:
mapds
},
})
found
,
err
:=
m
.
Has
(
datastore
.
NewKey
(
"/quux/thud"
))
if
err
!=
nil
{
t
.
Fatalf
(
"Has error: %v"
,
err
)
}
if
g
,
e
:=
found
,
false
;
g
!=
e
{
t
.
Fatalf
(
"wrong value: %v != %v"
,
g
,
e
)
}
}
func
TestHasNotFound
(
t
*
testing
.
T
)
{
mapds
:=
datastore
.
NewMapDatastore
()
m
:=
mount
.
New
([]
mount
.
Mount
{
{
Prefix
:
datastore
.
NewKey
(
"/quux"
),
Datastore
:
mapds
},
})
found
,
err
:=
m
.
Has
(
datastore
.
NewKey
(
"/quux/thud"
))
if
err
!=
nil
{
t
.
Fatalf
(
"Has error: %v"
,
err
)
}
if
g
,
e
:=
found
,
false
;
g
!=
e
{
t
.
Fatalf
(
"wrong value: %v != %v"
,
g
,
e
)
}
}
func
TestHas
(
t
*
testing
.
T
)
{
mapds
:=
datastore
.
NewMapDatastore
()
m
:=
mount
.
New
([]
mount
.
Mount
{
{
Prefix
:
datastore
.
NewKey
(
"/quux"
),
Datastore
:
mapds
},
})
if
err
:=
mapds
.
Put
(
datastore
.
NewKey
(
"/thud"
),
[]
byte
(
"foobar"
));
err
!=
nil
{
t
.
Fatalf
(
"Put error: %v"
,
err
)
}
found
,
err
:=
m
.
Has
(
datastore
.
NewKey
(
"/quux/thud"
))
if
err
!=
nil
{
t
.
Fatalf
(
"Has error: %v"
,
err
)
}
if
g
,
e
:=
found
,
true
;
g
!=
e
{
t
.
Fatalf
(
"wrong value: %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