aboutsummaryrefslogtreecommitdiff
path: root/db_test.go
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2014-03-24 08:31:15 -0600
committerBen Johnson <benbjohnson@yahoo.com>2014-03-24 08:31:15 -0600
commit59fde2f6648c532a6c70263b98c6cc3142004630 (patch)
tree5151a76ed8b98e87f12252bf86189135f4f3d2b0 /db_test.go
parentMerge pull request #86 from benbjohnson/mock (diff)
downloaddedo-59fde2f6648c532a6c70263b98c6cc3142004630.tar.gz
dedo-59fde2f6648c532a6c70263b98c6cc3142004630.tar.xz
Error refactoring.
Fixed up a few error issues and refactored out the Error type.
Diffstat (limited to 'db_test.go')
-rw-r--r--db_test.go27
1 files changed, 14 insertions, 13 deletions
diff --git a/db_test.go b/db_test.go
index b363486..462821f 100644
--- a/db_test.go
+++ b/db_test.go
@@ -1,6 +1,7 @@
package bolt
import (
+ "errors"
"io"
"io/ioutil"
"math/rand"
@@ -8,6 +9,7 @@ import (
"strconv"
"strings"
"testing"
+ "unsafe"
"github.com/stretchr/testify/assert"
)
@@ -53,14 +55,12 @@ func TestDBReopen(t *testing.T) {
// Ensure that the database returns an error if the file handle cannot be open.
func TestDBOpenFileError(t *testing.T) {
- withDBFile(func(db *DB, path string) {
- exp := &os.PathError{
- Op: "open",
- Path: path + "/youre-not-my-real-parent",
- Err: syscall.ENOTDIR,
- }
+ withDB(func(db *DB, path string) {
err := db.Open(path+"/youre-not-my-real-parent", 0666)
- assert.Equal(t, err, exp)
+ if err, _ := err.(*os.PathError); assert.Error(t, err) {
+ assert.Equal(t, path+"/youre-not-my-real-parent", err.Path)
+ assert.Equal(t, "open", err.Op)
+ }
})
}
@@ -78,13 +78,14 @@ func TestDBMetaInitWriteError(t *testing.T) {
// Ensure that a database that is too small returns an error.
func TestDBFileTooSmall(t *testing.T) {
- withDBFile(func(db *DB, path string) {
+ withOpenDB(func(db *DB, path string) {
+ db.Close()
+
// corrupt the database
- err := os.Truncate(path, int64(os.Getpagesize()))
- assert.NoError(t, err)
+ assert.NoError(t, os.Truncate(path, int64(os.Getpagesize())))
- err = db.Open(path, 0666)
- assert.Equal(t, err, &Error{"file size too small", nil})
+ err := db.Open(path, 0666)
+ assert.Equal(t, errors.New("file size too small"), err)
})
}
@@ -108,7 +109,7 @@ func TestDBCorruptMeta0(t *testing.T) {
// Open the database.
err = db.Open(path, 0666)
- assert.Equal(t, err, &Error{"meta error", ErrInvalid})
+ assert.Equal(t, err, errors.New("meta error: invalid database"))
})
}