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