mirror of
https://github.com/grafana/grafana.git
synced 2024-12-01 21:19:28 -06:00
6c0752473a
* refactor: tracing service refactoring * refactor: sqlstore to instance service * refactor: sqlstore & registory priority * refactor: sqlstore refactor wip * sqlstore: progress on getting tests to work again * sqlstore: progress on refactoring and getting tests working * sqlstore: connection string fix * fix: not sure why this test is not working and required changing expires * fix: updated grafana-cli
58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
package migrations
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/go-xorm/xorm"
|
|
. "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
|
"github.com/grafana/grafana/pkg/services/sqlstore/sqlutil"
|
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
)
|
|
|
|
func TestMigrations(t *testing.T) {
|
|
testDBs := []sqlutil.TestDB{
|
|
sqlutil.TestDB_Sqlite3,
|
|
}
|
|
|
|
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)
|
|
|
|
NewDialect(x).CleanDB()
|
|
|
|
_, 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)
|
|
expectedMigrations := mg.MigrationsCount() //we currently skip to migrations. We should rewrite skipped migrations to write in the log as well. until then we have to keep this
|
|
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)
|
|
})
|
|
}
|
|
}
|