2019-01-24 16:26:36 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2019-01-11 10:08:51 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2019-01-31 13:01:13 +00:00
|
|
|
package satellitedb_test
|
2019-01-11 10:08:51 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2019-01-15 13:03:24 +00:00
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/testcontext"
|
2019-01-31 13:01:13 +00:00
|
|
|
"storj.io/storj/satellite"
|
|
|
|
"storj.io/storj/satellite/satellitedb/satellitedbtest"
|
2019-01-11 10:08:51 +00:00
|
|
|
)
|
|
|
|
|
2019-01-31 13:01:13 +00:00
|
|
|
func TestConsoleTx(t *testing.T) {
|
|
|
|
satellitedbtest.Run(t, func(t *testing.T, db satellite.DB) {
|
|
|
|
ctx := testcontext.New(t)
|
|
|
|
defer ctx.Cleanup()
|
2019-01-11 10:08:51 +00:00
|
|
|
|
2019-01-31 13:01:13 +00:00
|
|
|
console := db.Console()
|
2019-01-11 10:08:51 +00:00
|
|
|
|
2019-01-31 13:01:13 +00:00
|
|
|
t.Run("BeginTx, Commit, Rollback", func(t *testing.T) {
|
|
|
|
tx, err := console.BeginTx(ctx)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, tx)
|
2019-01-11 10:08:51 +00:00
|
|
|
|
2019-01-31 13:01:13 +00:00
|
|
|
// TODO: add something into database
|
2019-01-11 10:08:51 +00:00
|
|
|
|
2019-01-31 13:01:13 +00:00
|
|
|
assert.NoError(t, tx.Commit())
|
|
|
|
assert.Error(t, tx.Rollback())
|
2019-01-11 10:08:51 +00:00
|
|
|
|
2019-01-31 13:01:13 +00:00
|
|
|
// TODO: check whether it has been committed
|
|
|
|
})
|
2019-01-11 10:08:51 +00:00
|
|
|
|
2019-01-31 13:01:13 +00:00
|
|
|
t.Run("BeginTx, Rollback, Commit", func(t *testing.T) {
|
|
|
|
tx, err := console.BeginTx(ctx)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, tx)
|
2019-01-11 10:08:51 +00:00
|
|
|
|
2019-01-31 13:01:13 +00:00
|
|
|
// TODO: add something into database
|
2019-01-11 10:08:51 +00:00
|
|
|
|
2019-01-31 13:01:13 +00:00
|
|
|
assert.NoError(t, tx.Rollback())
|
|
|
|
assert.Error(t, tx.Commit())
|
2019-01-11 10:08:51 +00:00
|
|
|
|
2019-01-31 13:01:13 +00:00
|
|
|
// TODO: check whether it has been rolled back
|
|
|
|
})
|
2019-01-11 10:08:51 +00:00
|
|
|
})
|
|
|
|
}
|