Skip to content

Commit

Permalink
Fixing failing unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
naemono committed Mar 22, 2020
1 parent a4583f1 commit 48cb398
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
4 changes: 1 addition & 3 deletions cli/client/config/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ func (m *MockConfig) Namespace() string {
// Timeout mocks the timeout config
func (m *MockConfig) Timeout() time.Duration {
args := m.Called()
timeoutString := args.String(0)
d, _ := time.ParseDuration(timeoutString)
return d
return args.Get(0).(time.Duration)
}

// TrustedCAFile mocks the trusted CA file config
Expand Down
4 changes: 1 addition & 3 deletions cli/client/testing/mock_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ func (m *MockConfig) TrustedCAFile() string {
// Timeout mocks the timeout config
func (m *MockConfig) Timeout() time.Duration {
args := m.Called()
timeoutString := args.String(0)
d, _ := time.ParseDuration(timeoutString)
return d
return args.Get(0).(time.Duration)
}

// SaveAPIUrl mocks saving the API URL
Expand Down
2 changes: 2 additions & 0 deletions cli/commands/config/view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"testing"
"time"

corev2 "github.com/sensu/sensu-go/api/core/v2"
clienttest "github.com/sensu/sensu-go/cli/client/testing"
Expand Down Expand Up @@ -37,6 +38,7 @@ func TestViewExec(t *testing.T) {
config.On("Tokens").Return(
corev2.FixtureTokens("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1NjIxODkzMTcsImp0aSI6IjAwZDFlYTE2OGU1MTQ1ZGEzN2U2Njg0YmRlOTgwNDM4Iiwic3ViIjoiYWRtaW4iLCJncm91cHMiOlsiY2x1c3Rlci1hZG1pbnMiLCJzeXN0ZW06dXNlcnMiXSwicHJvdmlkZXIiOnsicHJvdmlkZXJfaWQiOiJiYXNpYyIsInVzZXJfaWQiOiJhZG1pbiJ9fQ.ksuMGCJtkN5724CQ7e2W1P7T2ZPpR8IxU3fH9WhBMLk", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI0MGVhYTRiMzRkMzU4YTkzNTY5YzIzZWM1YjcxNmZiMiIsInN1YiI6ImFkbWluIiwiZ3JvdXBzIjpudWxsLCJwcm92aWRlciI6eyJwcm92aWRlcl9pZCI6IiIsInVzZXJfaWQiOiIifX0.7t0qoBvKEkHD1DJbhP-VfSj95yhsFyrPoeFhqEbKOn8"),
)
config.On("Timeout").Return(time.Second * 15)

out, err := test.RunCmd(cmd, nil)
assert.Regexp("Active Configuration", out)
Expand Down
3 changes: 3 additions & 0 deletions cli/commands/configure/configure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package configure
import (
"bytes"
"testing"
"time"

"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
Expand All @@ -23,6 +24,7 @@ func TestCommand(t *testing.T) {
mockConfig := cli.Config.(*client.MockConfig)
mockConfig.On("Format").Return(config.DefaultFormat)
mockConfig.On("APIUrl").Return("http://127.0.0.1:8080")
mockConfig.On("Timeout").Return(time.Second * 15)

cmd := Command(cli)

Expand All @@ -48,6 +50,7 @@ func TestCommandRunEClosureWithFlags(t *testing.T) {
mockConfig.On("SaveNamespace", mock.Anything).Return(nil)
mockConfig.On("SaveInsecureSkipTLSVerify", mock.Anything).Return(nil)
mockConfig.On("SaveTrustedCAFile", mock.Anything).Return(nil)
mockConfig.On("Timeout").Return(time.Second * 15)

// We need to call the "configure" command via the rootCmd so the global flags
// are set
Expand Down

0 comments on commit 48cb398

Please sign in to comment.