web/webtest: remove DatabaseMigration to export DB
continuous-integration/drone the build was successful Details

This commit is contained in:
Geno 2021-06-22 20:44:24 +02:00
parent 56ef5276ce
commit 1848fccbef
4 changed files with 9 additions and 21 deletions

View File

@ -6,7 +6,6 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"dev.sum7.eu/genofire/golang-lib/database"
"dev.sum7.eu/genofire/golang-lib/web" "dev.sum7.eu/genofire/golang-lib/web"
"dev.sum7.eu/genofire/golang-lib/web/webtest" "dev.sum7.eu/genofire/golang-lib/web/webtest"
) )
@ -15,9 +14,8 @@ func TestAPILogin(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
s := webtest.New(assert) s := webtest.New(assert)
assert.NotNil(s) assert.NotNil(s)
s.DatabaseMigration(func(db *database.Database) { SetupMigration(s.DB)
SetupMigration(db) s.DB.MigrateTestdata()
})
hErr := web.HTTPError{} hErr := web.HTTPError{}
// invalid // invalid

View File

@ -6,7 +6,6 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"dev.sum7.eu/genofire/golang-lib/database"
"dev.sum7.eu/genofire/golang-lib/web" "dev.sum7.eu/genofire/golang-lib/web"
"dev.sum7.eu/genofire/golang-lib/web/webtest" "dev.sum7.eu/genofire/golang-lib/web/webtest"
) )
@ -15,9 +14,8 @@ func TestAPIPassword(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
s := webtest.New(assert) s := webtest.New(assert)
assert.NotNil(s) assert.NotNil(s)
s.DatabaseMigration(func(db *database.Database) { SetupMigration(s.DB)
SetupMigration(db) s.DB.MigrateTestdata()
})
passwordCurrent := "CHANGEME" passwordCurrent := "CHANGEME"
passwordNew := "test" passwordNew := "test"

View File

@ -6,7 +6,6 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"dev.sum7.eu/genofire/golang-lib/database"
"dev.sum7.eu/genofire/golang-lib/web" "dev.sum7.eu/genofire/golang-lib/web"
"dev.sum7.eu/genofire/golang-lib/web/webtest" "dev.sum7.eu/genofire/golang-lib/web/webtest"
) )
@ -15,9 +14,8 @@ func TestAPIStatus(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
s := webtest.New(assert) s := webtest.New(assert)
assert.NotNil(s) assert.NotNil(s)
s.DatabaseMigration(func(db *database.Database) { SetupMigration(s.DB)
SetupMigration(db) s.DB.MigrateTestdata()
})
hErr := web.HTTPError{} hErr := web.HTTPError{}
// invalid // invalid

View File

@ -22,7 +22,7 @@ var (
) )
type testServer struct { type testServer struct {
db *database.Database DB *database.Database
gin *gin.Engine gin *gin.Engine
ws *web.Service ws *web.Service
assert *assert.Assertions assert *assert.Assertions
@ -65,7 +65,7 @@ func New(assert *assert.Assertions) *testServer {
ws.LoadSession(r) ws.LoadSession(r)
ws.Bind(r) ws.Bind(r)
return &testServer{ return &testServer{
db: &dbConfig, DB: &dbConfig,
gin: r, gin: r,
ws: ws, ws: ws,
assert: assert, assert: assert,
@ -75,13 +75,7 @@ func New(assert *assert.Assertions) *testServer {
// DatabaseForget, to run a test without a database // DatabaseForget, to run a test without a database
func (s *testServer) DatabaseForget() { func (s *testServer) DatabaseForget() {
s.ws.DB = nil s.ws.DB = nil
s.db = nil s.DB = nil
}
// DatabaseMigration set up a migration on webtest WebService
func (s *testServer) DatabaseMigration(f func(db *database.Database)) {
f(s.db)
s.db.MigrateTestdata()
} }
// Request sends a request to webtest WebService // Request sends a request to webtest WebService