2014-05-16 06:36:18 +04:00
|
|
|
package ledis
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2014-05-20 04:41:24 +04:00
|
|
|
func TestKVCodec(t *testing.T) {
|
|
|
|
db := getTestDB()
|
|
|
|
|
|
|
|
ek := db.encodeKVKey([]byte("key"))
|
|
|
|
|
|
|
|
if k, err := db.decodeKVKey(ek); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
} else if string(k) != "key" {
|
|
|
|
t.Fatal(string(k))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-16 06:36:18 +04:00
|
|
|
func TestDBKV(t *testing.T) {
|
|
|
|
db := getTestDB()
|
|
|
|
|
|
|
|
key := []byte("testdb_kv_a")
|
|
|
|
|
|
|
|
if err := db.Set(key, []byte("hello world")); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
2014-05-26 05:21:17 +04:00
|
|
|
|
|
|
|
func TestDBScan(t *testing.T) {
|
|
|
|
db := getTestDB()
|
|
|
|
|
2014-06-03 11:40:10 +04:00
|
|
|
db.FlushAll()
|
2014-05-26 05:21:17 +04:00
|
|
|
|
|
|
|
if v, err := db.Scan(nil, 10, true); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
} else if len(v) != 0 {
|
|
|
|
t.Fatal(len(v))
|
|
|
|
}
|
|
|
|
|
|
|
|
db.Set([]byte("a"), []byte{})
|
|
|
|
db.Set([]byte("b"), []byte{})
|
|
|
|
db.Set([]byte("c"), []byte{})
|
|
|
|
|
|
|
|
if v, err := db.Scan(nil, 1, true); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
} else if len(v) != 1 {
|
|
|
|
t.Fatal(len(v))
|
|
|
|
}
|
|
|
|
|
|
|
|
if v, err := db.Scan([]byte("a"), 2, false); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
} else if len(v) != 2 {
|
|
|
|
t.Fatal(len(v))
|
|
|
|
}
|
|
|
|
|
|
|
|
if v, err := db.Scan(nil, 3, true); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
} else if len(v) != 3 {
|
|
|
|
t.Fatal(len(v))
|
|
|
|
}
|
|
|
|
}
|