fix zap.Logger in webtest
continuous-integration/drone the build failed
Details
continuous-integration/drone the build failed
Details
This commit is contained in:
parent
36c185100b
commit
694ca30e0d
|
@ -45,6 +45,11 @@ type Service struct {
|
||||||
modules []ModuleRegisterFunc
|
modules []ModuleRegisterFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetLog - set new logger
|
||||||
|
func (s *Service) SetLog(l *zap.Logger) {
|
||||||
|
s.log = l
|
||||||
|
}
|
||||||
|
|
||||||
// Log - get current logger
|
// Log - get current logger
|
||||||
func (s *Service) Log() *zap.Logger {
|
func (s *Service) Log() *zap.Logger {
|
||||||
return s.log
|
return s.log
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -17,13 +18,13 @@ func TestRun(t *testing.T) {
|
||||||
s := &Service{AccessLog: true, Listen: "8.8.8.8:80"}
|
s := &Service{AccessLog: true, Listen: "8.8.8.8:80"}
|
||||||
s.ModuleRegister(func(_ *gin.Engine, _ *Service) {})
|
s.ModuleRegister(func(_ *gin.Engine, _ *Service) {})
|
||||||
// HTTP - failed
|
// HTTP - failed
|
||||||
err := s.Run()
|
err := s.Run(zap.L())
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
|
|
||||||
s.ACME.Enable = true
|
s.ACME.Enable = true
|
||||||
// acme with listen port - panic
|
// acme with listen port - panic
|
||||||
assert.Panics(func() {
|
assert.Panics(func() {
|
||||||
s.Run()
|
s.Run(zap.L())
|
||||||
})
|
})
|
||||||
|
|
||||||
if TestRunTLS == "false" {
|
if TestRunTLS == "false" {
|
||||||
|
@ -31,6 +32,6 @@ func TestRun(t *testing.T) {
|
||||||
}
|
}
|
||||||
s.Listen = ""
|
s.Listen = ""
|
||||||
// httpS - failed
|
// httpS - failed
|
||||||
err = s.Run()
|
err = s.Run(zap.L())
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"go.uber.org/zap"
|
||||||
|
|
||||||
"dev.sum7.eu/genofire/golang-lib/database"
|
"dev.sum7.eu/genofire/golang-lib/database"
|
||||||
"dev.sum7.eu/genofire/golang-lib/mailer"
|
"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
|
// New allows to configure WebService for testing
|
||||||
func (option Option) New() (*TestServer, error) {
|
func (option Option) New() (*TestServer, error) {
|
||||||
|
log := zap.L()
|
||||||
|
|
||||||
ws := &web.Service{}
|
ws := &web.Service{}
|
||||||
|
ws.SetLog(log)
|
||||||
ws.Session.Name = "mysession"
|
ws.Session.Name = "mysession"
|
||||||
ws.Session.Secret = "hidden"
|
ws.Session.Secret = "hidden"
|
||||||
|
|
||||||
|
@ -100,7 +103,7 @@ func (option Option) New() (*TestServer, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if option.Mailer {
|
if option.Mailer {
|
||||||
mock, mail := mailer.NewFakeServer()
|
mock, mail := mailer.NewFakeServer(log)
|
||||||
if err := mail.Setup(); err != nil {
|
if err := mail.Setup(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue