From 1848fccbeffc38ee4cb7dd56594af4569c978991 Mon Sep 17 00:00:00 2001 From: Geno Date: Tue, 22 Jun 2021 20:44:24 +0200 Subject: [PATCH] web/webtest: remove DatabaseMigration to export DB --- web/auth/api_login_test.go | 6 ++---- web/auth/api_password_test.go | 6 ++---- web/auth/api_status_test.go | 6 ++---- web/webtest/main.go | 12 +++--------- 4 files changed, 9 insertions(+), 21 deletions(-) diff --git a/web/auth/api_login_test.go b/web/auth/api_login_test.go index 87d9857..11d1714 100644 --- a/web/auth/api_login_test.go +++ b/web/auth/api_login_test.go @@ -6,7 +6,6 @@ import ( "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/webtest" ) @@ -15,9 +14,8 @@ func TestAPILogin(t *testing.T) { assert := assert.New(t) s := webtest.New(assert) assert.NotNil(s) - s.DatabaseMigration(func(db *database.Database) { - SetupMigration(db) - }) + SetupMigration(s.DB) + s.DB.MigrateTestdata() hErr := web.HTTPError{} // invalid diff --git a/web/auth/api_password_test.go b/web/auth/api_password_test.go index 58e0f3e..759dd2e 100644 --- a/web/auth/api_password_test.go +++ b/web/auth/api_password_test.go @@ -6,7 +6,6 @@ import ( "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/webtest" ) @@ -15,9 +14,8 @@ func TestAPIPassword(t *testing.T) { assert := assert.New(t) s := webtest.New(assert) assert.NotNil(s) - s.DatabaseMigration(func(db *database.Database) { - SetupMigration(db) - }) + SetupMigration(s.DB) + s.DB.MigrateTestdata() passwordCurrent := "CHANGEME" passwordNew := "test" diff --git a/web/auth/api_status_test.go b/web/auth/api_status_test.go index aca6661..52ba659 100644 --- a/web/auth/api_status_test.go +++ b/web/auth/api_status_test.go @@ -6,7 +6,6 @@ import ( "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/webtest" ) @@ -15,9 +14,8 @@ func TestAPIStatus(t *testing.T) { assert := assert.New(t) s := webtest.New(assert) assert.NotNil(s) - s.DatabaseMigration(func(db *database.Database) { - SetupMigration(db) - }) + SetupMigration(s.DB) + s.DB.MigrateTestdata() hErr := web.HTTPError{} // invalid diff --git a/web/webtest/main.go b/web/webtest/main.go index 20d17ac..ae9afdc 100644 --- a/web/webtest/main.go +++ b/web/webtest/main.go @@ -22,7 +22,7 @@ var ( ) type testServer struct { - db *database.Database + DB *database.Database gin *gin.Engine ws *web.Service assert *assert.Assertions @@ -65,7 +65,7 @@ func New(assert *assert.Assertions) *testServer { ws.LoadSession(r) ws.Bind(r) return &testServer{ - db: &dbConfig, + DB: &dbConfig, gin: r, ws: ws, assert: assert, @@ -75,13 +75,7 @@ func New(assert *assert.Assertions) *testServer { // DatabaseForget, to run a test without a database func (s *testServer) DatabaseForget() { s.ws.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() + s.DB = nil } // Request sends a request to webtest WebService