diff options
author | Ben Johnson <benbjohnson@yahoo.com> | 2014-02-14 08:32:42 -0700 |
---|---|---|
committer | Ben Johnson <benbjohnson@yahoo.com> | 2014-02-14 08:34:04 -0700 |
commit | 0ebef9c0bbf183a267c5cf861833d8854b4b2e31 (patch) | |
tree | 2b025229ec9c14e3945c0cf1bfb00d63472559ab /db_test.go | |
parent | Add godoc badge. (diff) | |
download | dedo-0ebef9c0bbf183a267c5cf861833d8854b4b2e31.tar.gz dedo-0ebef9c0bbf183a267c5cf861833d8854b4b2e31.tar.xz |
Add examples.
Diffstat (limited to 'db_test.go')
-rw-r--r-- | db_test.go | 19 |
1 files changed, 15 insertions, 4 deletions
@@ -140,6 +140,17 @@ func TestDBTransactionDatabaseNotOpenError(t *testing.T) { }) } +// Ensure that a bucket that gets a non-existent key returns nil. +func TestDBGetNonExistent(t *testing.T) { + withOpenDB(func(db *DB, path string) { + db.CreateBucket("widgets") + value, err := db.Get("widgets", []byte("foo")) + if assert.NoError(t, err) { + assert.Nil(t, value) + } + }) +} + // Ensure that a bucket can write a key/value. func TestDBPut(t *testing.T) { withOpenDB(func(db *DB, path string) { @@ -207,17 +218,17 @@ func withDB(fn func(*DB, string)) { os.Remove(path) defer os.RemoveAll(path) - db := NewDB() - fn(db, path) + var db DB + fn(&db, path) } // withMockDB executes a function with a database reference and a mock filesystem. func withMockDB(fn func(*DB, *mockos, *mocksyscall, string)) { os, syscall := &mockos{}, &mocksyscall{} - db := NewDB() + var db DB db.os = os db.syscall = syscall - fn(db, os, syscall, "/mock/db") + fn(&db, os, syscall, "/mock/db") } // withOpenDB executes a function with an already opened database. |