aboutsummaryrefslogtreecommitdiff
path: root/db_test.go
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2014-03-29 14:28:53 -0600
committerBen Johnson <benbjohnson@yahoo.com>2014-03-29 14:28:53 -0600
commitfcce87626ceeb4e9477b915f89aa0e9e3add5860 (patch)
treed8381077fb0d78b86219491d5331589cf470042a /db_test.go
parentMerge pull request #97 from benbjohnson/cli (diff)
parentAdd DB.Check(). (diff)
downloaddedo-fcce87626ceeb4e9477b915f89aa0e9e3add5860.tar.gz
dedo-fcce87626ceeb4e9477b915f89aa0e9e3add5860.tar.xz
Merge pull request #98 from benbjohnson/fsck
Add DB.Check().
Diffstat (limited to 'db_test.go')
-rw-r--r--db_test.go23
1 files changed, 22 insertions, 1 deletions
diff --git a/db_test.go b/db_test.go
index a2df9d3..487b968 100644
--- a/db_test.go
+++ b/db_test.go
@@ -78,7 +78,8 @@ func TestDBMetaInitWriteError(t *testing.T) {
// Ensure that a database that is too small returns an error.
func TestDBFileTooSmall(t *testing.T) {
- withOpenDB(func(db *DB, path string) {
+ withDB(func(db *DB, path string) {
+ assert.NoError(t, db.Open(path, 0666))
db.Close()
// corrupt the database
@@ -130,6 +131,7 @@ func TestDBBeginRW(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, tx.DB(), db)
assert.Equal(t, tx.Writable(), true)
+ assert.NoError(t, tx.Commit())
})
}
@@ -382,9 +384,28 @@ func withOpenDB(fn func(*DB, string)) {
}
defer db.Close()
fn(db, path)
+
+ // Check database consistency after every test.
+ mustCheck(db)
})
}
+// mustCheck runs a consistency check on the database and panics if any errors are found.
+func mustCheck(db *DB) {
+ if err := db.Check(); err != nil {
+ // Copy db off first.
+ db.CopyFile("/tmp/check.db", 0600)
+
+ if errors, ok := err.(ErrorList); ok {
+ for _, err := range errors {
+ warn(err)
+ }
+ }
+ warn(err)
+ panic("check failure: see /tmp/check.db")
+ }
+}
+
func trunc(b []byte, length int) []byte {
if length < len(b) {
return b[:length]