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
e13d6c97
Commit
e13d6c97
authored
Nov 18, 2016
by
Jeromy Johnson
Committed by
GitHub
Nov 18, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #57 from ipfs/kevina/rawkey
namespace: correctly handle case when prefix is empty
parents
971a83c4
dba5e788
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
2 deletions
+11
-2
namespace/namespace.go
namespace/namespace.go
+4
-0
namespace/namespace_test.go
namespace/namespace_test.go
+7
-2
No files found.
namespace/namespace.go
View file @
e13d6c97
...
...
@@ -23,6 +23,10 @@ func PrefixTransform(prefix ds.Key) ktds.KeyTransform {
// Invert removes the prefix. panics if prefix not found.
Invert
:
func
(
k
ds
.
Key
)
ds
.
Key
{
if
prefix
.
String
()
==
"/"
{
return
k
}
if
!
prefix
.
IsAncestorOf
(
k
)
{
fmt
.
Errorf
(
"Expected prefix (%s) in key (%s)"
,
prefix
,
k
)
panic
(
"expected prefix not found"
)
...
...
namespace/namespace_test.go
View file @
e13d6c97
...
...
@@ -20,9 +20,14 @@ type DSSuite struct{}
var
_
=
Suite
(
&
DSSuite
{})
func
(
ks
*
DSSuite
)
TestBasic
(
c
*
C
)
{
ks
.
testBasic
(
c
,
"abc"
)
ks
.
testBasic
(
c
,
""
)
}
func
(
ks
*
DSSuite
)
testBasic
(
c
*
C
,
prefix
string
)
{
mpds
:=
ds
.
NewMapDatastore
()
nsds
:=
ns
.
Wrap
(
mpds
,
ds
.
NewKey
(
"abc"
))
nsds
:=
ns
.
Wrap
(
mpds
,
ds
.
NewKey
(
prefix
))
keys
:=
strsToKeys
([]
string
{
"foo"
,
...
...
@@ -43,7 +48,7 @@ func (ks *DSSuite) TestBasic(c *C) {
c
.
Check
(
err
,
Equals
,
nil
)
c
.
Check
(
bytes
.
Equal
(
v1
.
([]
byte
),
[]
byte
(
k
.
String
())),
Equals
,
true
)
v2
,
err
:=
mpds
.
Get
(
ds
.
NewKey
(
"abc"
)
.
Child
(
k
))
v2
,
err
:=
mpds
.
Get
(
ds
.
NewKey
(
prefix
)
.
Child
(
k
))
c
.
Check
(
err
,
Equals
,
nil
)
c
.
Check
(
bytes
.
Equal
(
v2
.
([]
byte
),
[]
byte
(
k
.
String
())),
Equals
,
true
)
}
...
...
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