better engine coverage

This commit is contained in:
Pavel 2019-12-26 16:45:47 +03:00
parent 990f4f0697
commit b82d4e8258
2 changed files with 50 additions and 21 deletions

View File

@ -173,27 +173,6 @@ func (e *EngineTest) Test_BuildHTTPClient() {
assert.NotNil(e.T(), e.engine.httpClient) assert.NotNil(e.T(), e.engine.httpClient)
} }
func (e *EngineTest) Test_SetHTTPClient() {
var err error
e.engine.httpClient = nil
e.engine.httpClient, err = NewHTTPClientBuilder().Build()
assert.NoError(e.T(), err)
assert.NotNil(e.T(), e.engine.httpClient)
}
func (e *EngineTest) Test_HTTPClient() {
var err error
e.engine.httpClient = nil
assert.NotNil(e.T(), e.engine.HTTPClient())
e.engine.httpClient, err = NewHTTPClientBuilder().Build()
assert.NoError(e.T(), err)
assert.NotNil(e.T(), e.engine.httpClient)
}
func (e *EngineTest) Test_WithCookieSessions() { func (e *EngineTest) Test_WithCookieSessions() {
e.engine.Sessions = nil e.engine.Sessions = nil
e.engine.WithCookieSessions(4) e.engine.WithCookieSessions(4)
@ -208,6 +187,55 @@ func (e *EngineTest) Test_WithFilesystemSessions() {
assert.NotNil(e.T(), e.engine.Sessions) assert.NotNil(e.T(), e.engine.Sessions)
} }
func (e *EngineTest) Test_UnsafeLogger() {
origLogger := e.engine.logger
defer func() {
e.engine.logger = origLogger
}()
e.engine.logger = nil
assert.Nil(e.T(), e.engine.UnsafeLogger())
e.engine.logger = &Logger{}
assert.IsType(e.T(), &Logger{}, e.engine.UnsafeLogger())
}
func (e *EngineTest) Test_SetLogger() {
origLogger := e.engine.logger
defer func() {
e.engine.logger = origLogger
}()
e.engine.logger = &Logger{}
e.engine.SetLogger(nil)
assert.NotNil(e.T(), e.engine.logger)
}
func (e *EngineTest) Test_SetHTTPClient() {
origClient := e.engine.httpClient
defer func() {
e.engine.httpClient = origClient
}()
e.engine.httpClient = nil
httpClient, err := NewHTTPClientBuilder().Build()
require.NoError(e.T(), err)
assert.NotNil(e.T(), httpClient)
e.engine.SetHTTPClient(&http.Client{})
require.NotNil(e.T(), e.engine.httpClient)
e.engine.SetHTTPClient(nil)
assert.NotNil(e.T(), e.engine.httpClient)
}
func (e *EngineTest) Test_HTTPClient() {
origClient := e.engine.httpClient
defer func() {
e.engine.httpClient = origClient
}()
e.engine.httpClient = nil
require.Same(e.T(), http.DefaultClient, e.engine.HTTPClient())
httpClient, err := NewHTTPClientBuilder().Build()
require.NoError(e.T(), err)
e.engine.httpClient = httpClient
assert.Same(e.T(), httpClient, e.engine.HTTPClient())
}
func (e *EngineTest) Test_InitCSRF_Fail() { func (e *EngineTest) Test_InitCSRF_Fail() {
defer func() { defer func() {
assert.NotNil(e.T(), recover()) assert.NotNil(e.T(), recover())

1
go.sum
View File

@ -215,6 +215,7 @@ github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb6
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=