Commit e13d6c97 authored by Jeromy Johnson's avatar Jeromy Johnson Committed by GitHub

Merge pull request #57 from ipfs/kevina/rawkey

namespace: correctly handle case when prefix is empty
parents 971a83c4 dba5e788
......@@ -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")
......
......@@ -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)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment