web/webtest: options to make it more configurable
continuous-integration/drone the build failed
Details
continuous-integration/drone the build failed
Details
This commit is contained in:
parent
6fb3b904df
commit
07218da3f6
|
@ -21,6 +21,12 @@ var (
|
||||||
DBConnection = "user=root password=root dbname=defaultdb host=localhost port=26257 sslmode=disable"
|
DBConnection = "user=root password=root dbname=defaultdb host=localhost port=26257 sslmode=disable"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Option to configure TestServer
|
||||||
|
type Option struct {
|
||||||
|
ReRun bool
|
||||||
|
DBSetup func(db *database.Database)
|
||||||
|
}
|
||||||
|
|
||||||
type testServer struct {
|
type testServer struct {
|
||||||
DB *database.Database
|
DB *database.Database
|
||||||
Mails chan *mailer.TestingMail
|
Mails chan *mailer.TestingMail
|
||||||
|
@ -38,11 +44,16 @@ type Login struct {
|
||||||
|
|
||||||
// New starts WebService for testing
|
// New starts WebService for testing
|
||||||
func New() (*testServer, error) {
|
func New() (*testServer, error) {
|
||||||
return NewWithDBSetup(nil)
|
return NewWithOption(Option{})
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewWithDBSetup allows to reconfigure before ReRun the database - e.g. for adding Migration-Steps
|
// NewWithDBSetup allows to reconfigure before ReRun the database - e.g. for adding Migration-Steps
|
||||||
func NewWithDBSetup(dbCall func(db *database.Database)) (*testServer, error) {
|
func NewWithDBSetup(dbCall func(db *database.Database)) (*testServer, error) {
|
||||||
|
return NewWithOption(Option{ReRun: true, DBSetup: dbCall})
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewWithOption allows to configure WebService for testing
|
||||||
|
func NewWithOption(option Option) (*testServer, error) {
|
||||||
// db setup
|
// db setup
|
||||||
dbConfig := database.Database{
|
dbConfig := database.Database{
|
||||||
Connection: DBConnection,
|
Connection: DBConnection,
|
||||||
|
@ -50,10 +61,15 @@ func NewWithDBSetup(dbCall func(db *database.Database)) (*testServer, error) {
|
||||||
Debug: false,
|
Debug: false,
|
||||||
LogLevel: 0,
|
LogLevel: 0,
|
||||||
}
|
}
|
||||||
if dbCall != nil {
|
if option.DBSetup != nil {
|
||||||
dbCall(&dbConfig)
|
option.DBSetup(&dbConfig)
|
||||||
|
}
|
||||||
|
var err error
|
||||||
|
if option.ReRun {
|
||||||
|
err = dbConfig.ReRun()
|
||||||
|
} else {
|
||||||
|
err = dbConfig.Run()
|
||||||
}
|
}
|
||||||
err := dbConfig.ReRun()
|
|
||||||
if err != nil && err != database.ErrNothingToMigrate {
|
if err != nil && err != database.ErrNothingToMigrate {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue