From a47c50295a24c50872afc183927e34eec5c3dbdf Mon Sep 17 00:00:00 2001 From: Ben Johnson Date: Wed, 26 Feb 2014 16:32:05 -0700 Subject: Add bolt.Open(). Per the suggestion of @tv42 and @cespare, this commit adds a package level function to create and initialize a database at a given path. This is a common interface for database packages. --- db_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'db_test.go') diff --git a/db_test.go b/db_test.go index 19e10f1..59f8748 100644 --- a/db_test.go +++ b/db_test.go @@ -14,6 +14,27 @@ import ( "github.com/stretchr/testify/mock" ) +// Ensure that a database can be opened without error. +func TestOpen(t *testing.T) { + f, _ := ioutil.TempFile("", "bolt-") + path := f.Name() + f.Close() + os.Remove(path) + defer os.RemoveAll(path) + + db, err := Open(path, 0666) + assert.NoError(t, err) + assert.NotNil(t, db) + db.Close() +} + +// Ensure that opening a database with a bad path returns an error. +func TestOpenBadPath(t *testing.T) { + db, err := Open("/../bad-path", 0666) + assert.Error(t, err) + assert.Nil(t, db) +} + // Ensure that a database can be opened without error. func TestDBOpen(t *testing.T) { withDB(func(db *DB, path string) { -- cgit v1.2.3