add test for large db index

This commit is contained in:
siddontang 2015-03-16 09:20:26 +08:00
parent 13cc446870
commit 4c62cde287
1 changed files with 70 additions and 9 deletions

View File

@ -37,24 +37,85 @@ func TestDB(t *testing.T) {
func TestSelect(t *testing.T) { func TestSelect(t *testing.T) {
db0, _ := testLedis.Select(0) db0, _ := testLedis.Select(0)
db1, _ := testLedis.Select(1) db1, _ := testLedis.Select(1)
db1024, _ := testLedis.Select(1024)
key0 := []byte("db0_test_key") testSelect(t, db0)
key1 := []byte("db1_test_key") testSelect(t, db1)
testSelect(t, db1024)
}
db0.Set(key0, []byte("0")) func testSelect(t *testing.T, db *DB) {
db1.Set(key1, []byte("1")) key := []byte("test_select_key")
value := []byte("value")
if v, err := db0.Get(key0); err != nil { if err := db.Set(key, value); err != nil {
t.Fatal(err) t.Fatal(err)
} else if string(v) != "0" { }
if v, err := db.Get(key); err != nil {
t.Fatal(err)
} else if string(v) != string(value) {
t.Fatal(string(v)) t.Fatal(string(v))
} }
if v, err := db1.Get(key1); err != nil { if _, err := db.Expire(key, 100); err != nil {
t.Fatal(err) t.Fatal(err)
} else if string(v) != "1" { }
if _, err := db.TTL(key); err != nil {
t.Fatal(err)
}
if _, err := db.Persist(key); err != nil {
t.Fatal(err)
}
key = []byte("test_select_list_key")
if _, err := db.LPush(key, value); err != nil {
t.Fatal(err)
}
if _, err := db.LRange(key, 0, 100); err != nil {
t.Fatal(err)
}
if v, err := db.LPop(key); err != nil {
t.Fatal(err)
} else if string(v) != string(value) {
t.Fatal(string(v)) t.Fatal(string(v))
} }
key = []byte("test_select_hash_key")
if _, err := db.HSet(key, []byte("a"), value); err != nil {
t.Fatal(err)
}
if v, err := db.HGet(key, []byte("a")); err != nil {
t.Fatal(err)
} else if string(v) != string(value) {
t.Fatal(string(v))
}
key = []byte("test_select_set_key")
if _, err := db.SAdd(key, []byte("a"), []byte("b")); err != nil {
t.Fatal(err)
}
if n, err := db.SIsMember(key, []byte("a")); err != nil {
t.Fatal(err)
} else if n != 1 {
t.Fatal(n)
}
key = []byte("test_select_zset_key")
if _, err := db.ZAdd(key, ScorePair{1, []byte("a")}, ScorePair{2, []byte("b")}); err != nil {
t.Fatal(err)
}
if v, err := db.ZRangeByScore(key, 0, 100, 0, -1); err != nil {
t.Fatal(err)
} else if len(v) != 2 {
t.Fatal(len(v))
}
} }
func TestFlush(t *testing.T) { func TestFlush(t *testing.T) {