Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
db0fb1e2
Unverified
Commit
db0fb1e2
authored
Dec 04, 2020
by
Emil Hessman
Committed by
GitHub
Dec 04, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Chore: Rewrite sqlstore migration test to use standard library (#29589)
Signed-off-by: Emil Hessman <emil@hessman.se>
parent
3c1bcc72
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
48 deletions
+37
-48
pkg/services/sqlstore/migrations/migrations_test.go
+37
-48
No files found.
pkg/services/sqlstore/migrations/migrations_test.go
View file @
db0fb1e2
...
...
@@ -5,56 +5,45 @@ import (
.
"github.com/grafana/grafana/pkg/services/sqlstore/migrator"
"github.com/grafana/grafana/pkg/services/sqlstore/sqlutil"
"github.com/stretchr/testify/require"
"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
)
})
}
testDB
:=
sqlutil
.
SQLite3TestDB
()
const
query
=
`select count(*) as count from migration_log`
result
:=
struct
{
Count
int
}{}
x
,
err
:=
xorm
.
NewEngine
(
testDB
.
DriverName
,
testDB
.
ConnStr
)
require
.
NoError
(
t
,
err
)
err
=
NewDialect
(
x
)
.
CleanDB
()
require
.
NoError
(
t
,
err
)
_
,
err
=
x
.
SQL
(
query
)
.
Get
(
&
result
)
require
.
Error
(
t
,
err
)
mg
:=
NewMigrator
(
x
)
AddMigrations
(
mg
)
expectedMigrations
:=
mg
.
MigrationsCount
()
err
=
mg
.
Start
()
require
.
NoError
(
t
,
err
)
has
,
err
:=
x
.
SQL
(
query
)
.
Get
(
&
result
)
require
.
NoError
(
t
,
err
)
require
.
True
(
t
,
has
)
require
.
Equal
(
t
,
expectedMigrations
,
result
.
Count
)
mg
=
NewMigrator
(
x
)
AddMigrations
(
mg
)
err
=
mg
.
Start
()
require
.
NoError
(
t
,
err
)
has
,
err
=
x
.
SQL
(
query
)
.
Get
(
&
result
)
require
.
NoError
(
t
,
err
)
require
.
True
(
t
,
has
)
require
.
Equal
(
t
,
expectedMigrations
,
result
.
Count
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment