aboutsummaryrefslogtreecommitdiff
path: root/db_test.go
diff options
context:
space:
mode:
authorMartin Kobetic <mkobetic@gmail.com>2014-05-21 15:08:37 +0000
committerMartin Kobetic <mkobetic@gmail.com>2014-05-21 15:08:37 +0000
commit519d65228ef2bd99336a251f02c278a94b2df4d4 (patch)
tree53f28c761973abb3cf7cc3071a3eaa3db1a114f2 /db_test.go
parentREADME (diff)
downloaddedo-519d65228ef2bd99336a251f02c278a94b2df4d4.tar.gz
dedo-519d65228ef2bd99336a251f02c278a94b2df4d4.tar.xz
move Copy and CopyFile from DB to Tx
Diffstat (limited to 'db_test.go')
-rw-r--r--db_test.go61
1 files changed, 2 insertions, 59 deletions
diff --git a/db_test.go b/db_test.go
index 903f65e..7b1f554 100644
--- a/db_test.go
+++ b/db_test.go
@@ -238,30 +238,6 @@ func TestDB_View_Error(t *testing.T) {
})
}
-// Ensure that the database can be copied to a file path.
-func TestDB_CopyFile(t *testing.T) {
- withOpenDB(func(db *DB, path string) {
- var dest = tempfile()
- db.Update(func(tx *Tx) error {
- tx.CreateBucket([]byte("widgets"))
- tx.Bucket([]byte("widgets")).Put([]byte("foo"), []byte("bar"))
- tx.Bucket([]byte("widgets")).Put([]byte("baz"), []byte("bat"))
- return nil
- })
- assert.NoError(t, db.CopyFile(dest, 0600))
-
- db2, err := Open(dest, 0600)
- assert.NoError(t, err)
- defer db2.Close()
-
- db2.View(func(tx *Tx) error {
- assert.Equal(t, []byte("bar"), tx.Bucket([]byte("widgets")).Get([]byte("foo")))
- assert.Equal(t, []byte("bat"), tx.Bucket([]byte("widgets")).Get([]byte("baz")))
- return nil
- })
- })
-}
-
// Ensure that an error is returned when a database write fails.
func TestDB_Commit_WriteFail(t *testing.T) {
t.Skip("pending") // TODO(benbjohnson)
@@ -450,39 +426,6 @@ func ExampleDB_Begin_ReadOnly() {
// zephyr likes purple
}
-func ExampleDB_CopyFile() {
- // Open the database.
- db, _ := Open(tempfile(), 0666)
- defer os.Remove(db.Path())
- defer db.Close()
-
- // Create a bucket and a key.
- db.Update(func(tx *Tx) error {
- tx.CreateBucket([]byte("widgets"))
- tx.Bucket([]byte("widgets")).Put([]byte("foo"), []byte("bar"))
- return nil
- })
-
- // Copy the database to another file.
- toFile := tempfile()
- db.CopyFile(toFile, 0666)
- defer os.Remove(toFile)
-
- // Open the cloned database.
- db2, _ := Open(toFile, 0666)
- defer db2.Close()
-
- // Ensure that the key exists in the copy.
- db2.View(func(tx *Tx) error {
- value := tx.Bucket([]byte("widgets")).Get([]byte("foo"))
- fmt.Printf("The value for 'foo' in the clone is: %s\n", value)
- return nil
- })
-
- // Output:
- // The value for 'foo' in the clone is: bar
-}
-
// tempfile returns a temporary file path.
func tempfile() string {
f, _ := ioutil.TempFile("", "bolt-")
@@ -523,7 +466,7 @@ func mustCheck(db *DB) {
if err := db.Check(); err != nil {
// Copy db off first.
var path = tempfile()
- db.CopyFile(path, 0600)
+ db.View(func(tx *Tx) error { return tx.CopyFile(path, 0600) })
if errors, ok := err.(ErrorList); ok {
for _, err := range errors {
@@ -564,7 +507,7 @@ func truncDuration(d time.Duration) string {
// copyAndFailNow copies a database to a new location and then fails then test.
func copyAndFailNow(t *testing.T, db *DB) {
path := tempfile()
- db.CopyFile(path, 0600)
+ db.View(func(tx *Tx) error { return tx.CopyFile(path, 0600) })
fmt.Println("db copied to: ", path)
t.FailNow()
}