mirror of
https://github.com/retailcrm/mg-transport-core.git
synced 2024-11-21 20:56:04 +03:00
fixes for tests & more tests
This commit is contained in:
parent
f5ae2ea6c5
commit
b1ac06c604
19
cmd/transport-core-tool/main_test.go
Normal file
19
cmd/transport-core-tool/main_test.go
Normal file
@ -0,0 +1,19 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCoreTool_MigrationCommandExists(t *testing.T) {
|
||||
found := false
|
||||
|
||||
for _, cmd := range parser.Commands() {
|
||||
if cmd != nil && cmd.Name == "migration" {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
|
||||
assert.True(t, found)
|
||||
}
|
@ -19,7 +19,7 @@ type EngineTest struct {
|
||||
engine *Engine
|
||||
}
|
||||
|
||||
func (e *EngineTest) SetupSuite() {
|
||||
func (e *EngineTest) SetupTest() {
|
||||
var (
|
||||
db *sql.DB
|
||||
err error
|
||||
|
@ -70,14 +70,14 @@ func (b *HTTPClientBuilder) SetMockedDomains(domains []string) *HTTPClientBuilde
|
||||
return b
|
||||
}
|
||||
|
||||
// DisableSSLVerification disables SSL certificates verification in client
|
||||
func (b *HTTPClientBuilder) DisableSSLVerification() *HTTPClientBuilder {
|
||||
b.logf("WARNING: SSL verification is now disabled, don't use this parameter in production!")
|
||||
|
||||
b.httpTransport.TLSClientConfig = &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
// SetSSLVerification enables or disables SSL certificates verification in client
|
||||
func (b *HTTPClientBuilder) SetSSLVerification(enabled bool) *HTTPClientBuilder {
|
||||
if b.httpTransport.TLSClientConfig == nil {
|
||||
b.httpTransport.TLSClientConfig = &tls.Config{}
|
||||
}
|
||||
|
||||
b.httpTransport.TLSClientConfig.InsecureSkipVerify = !enabled
|
||||
|
||||
return b
|
||||
}
|
||||
|
||||
@ -98,14 +98,12 @@ func (b *HTTPClientBuilder) FromConfig(config *HTTPClientConfig) *HTTPClientBuil
|
||||
b.mockedDomains = config.MockedDomains
|
||||
}
|
||||
|
||||
if !config.SSLVerification {
|
||||
b.DisableSSLVerification()
|
||||
}
|
||||
|
||||
if config.Timeout > 0 {
|
||||
b.SetTimeout(config.Timeout)
|
||||
}
|
||||
|
||||
b.SetSSLVerification(config.SSLVerification)
|
||||
|
||||
return b
|
||||
}
|
||||
|
||||
|
@ -21,12 +21,12 @@ func (t *HTTPClientBuilderTest) SetupSuite() {
|
||||
func (t *HTTPClientBuilderTest) Test_SetTimeout() {
|
||||
t.builder.SetTimeout(90)
|
||||
|
||||
assert.Equal(t.T(), 90, t.builder.timeout)
|
||||
assert.Equal(t.T(), 90, t.builder.httpClient.Timeout)
|
||||
assert.Equal(t.T(), 90*time.Second, t.builder.timeout)
|
||||
assert.Equal(t.T(), 90*time.Second, t.builder.httpClient.Timeout)
|
||||
}
|
||||
|
||||
func (t *HTTPClientBuilderTest) Test_SetMockAddress() {
|
||||
addr := "http://mock.local:3004"
|
||||
addr := "mock.local:3004"
|
||||
t.builder.SetMockAddress(addr)
|
||||
|
||||
assert.Equal(t.T(), addr, t.builder.mockAddress)
|
||||
@ -48,21 +48,23 @@ func (t *HTTPClientBuilderTest) Test_SetMockedDomains() {
|
||||
assert.Equal(t.T(), domains[0], t.builder.mockedDomains[0])
|
||||
}
|
||||
|
||||
func (t *HTTPClientBuilderTest) Test_DisableSSLVerification() {
|
||||
t.builder.DisableSSLVerification()
|
||||
func (t *HTTPClientBuilderTest) Test_SetSSLVerification() {
|
||||
t.builder.SetSSLVerification(true)
|
||||
assert.False(t.T(), t.builder.httpTransport.TLSClientConfig.InsecureSkipVerify)
|
||||
|
||||
t.builder.SetSSLVerification(false)
|
||||
assert.True(t.T(), t.builder.httpTransport.TLSClientConfig.InsecureSkipVerify)
|
||||
}
|
||||
|
||||
func (t *HTTPClientBuilderTest) Test_FromConfig() {
|
||||
config := &HTTPClientConfig{
|
||||
SSLVerification: true,
|
||||
MockAddress: "http://anothermock.local:3004",
|
||||
MockAddress: "anothermock.local:3004",
|
||||
MockedDomains: []string{"example.gov"},
|
||||
Timeout: 60,
|
||||
}
|
||||
|
||||
t.builder.FromConfig(config)
|
||||
|
||||
assert.Equal(t.T(), !config.SSLVerification, t.builder.httpTransport.TLSClientConfig.InsecureSkipVerify)
|
||||
assert.Equal(t.T(), config.MockAddress, t.builder.mockAddress)
|
||||
assert.Equal(t.T(), config.MockedDomains[0], t.builder.mockedDomains[0])
|
||||
@ -75,14 +77,15 @@ func (t *HTTPClientBuilderTest) Test_FromEngine() {
|
||||
Config: Config{
|
||||
HTTPClientConfig: &HTTPClientConfig{
|
||||
SSLVerification: true,
|
||||
MockAddress: "http://anothermock.local:3004",
|
||||
MockAddress: "anothermock.local:3004",
|
||||
MockedDomains: []string{"example.gov"},
|
||||
},
|
||||
Debug: false,
|
||||
},
|
||||
}
|
||||
|
||||
assert.Equal(t.T(), engine, t.builder.engine)
|
||||
t.builder.FromEngine(engine)
|
||||
assert.NotNil(t.T(), engine, t.builder.engine)
|
||||
}
|
||||
|
||||
func (t *HTTPClientBuilderTest) Test_buildDialer() {
|
||||
@ -108,7 +111,11 @@ func (t *HTTPClientBuilderTest) Test_logf() {
|
||||
}
|
||||
|
||||
func (t *HTTPClientBuilderTest) Test_Build() {
|
||||
client, err := t.builder.Build(true)
|
||||
client, err := t.builder.
|
||||
SetTimeout(10).
|
||||
SetMockAddress("api_mock:3004").
|
||||
AddMockedDomain("google.com").
|
||||
Build(true)
|
||||
|
||||
assert.NoError(t.T(), err)
|
||||
assert.NotNil(t.T(), client)
|
||||
@ -116,9 +123,11 @@ func (t *HTTPClientBuilderTest) Test_Build() {
|
||||
}
|
||||
|
||||
func (t *HTTPClientBuilderTest) Test_RestoreDefault() {
|
||||
t.builder.ReplaceDefault()
|
||||
t.builder.RestoreDefault()
|
||||
|
||||
assert.NotEqual(t.T(), http.DefaultClient, t.builder.httpClient)
|
||||
assert.Equal(t.T(), http.DefaultClient, DefaultClient)
|
||||
assert.Equal(t.T(), http.DefaultTransport, DefaultTransport)
|
||||
}
|
||||
|
||||
func Test_HTTPClientBuilder(t *testing.T) {
|
||||
|
39
core/migration_generator_test.go
Normal file
39
core/migration_generator_test.go
Normal file
@ -0,0 +1,39 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
type MigrationGeneratorSuite struct {
|
||||
suite.Suite
|
||||
command *NewMigrationCommand
|
||||
}
|
||||
|
||||
func (s *MigrationGeneratorSuite) SetupSuite() {
|
||||
s.command = &NewMigrationCommand{Directory: "/tmp"}
|
||||
}
|
||||
|
||||
func (s *MigrationGeneratorSuite) Test_Execute() {
|
||||
found := false
|
||||
assert.NoError(s.T(), s.command.Execute([]string{}))
|
||||
files, err := ioutil.ReadDir(s.command.Directory)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
for _, f := range files {
|
||||
if strings.Index(f.Name(), "_app.go") != -1 {
|
||||
found = true
|
||||
assert.NoError(s.T(), os.Remove(path.Join(s.command.Directory, f.Name())))
|
||||
}
|
||||
}
|
||||
|
||||
assert.True(s.T(), found)
|
||||
}
|
@ -46,7 +46,7 @@ func (u *UtilsTest) SetupSuite() {
|
||||
|
||||
func (u *UtilsTest) Test_ResetUtils() {
|
||||
assert.Equal(u.T(), "access key id (will be removed)", u.utils.ConfigAWS.AccessKeyID)
|
||||
assert.Equal(u.T(), uint32(12345), u.utils.TokenCounter)
|
||||
assert.Equal(u.T(), uint32(12346), u.utils.TokenCounter)
|
||||
assert.False(u.T(), u.utils.IsDebug)
|
||||
|
||||
awsConfig := u.utils.ConfigAWS
|
||||
|
Loading…
Reference in New Issue
Block a user