From 4c62cde2871f95158fc6c4928b8d764378d367b9 Mon Sep 17 00:00:00 2001 From: siddontang Date: Mon, 16 Mar 2015 09:20:26 +0800 Subject: [PATCH] add test for large db index --- ledis/ledis_test.go | 79 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 70 insertions(+), 9 deletions(-) diff --git a/ledis/ledis_test.go b/ledis/ledis_test.go index 51e4d0d..a0c9879 100644 --- a/ledis/ledis_test.go +++ b/ledis/ledis_test.go @@ -37,24 +37,85 @@ func TestDB(t *testing.T) { func TestSelect(t *testing.T) { db0, _ := testLedis.Select(0) db1, _ := testLedis.Select(1) + db1024, _ := testLedis.Select(1024) - key0 := []byte("db0_test_key") - key1 := []byte("db1_test_key") + testSelect(t, db0) + testSelect(t, db1) + testSelect(t, db1024) +} - db0.Set(key0, []byte("0")) - db1.Set(key1, []byte("1")) - - if v, err := db0.Get(key0); err != nil { +func testSelect(t *testing.T, db *DB) { + key := []byte("test_select_key") + value := []byte("value") + if err := db.Set(key, value); err != nil { 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)) } - if v, err := db1.Get(key1); err != nil { + if _, err := db.Expire(key, 100); err != nil { 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)) } + + 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) {