blob: 0543f2daff06b8ff11d66df8ec0282978ca49de8 [file] [log] [blame]
package migrations
import (
"fmt"
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.skia.org/infra/go/testutils/unittest"
perfsql "go.skia.org/infra/perf/go/sql"
"go.skia.org/infra/perf/go/sql/migrations/cockroachdb"
)
func getEmulatorHost() string {
ret := os.Getenv("COCKROACHDB_EMULATOR_HOST")
if ret == "" {
ret = "localhost:26257"
}
return ret
}
func TestUpDown_CockroachDB(t *testing.T) {
unittest.LargeTest(t)
cockroachMigrations, err := cockroachdb.New()
require.NoError(t, err)
cockroachDBTest := fmt.Sprintf("cockroach://root@%s?sslmode=disable", perfsql.GetCockroachDBEmulatorHost())
err = Up(cockroachMigrations, cockroachDBTest)
assert.NoError(t, err)
err = Down(cockroachMigrations, cockroachDBTest)
assert.NoError(t, err)
// Do it a second time to ensure we are idempotent.
err = Up(cockroachMigrations, cockroachDBTest)
assert.NoError(t, err)
err = Down(cockroachMigrations, cockroachDBTest)
assert.NoError(t, err)
}