|
@@ -1,8 +1,10 @@
|
|
-package ezdb
|
|
|
|
|
|
+package ezleveldb
|
|
|
|
|
|
import (
|
|
import (
|
|
"fmt"
|
|
"fmt"
|
|
"testing"
|
|
"testing"
|
|
|
|
+
|
|
|
|
+ "github.com/annybs/ezdb"
|
|
)
|
|
)
|
|
|
|
|
|
func TestLevelDB(t *testing.T) {
|
|
func TestLevelDB(t *testing.T) {
|
|
@@ -13,11 +15,11 @@ func TestLevelDB(t *testing.T) {
|
|
|
|
|
|
path := ".leveldb/test_json"
|
|
path := ".leveldb/test_json"
|
|
|
|
|
|
- marshaler := JSON(func() *Student {
|
|
|
|
|
|
+ marshaler := ezdb.JSON(func() *Student {
|
|
return &Student{}
|
|
return &Student{}
|
|
})
|
|
})
|
|
|
|
|
|
- collection := LevelDB(path, marshaler, nil)
|
|
|
|
|
|
+ collection := ezdb.LevelDB(path, marshaler, nil)
|
|
|
|
|
|
cmp := func(expected, actual *Student) error {
|
|
cmp := func(expected, actual *Student) error {
|
|
if expected == nil && actual != nil {
|
|
if expected == nil && actual != nil {
|
|
@@ -33,7 +35,7 @@ func TestLevelDB(t *testing.T) {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
- tester := &CollectionTester[*Student]{
|
|
|
|
|
|
+ tester := &ezdb.CollectionTester[*Student]{
|
|
C: collection,
|
|
C: collection,
|
|
|
|
|
|
Cmp: cmp,
|
|
Cmp: cmp,
|
|
@@ -54,6 +56,10 @@ func TestLevelDB(t *testing.T) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ destroy := func() error {
|
|
|
|
+ return collection.Destroy()
|
|
|
|
+ }
|
|
|
|
+
|
|
sequence := []func(){
|
|
sequence := []func(){
|
|
named("init 1", tester.Init),
|
|
named("init 1", tester.Init),
|
|
named("has", tester.Has),
|
|
named("has", tester.Has),
|
|
@@ -69,6 +75,7 @@ func TestLevelDB(t *testing.T) {
|
|
named("iterSortKeys", tester.IterSortKeys),
|
|
named("iterSortKeys", tester.IterSortKeys),
|
|
named("deleteAll", tester.DeleteAll),
|
|
named("deleteAll", tester.DeleteAll),
|
|
named("close", tester.Close),
|
|
named("close", tester.Close),
|
|
|
|
+ named("destroy", destroy),
|
|
}
|
|
}
|
|
for _, do := range sequence {
|
|
for _, do := range sequence {
|
|
do()
|
|
do()
|