update tx test

This commit is contained in:
siddontang 2014-07-29 21:58:21 +08:00
parent a77de18dff
commit 39521c29e9
1 changed files with 42 additions and 0 deletions

View File

@ -11,6 +11,8 @@ func TestTx(t *testing.T) {
func testTx(db *DB, t *testing.T) { func testTx(db *DB, t *testing.T) {
key1 := []byte("1") key1 := []byte("1")
key2 := []byte("2") key2 := []byte("2")
key3 := []byte("3")
key4 := []byte("4")
db.Put(key1, []byte("1")) db.Put(key1, []byte("1"))
db.Put(key2, []byte("2")) db.Put(key2, []byte("2"))
@ -28,6 +30,14 @@ func testTx(db *DB, t *testing.T) {
t.Fatal(err) 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 := tx.NewIterator()
it.Seek(key1) it.Seek(key1)
@ -38,6 +48,38 @@ func testTx(db *DB, t *testing.T) {
t.Fatal(string(it.Value())) 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() it.Close()
tx.Rollback() tx.Rollback()