web/webtest: setup mailserver only on request
continuous-integration/drone the build failed Details

This commit is contained in:
genofire 2021-09-28 04:23:20 +02:00
parent 009126c253
commit 1e1571a2c3
1 changed files with 18 additions and 16 deletions

View File

@ -24,6 +24,7 @@ var (
// Option to configure TestServer // Option to configure TestServer
type Option struct { type Option struct {
ReRun bool ReRun bool
Mailer bool
DBSetup func(db *database.Database) DBSetup func(db *database.Database)
ModuleLoader web.ModuleRegisterFunc ModuleLoader web.ModuleRegisterFunc
} }
@ -87,31 +88,32 @@ func NewWithOption(option Option) (*TestServer, error) {
gin.EnableJsonDecoderDisallowUnknownFields() gin.EnableJsonDecoderDisallowUnknownFields()
gin.SetMode(gin.TestMode) gin.SetMode(gin.TestMode)
mock, mail := mailer.NewFakeServer()
err = mail.Setup()
if err != nil {
return nil, err
}
ws := &web.Service{ ws := &web.Service{
DB: dbConfig.DB, DB: dbConfig.DB,
Mailer: mail, }
ts := &TestServer{
DB: &dbConfig,
WS: ws,
} }
ws.ModuleRegister(option.ModuleLoader) ws.ModuleRegister(option.ModuleLoader)
ws.Session.Name = "mysession" ws.Session.Name = "mysession"
ws.Session.Secret = "hidden" ws.Session.Secret = "hidden"
if option.Mailer {
mock, mail := mailer.NewFakeServer()
if err := mail.Setup(); err != nil {
return nil, err
}
ws.Mailer = mail
ts.Mails = mock.Mails
ts.Close = mock.Close
}
r := gin.Default() r := gin.Default()
ws.LoadSession(r) ws.LoadSession(r)
ws.Bind(r) ws.Bind(r)
return &TestServer{ ts.gin = r
DB: &dbConfig, return ts, nil
Mails: mock.Mails,
Close: mock.Close,
gin: r,
WS: ws,
}, nil
} }
// DatabaseForget to run a test without a database // DatabaseForget to run a test without a database