mirror of https://github.com/etcd-io/bbolt.git
Add additional error checks in test suite.
parent
834b38e3e7
commit
4e3fb8d60b
19
db_test.go
19
db_test.go
|
@ -94,23 +94,30 @@ func TestOpen_Size(t *testing.T) {
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
// Insert until we get above the minimum 4MB size.
|
// Insert until we get above the minimum 4MB size.
|
||||||
db.Update(func(tx *bolt.Tx) error {
|
ok(t, db.Update(func(tx *bolt.Tx) error {
|
||||||
b, _ := tx.CreateBucketIfNotExists([]byte("data"))
|
b, _ := tx.CreateBucketIfNotExists([]byte("data"))
|
||||||
for i := 0; i < 10000; i++ {
|
for i := 0; i < 10000; i++ {
|
||||||
_ = b.Put([]byte(fmt.Sprintf("%04d", i)), make([]byte, 1000))
|
ok(t, b.Put([]byte(fmt.Sprintf("%04d", i)), make([]byte, 1000)))
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
}))
|
||||||
|
|
||||||
// Close database and grab the size.
|
// Close database and grab the size.
|
||||||
db.DB.Close()
|
db.DB.Close()
|
||||||
sz := fileSize(path)
|
sz := fileSize(path)
|
||||||
|
if sz == 0 {
|
||||||
|
t.Fatalf("unexpected new file size: %d", sz)
|
||||||
|
}
|
||||||
|
|
||||||
// Reopen database, update, and check size again.
|
// Reopen database, update, and check size again.
|
||||||
db0, _ := bolt.Open(path, 0666, nil)
|
db0, err := bolt.Open(path, 0666, nil)
|
||||||
db0.Update(func(tx *bolt.Tx) error { return tx.Bucket([]byte("data")).Put([]byte{0}, []byte{0}) })
|
ok(t, err)
|
||||||
db0.Close()
|
ok(t, db0.Update(func(tx *bolt.Tx) error { return tx.Bucket([]byte("data")).Put([]byte{0}, []byte{0}) }))
|
||||||
|
ok(t, db0.Close())
|
||||||
newSz := fileSize(path)
|
newSz := fileSize(path)
|
||||||
|
if newSz == 0 {
|
||||||
|
t.Fatalf("unexpected new file size: %d", newSz)
|
||||||
|
}
|
||||||
|
|
||||||
// Compare the original size with the new size.
|
// Compare the original size with the new size.
|
||||||
if sz != newSz {
|
if sz != newSz {
|
||||||
|
|
Loading…
Reference in New Issue