From 39521c29e9edcd42dcb97f97328c289d43c4ed84 Mon Sep 17 00:00:00 2001 From: siddontang Date: Tue, 29 Jul 2014 21:58:21 +0800 Subject: [PATCH] update tx test --- store/tx_test.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/store/tx_test.go b/store/tx_test.go index 339c3b0..cc1115b 100644 --- a/store/tx_test.go +++ b/store/tx_test.go @@ -11,6 +11,8 @@ func TestTx(t *testing.T) { func testTx(db *DB, t *testing.T) { key1 := []byte("1") key2 := []byte("2") + key3 := []byte("3") + key4 := []byte("4") db.Put(key1, []byte("1")) db.Put(key2, []byte("2")) @@ -28,6 +30,14 @@ func testTx(db *DB, t *testing.T) { t.Fatal(err) } + if err := tx.Put(key3, []byte("c")); err != nil { + t.Fatal(err) + } + + if err := tx.Put(key4, []byte("d")); err != nil { + t.Fatal(err) + } + it := tx.NewIterator() it.Seek(key1) @@ -38,6 +48,38 @@ func testTx(db *DB, t *testing.T) { t.Fatal(string(it.Value())) } + it.First() + + if !it.Valid() { + t.Fatal("must valid") + } else if string(it.Value()) != "a" { + t.Fatal(string(it.Value())) + } + + it.Seek(key2) + + if !it.Valid() { + t.Fatal("must valid") + } else if string(it.Value()) != "b" { + t.Fatal(string(it.Value())) + } + + it.Next() + + if !it.Valid() { + t.Fatal("must valid") + } else if string(it.Value()) != "c" { + t.Fatal(string(it.Value())) + } + + it.Last() + + if !it.Valid() { + t.Fatal("must valid") + } else if string(it.Value()) != "d" { + t.Fatal(string(it.Value())) + } + it.Close() tx.Rollback()