Files
grafana/pkg/services/sqlstore/migrations/migrations_test.go
Arve Knudsen b5379c5335 Chore: Fix SQL related Go variable naming (#28887)
* Chore: Fix variable naming

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
2020-11-11 06:21:08 +01:00

61 lines
1.3 KiB
Go

package migrations
import (
"testing"
. "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
"github.com/grafana/grafana/pkg/services/sqlstore/sqlutil"
"xorm.io/xorm"
. "github.com/smartystreets/goconvey/convey"
)
func TestMigrations(t *testing.T) {
testDBs := []sqlutil.TestDB{
sqlutil.SQLite3TestDB(),
}
for _, testDB := range testDBs {
sql := `select count(*) as count from migration_log`
r := struct {
Count int64
}{}
Convey("Initial "+testDB.DriverName+" migration", t, func() {
x, err := xorm.NewEngine(testDB.DriverName, testDB.ConnStr)
So(err, ShouldBeNil)
err = NewDialect(x).CleanDB()
So(err, ShouldBeNil)
_, err = x.SQL(sql).Get(&r)
So(err, ShouldNotBeNil)
mg := NewMigrator(x)
AddMigrations(mg)
err = mg.Start()
So(err, ShouldBeNil)
has, err := x.SQL(sql).Get(&r)
So(err, ShouldBeNil)
So(has, ShouldBeTrue)
// we currently skip to migrations. We should rewrite skipped migrations to write in the log as well.
// until then we have to keep this
expectedMigrations := mg.MigrationsCount()
So(r.Count, ShouldEqual, expectedMigrations)
mg = NewMigrator(x)
AddMigrations(mg)
err = mg.Start()
So(err, ShouldBeNil)
has, err = x.SQL(sql).Get(&r)
So(err, ShouldBeNil)
So(has, ShouldBeTrue)
So(r.Count, ShouldEqual, expectedMigrations)
})
}
}