mirror of
https://github.com/asdine/storm.git
synced 2025-10-05 23:06:49 +08:00
Passing external transaction to Storm
This commit is contained in:
22
node_test.go
22
node_test.go
@@ -6,6 +6,7 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/boltdb/bolt"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -22,5 +23,26 @@ func TestNode(t *testing.T) {
|
||||
assert.Equal(t, []string{"b", "c"}, n1.rootBucket)
|
||||
n2 := n1.From("d", "e")
|
||||
assert.Equal(t, []string{"b", "c", "d", "e"}, n2.rootBucket)
|
||||
}
|
||||
|
||||
func TestNodeWithTransaction(t *testing.T) {
|
||||
dir, _ := ioutil.TempDir(os.TempDir(), "storm")
|
||||
defer os.RemoveAll(dir)
|
||||
db, _ := Open(filepath.Join(dir, "storm.db"), Root("a"))
|
||||
defer db.Close()
|
||||
|
||||
var user User
|
||||
db.Bolt.Update(func(tx *bolt.Tx) error {
|
||||
dbx := db.WithTransaction(tx)
|
||||
err := dbx.Save(&User{ID: 10, Name: "John"})
|
||||
assert.NoError(t, err)
|
||||
err = dbx.One("ID", 10, &user)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "John", user.Name)
|
||||
return nil
|
||||
})
|
||||
|
||||
err := db.One("ID", 10, &user)
|
||||
assert.NoError(t, err)
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user