From 13cc446870503d6ff96c01cfeb6564dcaf769a9d Mon Sep 17 00:00:00 2001 From: siddontang Date: Mon, 16 Mar 2015 09:20:13 +0800 Subject: [PATCH] add TTL key codec test --- ledis/t_ttl_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/ledis/t_ttl_test.go b/ledis/t_ttl_test.go index 371a40d..f261399 100644 --- a/ledis/t_ttl_test.go +++ b/ledis/t_ttl_test.go @@ -437,3 +437,31 @@ func TestExpCompose(t *testing.T) { return } + +func TestTTLCodec(t *testing.T) { + db := getTestDB() + + key := []byte("key") + ek := db.expEncodeTimeKey(KVType, key, 10) + + if tp, k, when, err := db.expDecodeTimeKey(ek); err != nil { + t.Fatal(err) + } else if tp != KVType { + t.Fatal(tp, KVType) + } else if string(k) != "key" { + t.Fatal(string(k)) + } else if when != 10 { + t.Fatal(when) + } + + ek = db.expEncodeMetaKey(KVType, key) + + if tp, k, err := db.expDecodeMetaKey(ek); err != nil { + t.Fatal(err) + } else if tp != KVType { + t.Fatal(tp, KVType) + } else if string(k) != "key" { + t.Fatal(string(k)) + } + +}