mirror of https://github.com/ledisdb/ledisdb.git
71 lines
1.3 KiB
Go
71 lines
1.3 KiB
Go
package ledis
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestHashCodec(t *testing.T) {
|
|
db := getTestDB()
|
|
|
|
key := []byte("key")
|
|
field := []byte("field")
|
|
|
|
ek := db.hEncodeSizeKey(key)
|
|
if k, err := db.hDecodeSizeKey(ek); err != nil {
|
|
t.Fatal(err)
|
|
} else if string(k) != "key" {
|
|
t.Fatal(string(k))
|
|
}
|
|
|
|
ek = db.hEncodeHashKey(key, field)
|
|
if k, f, err := db.hDecodeHashKey(ek); err != nil {
|
|
t.Fatal(err)
|
|
} else if string(k) != "key" {
|
|
t.Fatal(string(k))
|
|
} else if string(f) != "field" {
|
|
t.Fatal(string(f))
|
|
}
|
|
}
|
|
|
|
func TestDBHash(t *testing.T) {
|
|
db := getTestDB()
|
|
|
|
key := []byte("testdb_hash_a")
|
|
|
|
if n, err := db.HSet(key, []byte("a"), []byte("hello world")); err != nil {
|
|
t.Fatal(err)
|
|
} else if n != 1 {
|
|
t.Fatal(n)
|
|
}
|
|
}
|
|
|
|
func TestDBHScan(t *testing.T) {
|
|
db := getTestDB()
|
|
|
|
db.hFlush()
|
|
|
|
key := []byte("a")
|
|
db.HSet(key, []byte("1"), []byte{})
|
|
db.HSet(key, []byte("2"), []byte{})
|
|
db.HSet(key, []byte("3"), []byte{})
|
|
|
|
if v, err := db.HScan(key, nil, 1, true); err != nil {
|
|
t.Fatal(err)
|
|
} else if len(v) != 1 {
|
|
t.Fatal(len(v))
|
|
}
|
|
|
|
if v, err := db.HScan(key, []byte("1"), 2, false); err != nil {
|
|
t.Fatal(err)
|
|
} else if len(v) != 2 {
|
|
t.Fatal(len(v))
|
|
}
|
|
|
|
if v, err := db.HScan(key, nil, 10, true); err != nil {
|
|
t.Fatal(err)
|
|
} else if len(v) != 3 {
|
|
t.Fatal(len(v))
|
|
}
|
|
|
|
}
|