fix zap.Logger in webtest
continuous-integration/drone the build failed Details

This commit is contained in:
genofire 2021-09-29 14:30:17 +02:00
parent 36c185100b
commit 694ca30e0d
3 changed files with 13 additions and 4 deletions

View File

@ -45,6 +45,11 @@ type Service struct {
modules []ModuleRegisterFunc
}
// SetLog - set new logger
func (s *Service) SetLog(l *zap.Logger) {
s.log = l
}
// Log - get current logger
func (s *Service) Log() *zap.Logger {
return s.log

View File

@ -5,6 +5,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
"go.uber.org/zap"
)
var (
@ -17,13 +18,13 @@ func TestRun(t *testing.T) {
s := &Service{AccessLog: true, Listen: "8.8.8.8:80"}
s.ModuleRegister(func(_ *gin.Engine, _ *Service) {})
// HTTP - failed
err := s.Run()
err := s.Run(zap.L())
assert.Error(err)
s.ACME.Enable = true
// acme with listen port - panic
assert.Panics(func() {
s.Run()
s.Run(zap.L())
})
if TestRunTLS == "false" {
@ -31,6 +32,6 @@ func TestRun(t *testing.T) {
}
s.Listen = ""
// httpS - failed
err = s.Run()
err = s.Run(zap.L())
assert.Error(err)
}

View File

@ -10,6 +10,7 @@ import (
"strings"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
"dev.sum7.eu/genofire/golang-lib/database"
"dev.sum7.eu/genofire/golang-lib/mailer"
@ -63,8 +64,10 @@ func NewWithDBSetup(modules web.ModuleRegisterFunc, dbCall func(db *database.Dat
// New allows to configure WebService for testing
func (option Option) New() (*TestServer, error) {
log := zap.L()
ws := &web.Service{}
ws.SetLog(log)
ws.Session.Name = "mysession"
ws.Session.Secret = "hidden"
@ -100,7 +103,7 @@ func (option Option) New() (*TestServer, error) {
}
if option.Mailer {
mock, mail := mailer.NewFakeServer()
mock, mail := mailer.NewFakeServer(log)
if err := mail.Setup(); err != nil {
return nil, err
}