|
|
|
@ -26,7 +26,7 @@ func newTestLDB() (*LDBDatabase, func()) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var test_values = []string{"", "a", "1251", "\x00123\x00"} |
|
|
|
|
var testValues = []string{"", "a", "1251", "\x00123\x00"} |
|
|
|
|
|
|
|
|
|
func TestLDB_PutGet(t *testing.T) { |
|
|
|
|
db, remove := newTestLDB() |
|
|
|
@ -41,14 +41,14 @@ func TestMemoryDB_PutGet(t *testing.T) { |
|
|
|
|
func testPutGet(db Database, t *testing.T) { |
|
|
|
|
t.Parallel() |
|
|
|
|
|
|
|
|
|
for _, k := range test_values { |
|
|
|
|
for _, k := range testValues { |
|
|
|
|
err := db.Put([]byte(k), nil) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("put failed: %v", err) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for _, k := range test_values { |
|
|
|
|
for _, k := range testValues { |
|
|
|
|
data, err := db.Get([]byte(k)) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("get failed: %v", err) |
|
|
|
@ -63,14 +63,14 @@ func testPutGet(db Database, t *testing.T) { |
|
|
|
|
t.Fatalf("expect to return a not found error") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for _, v := range test_values { |
|
|
|
|
for _, v := range testValues { |
|
|
|
|
err := db.Put([]byte(v), []byte(v)) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("put failed: %v", err) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for _, v := range test_values { |
|
|
|
|
for _, v := range testValues { |
|
|
|
|
data, err := db.Get([]byte(v)) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("get failed: %v", err) |
|
|
|
@ -80,14 +80,14 @@ func testPutGet(db Database, t *testing.T) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for _, v := range test_values { |
|
|
|
|
for _, v := range testValues { |
|
|
|
|
err := db.Put([]byte(v), []byte("?")) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("put override failed: %v", err) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for _, v := range test_values { |
|
|
|
|
for _, v := range testValues { |
|
|
|
|
data, err := db.Get([]byte(v)) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("get failed: %v", err) |
|
|
|
@ -97,7 +97,7 @@ func testPutGet(db Database, t *testing.T) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for _, v := range test_values { |
|
|
|
|
for _, v := range testValues { |
|
|
|
|
orig, err := db.Get([]byte(v)) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("get failed: %v", err) |
|
|
|
@ -112,14 +112,14 @@ func testPutGet(db Database, t *testing.T) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for _, v := range test_values { |
|
|
|
|
for _, v := range testValues { |
|
|
|
|
err := db.Delete([]byte(v)) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("delete %q failed: %v", v, err) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for _, v := range test_values { |
|
|
|
|
for _, v := range testValues { |
|
|
|
|
_, err := db.Get([]byte(v)) |
|
|
|
|
if err == nil { |
|
|
|
|
t.Fatalf("got deleted value %q", v) |
|
|
|
|