Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty string is not a valid key #5

Closed
eqv opened this issue Feb 7, 2014 · 1 comment
Closed

Empty string is not a valid key #5

eqv opened this issue Feb 7, 2014 · 1 comment

Comments

@eqv
Copy link

eqv commented Feb 7, 2014

Storing a value under the empty string fails silently:

import "testing"
import "bytes"
import "os"
import "github.com/steveyen/gkvlite"

func TestSimpleEmptyStore(t *testing.T){
    f, err := os.Create("/tmp/test.gkvlite")
    if err != nil {
        t.Errorf("Failed to create Storage File: %v",err)
    }
    res, err := gkvlite.NewStore(f)
    if err != nil {
        t.Errorf("Failed to create Storage Object: %v",err)
    }
    db := res.SetCollection("test",nil)
    key :=  []byte{}
    text := []byte("fnord")
    db.Set(key,text)
    readback,err := db.Get(key)
    if err != nil {
        t.Errorf("Failed to read back %v",err)
    }
    if bytes.Compare(text,readback) != 0 {
        t.Errorf("Failed to read back, got: %v expected: %v",readback,text)
    }
}

The test case fails after returning the empty string instead of the stored value:

--- FAIL: TestSimpleEmptyStore (0.00 seconds)
    gkvlite_test.go:26: Failed to read back, got: [] expected: [102 110 111 114 100]
@d2g d2g mentioned this issue Sep 18, 2014
Closed
@steveyen
Copy link
Owner

Looks like the provided sample test case isn't checking for the error return value from the Set() invocation.

The Set() implementation in gkvlite is doing the empty key correct check...

https://github.com/steveyen/gkvlite/blob/master/collection.go#L129

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants