From f9a39cffaa6d130ffe4eb3526cd265d30a63a150 Mon Sep 17 00:00:00 2001 From: naemono Date: Sun, 22 Mar 2020 18:18:04 -0500 Subject: [PATCH] Fixing failing unit tests Signed-off-by: naemono --- cli/client/config/mock.go | 4 +--- cli/client/testing/mock_config.go | 4 +--- cli/commands/config/view_test.go | 2 ++ cli/commands/configure/configure_test.go | 3 +++ 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/cli/client/config/mock.go b/cli/client/config/mock.go index 94a34df5e4..d0fe3cef75 100644 --- a/cli/client/config/mock.go +++ b/cli/client/config/mock.go @@ -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 diff --git a/cli/client/testing/mock_config.go b/cli/client/testing/mock_config.go index 153491ee2a..745bd830d4 100644 --- a/cli/client/testing/mock_config.go +++ b/cli/client/testing/mock_config.go @@ -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 diff --git a/cli/commands/config/view_test.go b/cli/commands/config/view_test.go index 01703cdd48..12ed9082bf 100644 --- a/cli/commands/config/view_test.go +++ b/cli/commands/config/view_test.go @@ -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" @@ -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) diff --git a/cli/commands/configure/configure_test.go b/cli/commands/configure/configure_test.go index 1cf90072b7..e8ebba8d27 100644 --- a/cli/commands/configure/configure_test.go +++ b/cli/commands/configure/configure_test.go @@ -3,6 +3,7 @@ package configure import ( "bytes" "testing" + "time" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" @@ -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) @@ -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