diff --git a/cmd/app/add_test.go b/cmd/app/add_test.go index 678a9208..1c77c8bc 100644 --- a/cmd/app/add_test.go +++ b/cmd/app/add_test.go @@ -352,7 +352,7 @@ func TestAppAddCommand(t *testing.T) { mockProjectConfig.On("Cache").Return(mockProjectCache) cm.Config.ProjectConfig = mockProjectConfig }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { cm.ApiInterface.AssertCalled(t, "DeveloperAppInstall", mock.Anything, mock.Anything, mockOrgAuth.Token, mock.Anything, mock.Anything, mock.Anything, "T123", mock.Anything) }, }, diff --git a/cmd/app/delete_test.go b/cmd/app/delete_test.go index 1d962c27..a87aaf44 100644 --- a/cmd/app/delete_test.go +++ b/cmd/app/delete_test.go @@ -74,7 +74,7 @@ func TestAppsDeleteCommand(t *testing.T) { appClientMock.On("Remove", mock.Anything, mock.Anything).Return(fakeDeployedApp, nil) cf.AppClient().AppClientInterface = appClientMock }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { cm.ApiInterface.AssertCalled(t, "DeleteApp", mock.Anything, mock.Anything, fakeDeployedApp.AppID) }, ExpectedStdoutOutputs: []string{ @@ -107,7 +107,7 @@ func TestAppsDeleteCommand(t *testing.T) { appClientMock.On("Remove", mock.Anything, mock.Anything).Return(fakeLocalApp, nil) cf.AppClient().AppClientInterface = appClientMock }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { cm.ApiInterface.AssertCalled(t, "DeleteApp", mock.Anything, mock.Anything, fakeLocalApp.AppID) }, ExpectedStdoutOutputs: []string{ diff --git a/cmd/app/link_test.go b/cmd/app/link_test.go index b2fd09f4..ccb0d795 100644 --- a/cmd/app/link_test.go +++ b/cmd/app/link_test.go @@ -95,7 +95,7 @@ func Test_Apps_Link(t *testing.T) { ).Return(api.GetAppStatusResult{}, nil) }, CmdArgs: []string{}, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { expectedApp := types.App{ AppID: mockLinkAppID1, TeamDomain: mockLinkSlackAuth1.TeamDomain, @@ -103,7 +103,7 @@ func Test_Apps_Link(t *testing.T) { EnterpriseID: mockLinkSlackAuth1.EnterpriseID, } actualApp, err := cm.AppClient.GetDeployed( - context.Background(), + ctx, mockLinkSlackAuth1.TeamID, ) require.NoError(t, err) @@ -153,7 +153,7 @@ func Test_Apps_Link(t *testing.T) { ).Return(api.GetAppStatusResult{}, nil) }, CmdArgs: []string{}, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { expectedApp := types.App{ AppID: mockLinkAppID2, TeamDomain: mockLinkSlackAuth2.TeamDomain, @@ -162,7 +162,7 @@ func Test_Apps_Link(t *testing.T) { UserID: mockLinkSlackAuth2.UserID, } actualApp, err := cm.AppClient.GetLocal( - context.Background(), + ctx, mockLinkSlackAuth2.TeamID, ) require.NoError(t, err) @@ -220,7 +220,7 @@ func Test_Apps_Link(t *testing.T) { ).Return(api.GetAppStatusResult{}, nil) }, CmdArgs: []string{}, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { expectedApp := types.App{ AppID: mockLinkAppID1, TeamDomain: mockLinkSlackAuth1.TeamDomain, @@ -228,7 +228,7 @@ func Test_Apps_Link(t *testing.T) { EnterpriseID: mockLinkSlackAuth1.EnterpriseID, } actualApp, err := cm.AppClient.GetDeployed( - context.Background(), + ctx, mockLinkSlackAuth1.TeamID, ) require.NoError(t, err) @@ -289,7 +289,7 @@ func Test_Apps_Link(t *testing.T) { ).Return(api.GetAppStatusResult{}, nil) }, CmdArgs: []string{}, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { expectedApp := types.App{ AppID: mockLinkAppID1, TeamDomain: mockLinkSlackAuth1.TeamDomain, @@ -297,13 +297,13 @@ func Test_Apps_Link(t *testing.T) { EnterpriseID: mockLinkSlackAuth1.EnterpriseID, } actualApp, err := cm.AppClient.GetDeployed( - context.Background(), + ctx, mockLinkSlackAuth1.TeamID, ) require.NoError(t, err) assert.Equal(t, expectedApp, actualApp) unsavedApp, err := cm.AppClient.GetLocal( - context.Background(), + ctx, mockLinkSlackAuth1.TeamID, ) require.NoError(t, err) @@ -365,7 +365,7 @@ func Test_Apps_Link(t *testing.T) { ).Return(api.GetAppStatusResult{}, nil) }, CmdArgs: []string{"--force"}, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { expectedApp := types.App{ AppID: mockLinkAppID1, TeamDomain: mockLinkSlackAuth2.TeamDomain, @@ -374,7 +374,7 @@ func Test_Apps_Link(t *testing.T) { UserID: mockLinkSlackAuth2.UserID, } actualApp, err := cm.AppClient.GetLocal( - context.Background(), + ctx, mockLinkSlackAuth2.TeamID, ) require.NoError(t, err) @@ -481,7 +481,7 @@ func Test_Apps_Link(t *testing.T) { ).Return(api.GetAppStatusResult{}, nil) }, CmdArgs: []string{}, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { expectedApp := types.App{ AppID: mockLinkAppID1, TeamDomain: mockLinkSlackAuth1.TeamDomain, @@ -489,7 +489,7 @@ func Test_Apps_Link(t *testing.T) { EnterpriseID: mockLinkSlackAuth1.EnterpriseID, } actualApp, err := cm.AppClient.GetDeployed( - context.Background(), + ctx, mockLinkSlackAuth1.TeamID, ) require.NoError(t, err) @@ -518,9 +518,7 @@ func Test_Apps_Link(t *testing.T) { ).Return(false, nil) }, CmdArgs: []string{}, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { - ctx := t.Context() - + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { // Assert manifest confirmation prompt accepted cm.IO.AssertCalled(t, "ConfirmPrompt", mock.Anything, diff --git a/cmd/auth/login_test.go b/cmd/auth/login_test.go index 968e83b5..a085ef09 100644 --- a/cmd/auth/login_test.go +++ b/cmd/auth/login_test.go @@ -157,7 +157,7 @@ func TestLoginCommmand(t *testing.T) { nil, ) }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { cm.ApiInterface.AssertCalled(t, "ExchangeAuthTicket", mock.Anything, mock.Anything, mockChallengeCode, mock.Anything) }, }, diff --git a/cmd/auth/logout_test.go b/cmd/auth/logout_test.go index 445f75ab..9f1b07d0 100644 --- a/cmd/auth/logout_test.go +++ b/cmd/auth/logout_test.go @@ -47,7 +47,7 @@ func TestLogoutCommand(t *testing.T) { clientsMock.AuthInterface.On("DeleteAuth", mock.Anything, fakeAuthsByTeamSlice[1]).Return(types.SlackAuth{}, nil) }, ExpectedOutputs: []string{"Authorization successfully revoked for all teams"}, - ExpectedAsserts: func(t *testing.T, clients *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clients *shared.ClientsMock) { clients.AuthInterface.AssertCalled(t, "RevokeToken", mock.Anything, fakeAuthsByTeamSlice[0].Token) clients.AuthInterface.AssertCalled(t, "RevokeToken", mock.Anything, fakeAuthsByTeamSlice[0].RefreshToken) clients.AuthInterface.AssertCalled(t, "RevokeToken", mock.Anything, fakeAuthsByTeamSlice[1].Token) @@ -74,7 +74,7 @@ func TestLogoutCommand(t *testing.T) { clientsMock.AuthInterface.On("DeleteAuth", mock.Anything, fakeAuthsByTeamSlice[0]).Return(types.SlackAuth{}, nil) }, ExpectedOutputs: []string{"Authorization successfully revoked for team1"}, - ExpectedAsserts: func(t *testing.T, clients *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clients *shared.ClientsMock) { clients.AuthInterface.AssertCalled(t, "RevokeToken", mock.Anything, fakeAuthsByTeamSlice[0].Token) clients.AuthInterface.AssertCalled(t, "RevokeToken", mock.Anything, fakeAuthsByTeamSlice[0].RefreshToken) clients.AuthInterface.AssertCalled(t, "DeleteAuth", mock.Anything, fakeAuthsByTeamSlice[0]) @@ -98,7 +98,7 @@ func TestLogoutCommand(t *testing.T) { clientsMock.AuthInterface.On("DeleteAuth", mock.Anything, fakeAuthsByTeamSlice[1]).Return(types.SlackAuth{}, nil) }, ExpectedOutputs: []string{"Authorization successfully revoked for team2"}, - ExpectedAsserts: func(t *testing.T, clients *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clients *shared.ClientsMock) { clients.AuthInterface.AssertCalled(t, "RevokeToken", mock.Anything, fakeAuthsByTeamSlice[1].Token) clients.AuthInterface.AssertCalled(t, "RevokeToken", mock.Anything, fakeAuthsByTeamSlice[1].RefreshToken) clients.AuthInterface.AssertCalled(t, "DeleteAuth", mock.Anything, fakeAuthsByTeamSlice[1]) @@ -108,7 +108,7 @@ func TestLogoutCommand(t *testing.T) { "require a team value with the flag": { CmdArgs: []string{"--team", ""}, ExpectedErrorStrings: []string{"The argument is missing from the --team flag (missing_flag)"}, - ExpectedAsserts: func(t *testing.T, clients *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clients *shared.ClientsMock) { clients.AuthInterface.AssertNotCalled(t, "RevokeToken") clients.IO.AssertNotCalled(t, "SelectPrompt", mock.Anything, "Select an workspace authorization to revoke", mock.Anything, mock.Anything) }, @@ -125,7 +125,7 @@ func TestLogoutCommand(t *testing.T) { }, nil) }, ExpectedErrorStrings: []string{"invalid_auth", "Cannot revoke authentication tokens for 'randomteamdomain'"}, - ExpectedAsserts: func(t *testing.T, clients *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clients *shared.ClientsMock) { clients.AuthInterface.AssertNotCalled(t, "RevokeToken") clients.IO.AssertCalled(t, "SelectPrompt", mock.Anything, "Select an authorization to revoke", mock.Anything, mock.Anything) }, @@ -151,7 +151,7 @@ func TestLogoutCommand(t *testing.T) { clientsMock.AuthInterface.On("DeleteAuth", mock.Anything, fakeAuthsByTeamSlice[1]).Return(types.SlackAuth{}, nil) }, ExpectedOutputs: []string{"Authorization successfully revoked for team2"}, - ExpectedAsserts: func(t *testing.T, clients *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clients *shared.ClientsMock) { clients.AuthInterface.AssertCalled(t, "RevokeToken", mock.Anything, fakeAuthsByTeamSlice[1].Token) clients.AuthInterface.AssertCalled(t, "RevokeToken", mock.Anything, fakeAuthsByTeamSlice[1].RefreshToken) clients.AuthInterface.AssertCalled(t, "DeleteAuth", mock.Anything, fakeAuthsByTeamSlice[1]) @@ -171,7 +171,7 @@ func TestLogoutCommand(t *testing.T) { clientsMock.AuthInterface.On("DeleteAuth", mock.Anything, fakeAuthsByTeamSlice[0]).Return(types.SlackAuth{}, nil) }, ExpectedOutputs: []string{"Authorization successfully revoked for team1"}, - ExpectedAsserts: func(t *testing.T, clients *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clients *shared.ClientsMock) { clients.AuthInterface.AssertCalled(t, "RevokeToken", mock.Anything, fakeAuthsByTeamSlice[0].Token) clients.AuthInterface.AssertCalled(t, "RevokeToken", mock.Anything, fakeAuthsByTeamSlice[0].RefreshToken) clients.AuthInterface.AssertCalled(t, "DeleteAuth", mock.Anything, fakeAuthsByTeamSlice[0]) @@ -192,7 +192,7 @@ func TestLogoutCommand(t *testing.T) { }, nil) }, ExpectedErrorStrings: []string{"invalid_auth", "Cannot revoke authentication tokens for 'anotherteam'"}, - ExpectedAsserts: func(t *testing.T, clients *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clients *shared.ClientsMock) { clients.AuthInterface.AssertNotCalled(t, "RevokeToken") clients.IO.AssertCalled(t, "SelectPrompt", mock.Anything, "Select an authorization to revoke", mock.Anything, mock.Anything) }, @@ -203,7 +203,7 @@ func TestLogoutCommand(t *testing.T) { clientsMock.AuthInterface.On("Auths", mock.Anything).Return([]types.SlackAuth{}, nil) }, ExpectedOutputs: []string{"All authorizations successfully revoked"}, - ExpectedAsserts: func(t *testing.T, clients *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clients *shared.ClientsMock) { clients.AuthInterface.AssertNotCalled(t, "RevokeToken") clients.IO.AssertNotCalled(t, "SelectPrompt", mock.Anything, "Select an authorization to revoke", mock.Anything, mock.Anything) }, @@ -219,7 +219,7 @@ func TestLogoutCommand(t *testing.T) { Option: "someteam", }, nil) }, - ExpectedAsserts: func(t *testing.T, clients *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clients *shared.ClientsMock) { clients.AuthInterface.AssertNotCalled(t, "RevokeToken") clients.IO.AssertCalled(t, "SelectPrompt", mock.Anything, "Select an authorization to revoke", mock.Anything, mock.Anything) }, diff --git a/cmd/auth/revoke_test.go b/cmd/auth/revoke_test.go index e0cc37e0..997e18a7 100644 --- a/cmd/auth/revoke_test.go +++ b/cmd/auth/revoke_test.go @@ -41,7 +41,7 @@ func TestRevokeCommand(t *testing.T) { clientsMock.AuthInterface.On("RevokeToken", mock.Anything, "xoxp-example-1234").Return(nil) }, ExpectedOutputs: []string{"Authorization successfully revoked"}, - ExpectedAsserts: func(t *testing.T, clients *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clients *shared.ClientsMock) { clients.AuthInterface.AssertCalled(t, "RevokeToken", mock.Anything, "xoxp-example-1234") }, }, @@ -53,7 +53,7 @@ func TestRevokeCommand(t *testing.T) { })).Return(iostreams.PasswordPromptResponse{}, slackerror.New(slackerror.ErrMissingFlag)) }, ExpectedErrorStrings: []string{"Failed to collect a token to revoke", "no_token_found", "missing_flag"}, - ExpectedAsserts: func(t *testing.T, clients *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clients *shared.ClientsMock) { clients.AuthInterface.AssertNotCalled(t, "RevokeToken") }, }, @@ -69,7 +69,7 @@ func TestRevokeCommand(t *testing.T) { clientsMock.AuthInterface.On("RevokeToken", mock.Anything, "xoxp-example-1234").Return(nil) }, ExpectedOutputs: []string{"Authorization successfully revoked"}, - ExpectedAsserts: func(t *testing.T, clients *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clients *shared.ClientsMock) { clients.AuthInterface.AssertCalled(t, "RevokeToken", mock.Anything, "xoxp-example-1234") }, }, @@ -85,7 +85,7 @@ func TestRevokeCommand(t *testing.T) { clientsMock.AuthInterface.On("RevokeToken", mock.Anything, "xoxp-example-1234").Return(slackerror.New(slackerror.ErrNotAuthed)) }, ExpectedError: slackerror.New(slackerror.ErrNotAuthed), - ExpectedAsserts: func(t *testing.T, clients *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clients *shared.ClientsMock) { clients.AuthInterface.AssertCalled(t, "RevokeToken", mock.Anything, "xoxp-example-1234") clients.IO.AssertNotCalled(t, "PrintTrace", mock.Anything, slacktrace.AuthRevokeSuccess) }, diff --git a/cmd/collaborators/add_test.go b/cmd/collaborators/add_test.go index 32945485..b168c7b6 100644 --- a/cmd/collaborators/add_test.go +++ b/cmd/collaborators/add_test.go @@ -39,13 +39,13 @@ func TestAddCommand(t *testing.T) { appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{App: types.App{AppID: "A123"}, Auth: types.SlackAuth{}}, nil) // Set experiment flag cm.Config.ExperimentsFlag = append(cm.Config.ExperimentsFlag, "read-only-collaborators") - cm.Config.LoadExperiments(context.Background(), cm.IO.PrintDebug) + cm.Config.LoadExperiments(ctx, cm.IO.PrintDebug) // Mock API call cm.ApiInterface.On("AddCollaborator", mock.Anything, mock.Anything, "A123", types.SlackUser{ID: "U123", PermissionType: types.READER}).Return(nil) }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { cm.ApiInterface.AssertCalled(t, "AddCollaborator", mock.Anything, mock.Anything, "A123", types.SlackUser{ID: "U123", PermissionType: types.READER}) @@ -63,14 +63,14 @@ func TestAddCommand(t *testing.T) { appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{App: types.App{AppID: "A123"}, Auth: types.SlackAuth{}}, nil) // Set experiment flag cm.Config.ExperimentsFlag = append(cm.Config.ExperimentsFlag, "read-only-collaborators") - cm.Config.LoadExperiments(context.Background(), cm.IO.PrintDebug) + cm.Config.LoadExperiments(ctx, cm.IO.PrintDebug) // Mock API call cm.ApiInterface.On("AddCollaborator", mock.Anything, mock.Anything, "A123", types.SlackUser{Email: "joe.smith@company.com", PermissionType: types.OWNER}).Return(nil) addFlags.permissionType = "owner" }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { cm.ApiInterface.AssertCalled(t, "AddCollaborator", mock.Anything, mock.Anything, "A123", types.SlackUser{Email: "joe.smith@company.com", PermissionType: types.OWNER}) @@ -90,7 +90,7 @@ func TestAddCommand(t *testing.T) { cm.ApiInterface.On("AddCollaborator", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(nil) }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { cm.ApiInterface.AssertCalled(t, "AddCollaborator", mock.Anything, mock.Anything, "A123", types.SlackUser{Email: "joe.smith@company.com", PermissionType: types.OWNER}) diff --git a/cmd/collaborators/remove_test.go b/cmd/collaborators/remove_test.go index 70f31076..338a5bb9 100644 --- a/cmd/collaborators/remove_test.go +++ b/cmd/collaborators/remove_test.go @@ -59,7 +59,7 @@ func TestRemoveCommand(t *testing.T) { cm.ApiInterface.On("RemoveCollaborator", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(nil) }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { collaborator := types.SlackUser{ ID: "USLACKBOT", } @@ -83,7 +83,7 @@ func TestRemoveCommand(t *testing.T) { cm.IO.On("SelectPrompt", mock.Anything, "Remove a collaborator", mock.Anything, mock.Anything). Return(iostreams.SelectPromptResponse{Prompt: true, Index: 1}, nil) }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { cm.ApiInterface.AssertCalled(t, "RemoveCollaborator", mock.Anything, mock.Anything, "A001", mockCollaborators[1]) cm.IO.AssertCalled(t, "PrintTrace", mock.Anything, slacktrace.CollaboratorRemoveSuccess, mock.Anything) cm.IO.AssertCalled(t, "PrintTrace", mock.Anything, slacktrace.CollaboratorRemoveCollaborator, []string{"reader@slack.com"}) @@ -106,7 +106,7 @@ func TestRemoveCommand(t *testing.T) { cm.IO.On("ConfirmPrompt", mock.Anything, "Are you sure you want to remove yourself?", mock.Anything, mock.Anything). Return(false, nil) }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { cm.ApiInterface.AssertNotCalled(t, "RemoveCollaborator", mock.Anything, mock.Anything, mock.Anything, mock.Anything) }, ExpectedError: slackerror.New(slackerror.ErrProcessInterrupted), diff --git a/cmd/collaborators/update_test.go b/cmd/collaborators/update_test.go index 7a090ddb..851b5787 100644 --- a/cmd/collaborators/update_test.go +++ b/cmd/collaborators/update_test.go @@ -39,7 +39,7 @@ func TestUpdateCommand(t *testing.T) { appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{App: types.App{AppID: "A123"}, Auth: types.SlackAuth{}}, nil) // Set experiment flag clientsMock.Config.ExperimentsFlag = append(clientsMock.Config.ExperimentsFlag, "read-only-collaborators") - clientsMock.Config.LoadExperiments(context.Background(), clientsMock.IO.PrintDebug) + clientsMock.Config.LoadExperiments(ctx, clientsMock.IO.PrintDebug) // Mock APi call clientsMock.ApiInterface.On("UpdateCollaborator", mock.Anything, mock.Anything, "A123", @@ -57,7 +57,7 @@ func TestUpdateCommand(t *testing.T) { appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{App: types.App{AppID: "A123"}, Auth: types.SlackAuth{}}, nil) // Set experiment flag clientsMock.Config.ExperimentsFlag = append(clientsMock.Config.ExperimentsFlag, "read-only-collaborators") - clientsMock.Config.LoadExperiments(context.Background(), clientsMock.IO.PrintDebug) + clientsMock.Config.LoadExperiments(ctx, clientsMock.IO.PrintDebug) // Mock APi call clientsMock.ApiInterface.On("UpdateCollaborator", mock.Anything, mock.Anything, "A123", @@ -71,7 +71,7 @@ func TestUpdateCommand(t *testing.T) { clientsMock.AddDefaultMocks() // Set experiment flag clientsMock.Config.ExperimentsFlag = append(clientsMock.Config.ExperimentsFlag, "read-only-collaborators") - clientsMock.Config.LoadExperiments(context.Background(), clientsMock.IO.PrintDebug) + clientsMock.Config.LoadExperiments(ctx, clientsMock.IO.PrintDebug) }, }, "user ID must be provided": { @@ -81,7 +81,7 @@ func TestUpdateCommand(t *testing.T) { clientsMock.AddDefaultMocks() // Set experiment flag clientsMock.Config.ExperimentsFlag = append(clientsMock.Config.ExperimentsFlag, "read-only-collaborators") - clientsMock.Config.LoadExperiments(context.Background(), clientsMock.IO.PrintDebug) + clientsMock.Config.LoadExperiments(ctx, clientsMock.IO.PrintDebug) }, }, }, func(clients *shared.ClientFactory) *cobra.Command { diff --git a/cmd/datastore/bulk_put_test.go b/cmd/datastore/bulk_put_test.go index d5749372..18128f07 100644 --- a/cmd/datastore/bulk_put_test.go +++ b/cmd/datastore/bulk_put_test.go @@ -243,7 +243,7 @@ func TestBulkPutCommandImport(t *testing.T) { *cf = *shared.NewClientFactory(cm.MockClientFactory()) }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { status, _ := importProgressSpinner.Status() assert.Contains(t, status, "Successfully imported (30) items! (0) items failed to be imported. Total processed items is (30)") @@ -273,7 +273,7 @@ func TestBulkPutCommandImport(t *testing.T) { *cf = *shared.NewClientFactory(cm.MockClientFactory()) }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { status, _ := importProgressSpinner.Status() assert.Contains(t, status, "Successfully imported (30) items! (5) items failed to be imported. Total processed items is (35)") @@ -316,7 +316,7 @@ func TestBulkPutCommandImport(t *testing.T) { *cf = *shared.NewClientFactory(cm.MockClientFactory()) }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { status, _ := importProgressSpinner.Status() assert.Contains(t, status, "Successfully imported (5000) items! (0) items failed to be imported. Total processed items is (5000)") }, @@ -343,7 +343,7 @@ func TestBulkPutCommandImport(t *testing.T) { *cf = *shared.NewClientFactory(cm.MockClientFactory()) }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { status, _ := importProgressSpinner.Status() assert.Contains(t, status, "Successfully imported (2) items! (0) items failed to be imported. Total processed items is (2)") diff --git a/cmd/datastore/count_test.go b/cmd/datastore/count_test.go index c64bd56d..65703cbc 100644 --- a/cmd/datastore/count_test.go +++ b/cmd/datastore/count_test.go @@ -135,7 +135,7 @@ func TestCountCommand(t *testing.T) { cm.ApiInterface.On("AppsDatastoreCount", mock.Anything, mock.Anything, mock.Anything). Return(types.AppDatastoreCountResult{Datastore: "tasks", Count: 12}, nil) }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { cm.IO.AssertCalled(t, "PrintTrace", mock.Anything, slacktrace.DatastoreCountSuccess, mock.Anything) cm.IO.AssertCalled(t, "PrintTrace", mock.Anything, slacktrace.DatastoreCountTotal, []string{"12"}) cm.IO.AssertCalled(t, "PrintTrace", mock.Anything, slacktrace.DatastoreCountDatastore, []string{"tasks"}) @@ -154,7 +154,7 @@ func TestCountCommand(t *testing.T) { cm.ApiInterface.On("AppsDatastoreCount", mock.Anything, mock.Anything, mock.Anything). Return(types.AppDatastoreCountResult{Datastore: "tasks", Count: 12}, nil) }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { cm.IO.AssertCalled(t, "PrintTrace", mock.Anything, slacktrace.DatastoreCountSuccess, mock.Anything) cm.IO.AssertCalled(t, "PrintTrace", mock.Anything, slacktrace.DatastoreCountTotal, []string{"12"}) cm.IO.AssertCalled(t, "PrintTrace", mock.Anything, slacktrace.DatastoreCountDatastore, []string{"tasks"}) @@ -175,7 +175,7 @@ func TestCountCommand(t *testing.T) { cm.ApiInterface.On("AppsDatastoreCount", mock.Anything, mock.Anything, mock.Anything). Return(types.AppDatastoreCountResult{Datastore: "tasks", Count: 12}, nil) }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { cm.IO.AssertCalled(t, "PrintTrace", mock.Anything, slacktrace.DatastoreCountSuccess, mock.Anything) cm.IO.AssertCalled(t, "PrintTrace", mock.Anything, slacktrace.DatastoreCountTotal, []string{"12"}) cm.IO.AssertCalled(t, "PrintTrace", mock.Anything, slacktrace.DatastoreCountDatastore, []string{"tasks"}) @@ -206,7 +206,7 @@ func TestCountCommand(t *testing.T) { cm.ApiInterface.On("AppsDatastoreCount", mock.Anything, mock.Anything, mock.Anything). Return(types.AppDatastoreCountResult{Datastore: "tasks", Count: 12}, nil) }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { cm.IO.AssertCalled(t, "PrintTrace", mock.Anything, slacktrace.DatastoreCountSuccess, mock.Anything) cm.IO.AssertCalled(t, "PrintTrace", mock.Anything, slacktrace.DatastoreCountTotal, []string{"12"}) cm.IO.AssertCalled(t, "PrintTrace", mock.Anything, slacktrace.DatastoreCountDatastore, []string{"tasks"}) @@ -254,7 +254,7 @@ func TestCountCommand(t *testing.T) { cm.ApiInterface.On("AppsDatastoreCount", mock.Anything, mock.Anything, mock.Anything). Return(types.AppDatastoreCountResult{Datastore: "numbers", Count: 12}, nil) }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { cm.IO.AssertCalled(t, "PrintTrace", mock.Anything, slacktrace.DatastoreCountSuccess, mock.Anything) cm.IO.AssertCalled(t, "PrintTrace", mock.Anything, slacktrace.DatastoreCountTotal, []string{"12"}) cm.IO.AssertCalled(t, "PrintTrace", mock.Anything, slacktrace.DatastoreCountDatastore, []string{"numbers"}) @@ -310,7 +310,7 @@ func TestCountCommand(t *testing.T) { cm.ApiInterface.On("AppsDatastoreCount", mock.Anything, mock.Anything, mock.Anything). Return(types.AppDatastoreCountResult{Datastore: "numbers", Count: 6}, nil) }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { cm.IO.AssertCalled(t, "PrintTrace", mock.Anything, slacktrace.DatastoreCountSuccess, mock.Anything) cm.IO.AssertCalled(t, "PrintTrace", mock.Anything, slacktrace.DatastoreCountTotal, []string{"6"}) cm.IO.AssertCalled(t, "PrintTrace", mock.Anything, slacktrace.DatastoreCountDatastore, []string{"numbers"}) diff --git a/cmd/datastore/query_test.go b/cmd/datastore/query_test.go index e858fdaf..e7b74363 100644 --- a/cmd/datastore/query_test.go +++ b/cmd/datastore/query_test.go @@ -399,7 +399,7 @@ func TestQueryCommandExport(t *testing.T) { *cf = *shared.NewClientFactory(cm.MockClientFactory()) }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { status, _ := exportProgressSpinner.Status() assert.Contains(t, status, "Successfully exported (10) items!") @@ -428,7 +428,7 @@ func TestQueryCommandExport(t *testing.T) { *cf = *shared.NewClientFactory(cm.MockClientFactory()) }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { status, _ := exportProgressSpinner.Status() assert.Contains(t, status, "Successfully exported (10000) items!") }, diff --git a/cmd/docgen/docgen_test.go b/cmd/docgen/docgen_test.go index c283e159..67752b3c 100644 --- a/cmd/docgen/docgen_test.go +++ b/cmd/docgen/docgen_test.go @@ -39,7 +39,7 @@ func TestNewDocsCommand(t *testing.T) { ExpectedOutputs: []string{ filepath.Join(slackdeps.MockWorkingDirectory, "docs"), }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { cm.Cobra.AssertCalled( t, "GenMarkdownTree", @@ -83,7 +83,7 @@ func TestNewDocsCommand(t *testing.T) { ExpectedOutputs: []string{ filepath.Join(slackdeps.MockWorkingDirectory, "markdown-docs"), }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { cm.Cobra.AssertCalled( t, "GenMarkdownTree", @@ -125,7 +125,7 @@ func TestNewDocsCommand(t *testing.T) { }, CmdArgs: []string{}, ExpectedOutputs: []string{"References saved to: docs"}, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { cm.Cobra.AssertCalled( t, "GenMarkdownTree", diff --git a/cmd/env/add_test.go b/cmd/env/add_test.go index c3aceafe..94ee8178 100644 --- a/cmd/env/add_test.go +++ b/cmd/env/add_test.go @@ -147,7 +147,7 @@ func Test_Env_AddCommand(t *testing.T) { Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { setupEnvAddCommandMocks(cm, cf) }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { cm.ApiInterface.AssertCalled( t, "AddVariable", @@ -185,7 +185,7 @@ func Test_Env_AddCommand(t *testing.T) { nil, ) }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { cm.ApiInterface.AssertCalled( t, "AddVariable", @@ -216,7 +216,7 @@ func Test_Env_AddCommand(t *testing.T) { nil, ) }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { cm.ApiInterface.AssertCalled( t, "AddVariable", @@ -256,7 +256,7 @@ func Test_Env_AddCommand(t *testing.T) { nil, ) }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { cm.ApiInterface.AssertCalled( t, "AddVariable", diff --git a/cmd/env/list_test.go b/cmd/env/list_test.go index b261f53f..07d8787a 100644 --- a/cmd/env/list_test.go +++ b/cmd/env/list_test.go @@ -148,7 +148,7 @@ func Test_Env_ListCommand(t *testing.T) { teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{}, nil) }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { cm.ApiInterface.AssertCalled( t, "ListVariables", diff --git a/cmd/env/remove_test.go b/cmd/env/remove_test.go index b24d1b4e..d75676a7 100644 --- a/cmd/env/remove_test.go +++ b/cmd/env/remove_test.go @@ -155,7 +155,7 @@ func Test_Env_RemoveCommand(t *testing.T) { teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{}, nil) }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { cm.ApiInterface.AssertCalled( t, "RemoveVariable", @@ -214,7 +214,7 @@ func Test_Env_RemoveCommand(t *testing.T) { teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{}, nil) }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { cm.ApiInterface.AssertCalled( t, "ListVariables", @@ -248,7 +248,7 @@ func Test_Env_RemoveCommand(t *testing.T) { teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{}, nil) }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { cm.ApiInterface.AssertCalled( t, "ListVariables", diff --git a/cmd/externalauth/add_secret_test.go b/cmd/externalauth/add_secret_test.go index 6ae691e7..ca92aac1 100644 --- a/cmd/externalauth/add_secret_test.go +++ b/cmd/externalauth/add_secret_test.go @@ -163,11 +163,11 @@ func TestExternalAuthAddClientSecretCommand(t *testing.T) { clientsMock.AddDefaultMocks() // TODO this can probably be replaced by a helper that sets up an apps.json file in // the right place on the afero memfs instance - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, ExpectedOutputs: []string{}, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertCalled(t, "AppsAuthExternalClientSecretAdd", mock.Anything, mock.Anything, fakeAppID, "provider_a", "secret_key_1234") }, }, @@ -198,11 +198,11 @@ func TestExternalAuthAddClientSecretCommand(t *testing.T) { clientsMock.AddDefaultMocks() // TODO this can probably be replaced by a helper that sets up an apps.json file in // the right place on the afero memfs instance - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, ExpectedOutputs: []string{}, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertCalled(t, "AppsAuthExternalClientSecretAdd", mock.Anything, mock.Anything, fakeAppID, "provider_a", "secret_key_1234") }, }, @@ -231,11 +231,11 @@ func TestExternalAuthAddClientSecretCommand(t *testing.T) { clientsMock.AddDefaultMocks() // TODO this can probably be replaced by a helper that sets up an apps.json file in // the right place on the afero memfs instance - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, ExpectedOutputs: []string{}, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertCalled(t, "AppsAuthExternalClientSecretAdd", mock.Anything, mock.Anything, fakeAppID, "provider_a", "secret") }, }, @@ -264,10 +264,10 @@ func TestExternalAuthAddClientSecretCommand(t *testing.T) { clientsMock.AddDefaultMocks() // TODO this can probably be replaced by a helper that sets up an apps.json file in // the right place on the afero memfs instance - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertCalled(t, "AppsAuthExternalClientSecretAdd", mock.Anything, mock.Anything, fakeAppID, "provider_a", "secret") }, }, @@ -289,11 +289,11 @@ func TestExternalAuthAddClientSecretCommand(t *testing.T) { clientsMock.AddDefaultMocks() // TODO this can probably be replaced by a helper that sets up an apps.json file in // the right place on the afero memfs instance - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, ExpectedErrorStrings: []string{"test error"}, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertNotCalled(t, "AppsAuthExternalClientSecretAdd", mock.Anything, mock.Anything, fakeAppID, "provider_a") }, }, diff --git a/cmd/externalauth/add_test.go b/cmd/externalauth/add_test.go index b4c93ba2..682d0d77 100644 --- a/cmd/externalauth/add_test.go +++ b/cmd/externalauth/add_test.go @@ -156,10 +156,10 @@ func TestExternalAuthAddCommand(t *testing.T) { clientsMock.AddDefaultMocks() // TODO this can probably be replaced by a helper that sets up an apps.json file in // the right place on the afero memfs instance - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertCalled(t, "AppsAuthExternalStart", mock.Anything, mock.Anything, fakeAppID, "provider_a") clientsMock.Browser.AssertCalled(t, "OpenURL", "https://authorizationurl1.com") }, @@ -184,10 +184,10 @@ func TestExternalAuthAddCommand(t *testing.T) { clientsMock.AddDefaultMocks() // TODO this can probably be replaced by a helper that sets up an apps.json file in // the right place on the afero memfs instance - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertNotCalled(t, "AppsAuthExternalStart") clientsMock.Browser.AssertNotCalled(t, "OpenURL") }, @@ -212,10 +212,10 @@ func TestExternalAuthAddCommand(t *testing.T) { clientsMock.AddDefaultMocks() // TODO this can probably be replaced by a helper that sets up an apps.json file in // the right place on the afero memfs instance - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertCalled(t, "AppsAuthExternalStart", mock.Anything, mock.Anything, fakeAppID, "provider_a") clientsMock.Browser.AssertCalled(t, "OpenURL", "https://authorizationurl3.com/provider") }, @@ -241,10 +241,10 @@ func TestExternalAuthAddCommand(t *testing.T) { clientsMock.AddDefaultMocks() // TODO this can probably be replaced by a helper that sets up an apps.json file in // the right place on the afero memfs instance - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertNotCalled(t, "AppsAuthExternalStart") clientsMock.Browser.AssertNotCalled(t, "OpenURL") }, @@ -261,11 +261,11 @@ func TestExternalAuthAddCommand(t *testing.T) { clientsMock.AddDefaultMocks() // TODO this can probably be replaced by a helper that sets up an apps.json file in // the right place on the afero memfs instance - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, ExpectedErrorStrings: []string{"test error"}, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertNotCalled(t, "AppsAuthExternalStart", mock.Anything, mock.Anything, fakeAppID, "provider_a") clientsMock.Browser.AssertNotCalled(t, "OpenURL") }, diff --git a/cmd/externalauth/remove_test.go b/cmd/externalauth/remove_test.go index 85ca6210..6d891aa6 100644 --- a/cmd/externalauth/remove_test.go +++ b/cmd/externalauth/remove_test.go @@ -157,10 +157,10 @@ func TestExternalAuthRemoveCommand(t *testing.T) { clientsMock.AddDefaultMocks() // TODO this can probably be replaced by a helper that sets up an apps.json file in // the right place on the afero memfs instance - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertCalled(t, "AppsAuthExternalDelete", mock.Anything, mock.Anything, fakeAppID, "provider_a", "") }, }, @@ -182,10 +182,10 @@ func TestExternalAuthRemoveCommand(t *testing.T) { clientsMock.ApiInterface.On("AppsAuthExternalDelete", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) clientsMock.AddDefaultMocks() clientsMock.IO.On("ConfirmPrompt", mock.Anything, "Are you sure you want to remove all tokens for this app relevant to the specified provider from your current team/org?", mock.Anything).Return(true) - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertCalled(t, "AppsAuthExternalDelete", mock.Anything, mock.Anything, fakeAppID, "provider_a", "") }, }, @@ -206,11 +206,11 @@ func TestExternalAuthRemoveCommand(t *testing.T) { }}, nil) clientsMock.ApiInterface.On("AppsAuthExternalDelete", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) clientsMock.AddDefaultMocks() - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") clientsMock.IO.On("ConfirmPrompt", mock.Anything, "Are you sure you want to remove all tokens for this app from your current team/org?", mock.Anything).Return(true) }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertCalled(t, "AppsAuthExternalDelete", mock.Anything, mock.Anything, fakeAppID, "", "") }, }, @@ -231,12 +231,12 @@ func TestExternalAuthRemoveCommand(t *testing.T) { }}, nil) clientsMock.ApiInterface.On("AppsAuthExternalDelete", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) clientsMock.AddDefaultMocks() - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") clientsMock.IO.On("ConfirmPrompt", mock.Anything, "Are you sure you want to remove all tokens for this app relevant to the specified provider from your current team/org?", mock.Anything).Return(true) }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertCalled(t, "AppsAuthExternalDelete", mock.Anything, mock.Anything, fakeAppID, "provider_a", "") }, }, @@ -249,11 +249,11 @@ func TestExternalAuthRemoveCommand(t *testing.T) { Authorizations: []types.ExternalAuthorizationInfo{}}, errors.New("test error")) clientsMock.ApiInterface.On("AppsAuthExternalDelete", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) clientsMock.AddDefaultMocks() - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") clientsMock.IO.On("ConfirmPrompt", mock.Anything, "Are you sure you want to remove all tokens for this app from your current team/org?", mock.Anything).Return(true) }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertCalled(t, "AppsAuthExternalDelete", mock.Anything, mock.Anything, fakeAppID, "", "") }, }, diff --git a/cmd/externalauth/select_auth_test.go b/cmd/externalauth/select_auth_test.go index 9a5ff9a9..2bd276a7 100644 --- a/cmd/externalauth/select_auth_test.go +++ b/cmd/externalauth/select_auth_test.go @@ -248,7 +248,7 @@ func TestExternalAuthSelectAuthCommand(t *testing.T) { Return(types.ExternalAuthorizationInfoLists{}, errors.New("test error")) }, ExpectedErrorStrings: []string{"test error"}, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertNotCalled(t, "AppsAuthExternalSelectAuth", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything) }, }, @@ -263,7 +263,7 @@ func TestExternalAuthSelectAuthCommand(t *testing.T) { })).Return(iostreams.SelectPromptResponse{}, slackerror.New(slackerror.ErrMissingOptions)) }, ExpectedErrorStrings: []string{"No workflows found that require developer authorization"}, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertNotCalled(t, "AppsAuthExternalSelectAuth", mock.Anything, mock.Anything, fakeAppID, mock.Anything, mock.Anything) }, }, @@ -281,7 +281,7 @@ func TestExternalAuthSelectAuthCommand(t *testing.T) { }, nil) }, ExpectedErrorStrings: []string{"Workflow not found"}, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertNotCalled(t, "AppsAuthExternalSelectAuth", mock.Anything, mock.Anything, fakeAppID, mock.Anything, mock.Anything, mock.Anything) }, }, @@ -296,7 +296,7 @@ func TestExternalAuthSelectAuthCommand(t *testing.T) { })).Return(iostreams.SelectPromptResponse{}, slackerror.New(slackerror.ErrMissingOptions)) }, ExpectedErrorStrings: []string{"No workflows found that require developer authorization"}, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertNotCalled(t, "AppsAuthExternalSelectAuth", mock.Anything, mock.Anything, fakeAppID, mock.Anything, mock.Anything, mock.Anything) }, }, @@ -314,7 +314,7 @@ func TestExternalAuthSelectAuthCommand(t *testing.T) { }, nil) }, ExpectedErrorStrings: []string{"Workflow not found"}, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertNotCalled(t, "AppsAuthExternalSelectAuth", mock.Anything, mock.Anything, fakeAppID, mock.Anything, mock.Anything, mock.Anything) }, }, @@ -340,7 +340,7 @@ func TestExternalAuthSelectAuthCommand(t *testing.T) { }, nil) }, ExpectedErrorStrings: []string{"No connected accounts found"}, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertNotCalled(t, "AppsAuthExternalSelectAuth", mock.Anything, mock.Anything, fakeAppID, mock.Anything, mock.Anything, mock.Anything) }, }, @@ -372,7 +372,7 @@ func TestExternalAuthSelectAuthCommand(t *testing.T) { }, nil) }, ExpectedErrorStrings: []string{"Workflow not found"}, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertNotCalled(t, "AppsAuthExternalSelectAuth", mock.Anything, mock.Anything, fakeAppID, mock.Anything, mock.Anything, mock.Anything) }, }, @@ -397,7 +397,7 @@ func TestExternalAuthSelectAuthCommand(t *testing.T) { }, nil) }, ExpectedErrorStrings: []string{"No connected accounts found"}, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertNotCalled(t, "AppsAuthExternalSelectAuth", mock.Anything, mock.Anything, fakeAppID, mock.Anything, mock.Anything, mock.Anything) }, }, @@ -421,7 +421,7 @@ func TestExternalAuthSelectAuthCommand(t *testing.T) { }, nil) }, ExpectedErrorStrings: []string{"Provider is not used in the selected workflow"}, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertNotCalled(t, "AppsAuthExternalSelectAuth", mock.Anything, mock.Anything, fakeAppID, mock.Anything, mock.Anything, mock.Anything) }, }, @@ -447,7 +447,7 @@ func TestExternalAuthSelectAuthCommand(t *testing.T) { }, nil) }, ExpectedErrorStrings: []string{"No connected accounts found"}, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertNotCalled(t, "AppsAuthExternalSelectAuth", mock.Anything, mock.Anything, fakeAppID, mock.Anything, mock.Anything, mock.Anything) }, }, @@ -479,7 +479,7 @@ func TestExternalAuthSelectAuthCommand(t *testing.T) { }, nil) }, ExpectedOutputs: []string{"Workflow #/workflows/my_callback_id2 will use developer account xyz2@salesforce.com when making calls to provider_a APIs"}, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertCalled(t, "AppsAuthExternalSelectAuth", mock.Anything, mock.Anything, fakeAppID, mock.Anything, mock.Anything, mock.Anything) }, }, @@ -510,7 +510,7 @@ func TestExternalAuthSelectAuthCommand(t *testing.T) { }, nil) }, ExpectedErrorStrings: []string{"Account is not used in the selected workflow"}, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertNotCalled(t, "AppsAuthExternalSelectAuth", mock.Anything, mock.Anything, fakeAppID, mock.Anything, mock.Anything, mock.Anything) }, }, @@ -541,7 +541,7 @@ func TestExternalAuthSelectAuthCommand(t *testing.T) { }, nil) }, ExpectedOutputs: []string{"Workflow #/workflows/my_callback_id2 will use developer account xyz2@salesforce.com when making calls to provider_a APIs"}, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertCalled(t, "AppsAuthExternalSelectAuth", mock.Anything, mock.Anything, fakeAppID, mock.Anything, mock.Anything, mock.Anything) }, }}, func(clients *shared.ClientFactory) *cobra.Command { diff --git a/cmd/function/access_test.go b/cmd/function/access_test.go index 1ffd6947..d5021f1b 100644 --- a/cmd/function/access_test.go +++ b/cmd/function/access_test.go @@ -49,7 +49,7 @@ func TestFunctionDistributionCommand(t *testing.T) { clientsMock.AddDefaultMocks() appSelectTeardown = setupMockAppSelection(installedProdApp) - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, Teardown: func() { @@ -81,7 +81,7 @@ func TestFunctionDistributionCommand(t *testing.T) { clientsMock.AddDefaultMocks() appSelectTeardown = setupMockAppSelection(installedProdApp) - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, Teardown: func() { @@ -109,7 +109,7 @@ func TestFunctionDistributionCommand(t *testing.T) { clientsMock.AddDefaultMocks() appSelectTeardown = setupMockAppSelection(installedProdApp) - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, Teardown: func() { @@ -129,10 +129,10 @@ func TestFunctionDistributionCommand(t *testing.T) { clientsMock.AddDefaultMocks() appSelectTeardown = setupMockAppSelection(installedProdApp) - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { cm.ApiInterface.AssertNotCalled(t, "FunctionDistributionAddUsers") cm.ApiInterface.AssertNotCalled(t, "FunctionDistributionRemoveUsers") cm.ApiInterface.AssertNotCalled(t, "FunctionDistributionSet") @@ -146,7 +146,7 @@ func TestFunctionDistributionCommand(t *testing.T) { Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.AddDefaultMocks() appSelectTeardown = setupMockAppSelection(installedProdApp) - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, ExpectedErrorStrings: []string{"file does not exist"}, diff --git a/cmd/manifest/info_test.go b/cmd/manifest/info_test.go index 70e730ef..48903f0d 100644 --- a/cmd/manifest/info_test.go +++ b/cmd/manifest/info_test.go @@ -71,7 +71,7 @@ func TestInfoCommand(t *testing.T) { cf.AppClient().Manifest = manifestMock cf.SDKConfig = hooks.NewSDKConfigMock() }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { mockManifest := types.AppManifest{ DisplayInformation: types.DisplayInformation{ Name: "app001", @@ -102,7 +102,7 @@ func TestInfoCommand(t *testing.T) { cf.AppClient().Manifest = manifestMock cf.SDKConfig = hooks.NewSDKConfigMock() }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { mockManifest := types.AppManifest{ DisplayInformation: types.DisplayInformation{ Name: "app002", @@ -139,7 +139,7 @@ func TestInfoCommand(t *testing.T) { mockProjectConfig.On("GetManifestSource", mock.Anything).Return(config.MANIFEST_SOURCE_LOCAL, nil) cm.Config.ProjectConfig = mockProjectConfig }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { mockManifest := types.AppManifest{ DisplayInformation: types.DisplayInformation{ Name: "app002", diff --git a/cmd/manifest/manifest_test.go b/cmd/manifest/manifest_test.go index 8c868308..75a30488 100644 --- a/cmd/manifest/manifest_test.go +++ b/cmd/manifest/manifest_test.go @@ -54,7 +54,7 @@ func TestManifestCommand(t *testing.T) { cf.AppClient().Manifest = manifestMock cf.SDKConfig = hooks.NewSDKConfigMock() }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { mockManifest := types.AppManifest{ DisplayInformation: types.DisplayInformation{ Name: "app001", diff --git a/cmd/openformresponse/export_test.go b/cmd/openformresponse/export_test.go index 58c6dfcb..1eb762c5 100644 --- a/cmd/openformresponse/export_test.go +++ b/cmd/openformresponse/export_test.go @@ -54,7 +54,7 @@ func TestExportCommand(t *testing.T) { Teardown: func() { appSelectTeardown() }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { cm.ApiInterface.AssertCalled(t, "StepsResponsesExport", mock.Anything, token, "#/workflows/my_workflow", appId, "stepId") }, }, @@ -68,7 +68,7 @@ func TestExportCommand(t *testing.T) { Teardown: func() { appSelectTeardown() }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { cm.ApiInterface.AssertCalled(t, "StepsResponsesExport", mock.Anything, token, "#/workflows/my_workflow", appId, "stepId") }, }, diff --git a/cmd/project/init_test.go b/cmd/project/init_test.go index 530c568c..381696b0 100644 --- a/cmd/project/init_test.go +++ b/cmd/project/init_test.go @@ -72,7 +72,7 @@ func Test_Project_InitCommand(t *testing.T) { "App Link", // Assert section header "Next steps to begin development", // Assert section header }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { // Assert installing project dependencies output := cm.GetCombinedOutput() require.Contains(t, output, "Installed project dependencies") @@ -161,7 +161,7 @@ func Test_Project_InitCommand(t *testing.T) { "App Link", // Assert section header "Next steps to begin development", // Assert section header }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { // Assert prompt to add existing apps was called cm.IO.AssertCalled(t, "ConfirmPrompt", mock.Anything, @@ -207,7 +207,7 @@ func Test_Project_InitCommand(t *testing.T) { UserID: mockLinkSlackAuth2.UserID, } actualApp, err := cm.AppClient.GetLocal( - context.Background(), + ctx, mockLinkSlackAuth2.TeamID, ) require.NoError(t, err) diff --git a/cmd/project/samples_test.go b/cmd/project/samples_test.go index 2ec13757..0bc7e96d 100644 --- a/cmd/project/samples_test.go +++ b/cmd/project/samples_test.go @@ -67,7 +67,7 @@ func TestSamplesCommand(t *testing.T) { return "", nil } }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { for _, call := range cm.IO.Calls { switch call.Method { case "SelectPrompt": diff --git a/cmd/triggers/access_test.go b/cmd/triggers/access_test.go index 9f8c6f12..ae1aa9fc 100644 --- a/cmd/triggers/access_test.go +++ b/cmd/triggers/access_test.go @@ -55,7 +55,7 @@ func TestTriggersAccessCommand(t *testing.T) { Return(&types.UserInfo{}, nil).Once() clientsMock.AddDefaultMocks() - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, Teardown: func() { @@ -85,7 +85,7 @@ func TestTriggersAccessCommand(t *testing.T) { Return(types.EVERYONE, []string{}, nil).Once() clientsMock.AddDefaultMocks() - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, Teardown: func() { @@ -115,7 +115,7 @@ func TestTriggersAccessCommand(t *testing.T) { Return(types.EVERYONE, []string{}, nil).Once() clientsMock.AddDefaultMocks() - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, Teardown: func() { @@ -147,7 +147,7 @@ func TestTriggersAccessCommand(t *testing.T) { Return(&types.UserInfo{RealName: "User Two", Name: "USER2", Profile: user2Profile}, nil).Once() clientsMock.AddDefaultMocks() - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, Teardown: func() { @@ -179,7 +179,7 @@ func TestTriggersAccessCommand(t *testing.T) { Return(&types.ChannelInfo{ID: "CHANNEL2", Name: "Channel Two"}, nil).Once() clientsMock.AddDefaultMocks() - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, Teardown: func() { @@ -216,7 +216,7 @@ func TestTriggersAccessCommand(t *testing.T) { clientsMock.ApiInterface.On("ListCollaborators", mock.Anything, mock.Anything, mock.Anything).Return([]types.SlackUser{}, nil) clientsMock.AddDefaultMocks() - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, Teardown: func() { @@ -251,7 +251,7 @@ func TestTriggersAccessCommand(t *testing.T) { clientsMock.ApiInterface.On("ListCollaborators", mock.Anything, mock.Anything, mock.Anything).Return([]types.SlackUser{}, nil) clientsMock.AddDefaultMocks() - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, Teardown: func() { @@ -302,7 +302,7 @@ func TestTriggersAccessCommand(t *testing.T) { clientsMock.ApiInterface.On("ListCollaborators", mock.Anything, mock.Anything, mock.Anything).Return([]types.SlackUser{}, nil) clientsMock.AddDefaultMocks() - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, Teardown: func() { @@ -333,7 +333,7 @@ func TestTriggersAccessCommand(t *testing.T) { Return(&types.UserInfo{RealName: "User Two", Name: "USER2", Profile: user2Profile}, nil).Once() clientsMock.AddDefaultMocks() - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, Teardown: func() { @@ -365,7 +365,7 @@ func TestTriggersAccessCommand(t *testing.T) { Return(&types.ChannelInfo{ID: "CHANNEL2", Name: "Channel Two"}, nil).Once() clientsMock.AddDefaultMocks() - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, Teardown: func() { @@ -407,7 +407,7 @@ func TestTriggersAccessCommand(t *testing.T) { Return(&types.TeamInfo{ID: "TEAM1", Name: "Team One"}, nil).Once() clientsMock.AddDefaultMocks() - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, Teardown: func() { @@ -437,7 +437,7 @@ func TestTriggersAccessCommand(t *testing.T) { Return(&types.UserInfo{RealName: "User One", Name: "USER1", Profile: user1Profile}, nil).Once() clientsMock.AddDefaultMocks() - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, Teardown: func() { @@ -464,7 +464,7 @@ func TestTriggersAccessCommand(t *testing.T) { Return(&types.ChannelInfo{ID: "CHANNEL1", Name: "Channel One"}, nil).Once() clientsMock.AddDefaultMocks() - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, Teardown: func() { @@ -492,7 +492,7 @@ func TestTriggersAccessCommand(t *testing.T) { Return(&types.TeamInfo{ID: "TEAM1", Name: "Team One"}, nil).Once() clientsMock.AddDefaultMocks() - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, Teardown: func() { @@ -523,7 +523,7 @@ func TestTriggersAccessCommand(t *testing.T) { // display channel info for updated access clientsMock.ApiInterface.On("ChannelsInfo", mock.Anything, mock.Anything, "CHANNEL1"). Return(&types.ChannelInfo{ID: "CHANNEL1", Name: "Channel One"}, nil).Once() - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, Teardown: func() { @@ -558,7 +558,7 @@ func TestTriggersAccessCommand(t *testing.T) { }, nil) clientsMock.AddDefaultMocks() - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, Teardown: func() { @@ -580,7 +580,7 @@ func TestTriggersAccessCommand_AppSelection(t *testing.T) { ExpectedErrorStrings: []string{cmdutil.DeployedAppNotInstalledMsg}, Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.AddDefaultMocks() - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") appSelectTeardown = setupMockAccessAppSelection( prompts.SelectedApp{Auth: types.SlackAuth{}, App: types.App{}}, diff --git a/cmd/triggers/create_test.go b/cmd/triggers/create_test.go index 2733a98f..23dbc16b 100644 --- a/cmd/triggers/create_test.go +++ b/cmd/triggers/create_test.go @@ -69,13 +69,13 @@ func TestTriggersCreateCommand(t *testing.T) { clientsMock.AddDefaultMocks() // TODO this can probably be replaced by a helper that sets up an apps.json file in // the right place on the afero memfs instance - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, Teardown: func() { appSelectTeardown() }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { expectedTriggerRequest := api.TriggerRequest{ Type: types.TriggerTypeShortcut, Shortcut: &api.Shortcut{}, @@ -100,13 +100,13 @@ func TestTriggersCreateCommand(t *testing.T) { Return(types.EVERYONE, []string{}, nil).Once() // TODO: testing chicken and egg: we need the default mocks in place before we can use any of the `clients` methods clientsMock.AddDefaultMocks() - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, Teardown: func() { appSelectTeardown() }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { expectedTriggerRequest := api.TriggerRequest{ Type: types.TriggerTypeShortcut, Name: "unit tests", @@ -131,13 +131,13 @@ func TestTriggersCreateCommand(t *testing.T) { Return(types.EVERYONE, []string{}, nil).Once() // TODO: testing chicken and egg: we need the default mocks in place before we can use any of the `clients` methods clientsMock.AddDefaultMocks() - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, Teardown: func() { appSelectTeardown() }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { expectedTriggerRequest := api.TriggerRequest{ Type: types.TriggerTypeShortcut, Name: "unit tests", @@ -167,13 +167,13 @@ func TestTriggersCreateCommand(t *testing.T) { Return(types.EVERYONE, []string{}, nil).Once() // TODO: testing chicken and egg: we need the default mocks in place before we can use any of the `clients` methods clientsMock.AddDefaultMocks() - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, Teardown: func() { appSelectTeardown() }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { expectedTriggerRequest := api.TriggerRequest{ Type: types.TriggerTypeShortcut, Name: "unit tests", @@ -199,7 +199,7 @@ func TestTriggersCreateCommand(t *testing.T) { clientsMock.ApiInterface.On("WorkflowsTriggersCreate", mock.Anything, mock.Anything, mock.Anything).Return(types.DeployedTrigger{}, errors.New("invalid_auth")) // TODO: testing chicken and egg: we need the default mocks in place before we can use any of the `clients` methods clientsMock.AddDefaultMocks() - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, Teardown: func() { @@ -220,7 +220,7 @@ func TestTriggersCreateCommand(t *testing.T) { Return(types.EVERYONE, []string{}, nil).Once() // TODO: testing chicken and egg: we need the default mocks in place before we can use any of the `clients` methods clientsMock.AddDefaultMocks() - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") jsonPayload := `{ "type":"scheduled", @@ -236,7 +236,7 @@ func TestTriggersCreateCommand(t *testing.T) { Teardown: func() { appSelectTeardown() }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { expectedTriggerRequest := api.TriggerRequest{ Type: types.TriggerTypeScheduled, Name: "name", @@ -256,7 +256,7 @@ func TestTriggersCreateCommand(t *testing.T) { // TODO: testing chicken and egg: we need the default mocks in place before we can use any of the `clients` methods clientsMock.AddDefaultMocks() clientsMock.HookExecutor.On("Execute", mock.Anything).Return("", nil) - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, Teardown: func() { @@ -275,7 +275,7 @@ func TestTriggersCreateCommand(t *testing.T) { // TODO: testing chicken and egg: we need the default mocks in place before we can use any of the `clients` methods clientsMock.AddDefaultMocks() clientsMock.HookExecutor.On("Execute", mock.Anything).Return(`{}`, nil) - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") var content = `export default {}` err = afero.WriteFile(clients.Fs, "triggers/shortcut.ts", []byte(content), 0600) @@ -285,7 +285,7 @@ func TestTriggersCreateCommand(t *testing.T) { Teardown: func() { appSelectTeardown() }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.HookExecutor.AssertCalled(t, "Execute", mock.Anything) clientsMock.ApiInterface.AssertCalled(t, "WorkflowsTriggersCreate", mock.Anything, mock.Anything, mock.Anything) }, @@ -297,7 +297,7 @@ func TestTriggersCreateCommand(t *testing.T) { appSelectTeardown = setupMockCreateAppSelection(installedProdApp) // TODO: testing chicken and egg: we need the default mocks in place before we can use any of the `clients` methods clientsMock.AddDefaultMocks() - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") var content = `export default {}` err = afero.WriteFile(clients.Fs, "triggers/shortcut.ts", []byte(content), 0600) @@ -307,7 +307,7 @@ func TestTriggersCreateCommand(t *testing.T) { Teardown: func() { appSelectTeardown() }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertNotCalled(t, "WorkflowsTriggersCreate", mock.Anything, mock.Anything, mock.Anything) }, }, @@ -372,10 +372,10 @@ func TestTriggersCreateCommand_MissingParameters(t *testing.T) { Return(types.EVERYONE, []string{}, nil).Once() // TODO: testing chicken and egg: we need the default mocks in place before we can use any of the `clients` methods clientsMock.AddDefaultMocks() - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertCalled(t, "WorkflowsTriggersCreate", mock.Anything, mock.Anything, triggerRequestMissingInputs) clientsMock.ApiInterface.AssertCalled(t, "WorkflowsTriggersCreate", mock.Anything, mock.Anything, triggerRequestWithInteractivityInputs) }, @@ -403,10 +403,10 @@ func TestTriggersCreateCommand_MissingParameters(t *testing.T) { clientsMock.ApiInterface.On("WorkflowsTriggersCreate", mock.Anything, mock.Anything, triggerRequestWithInteractivityInputs).Return(types.DeployedTrigger{}, errors.New("internal_error")).Once() // TODO: testing chicken and egg: we need the default mocks in place before we can use any of the `clients` methods clientsMock.AddDefaultMocks() - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertCalled(t, "WorkflowsTriggersCreate", mock.Anything, mock.Anything, triggerRequestMissingInputs) clientsMock.ApiInterface.AssertCalled(t, "WorkflowsTriggersCreate", mock.Anything, mock.Anything, triggerRequestWithInteractivityInputs) }, @@ -432,10 +432,10 @@ func TestTriggersCreateCommand_MissingParameters(t *testing.T) { clientsMock.ApiInterface.On("WorkflowsTriggersCreate", mock.Anything, mock.Anything, mock.Anything).Return(types.DeployedTrigger{}, extendedErr) // TODO: testing chicken and egg: we need the default mocks in place before we can use any of the `clients` methods clientsMock.AddDefaultMocks() - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertCalled(t, "WorkflowsTriggersCreate", mock.Anything, mock.Anything, mock.Anything) }, Teardown: func() { @@ -489,7 +489,7 @@ func TestTriggersCreateCommand_AppSelection(t *testing.T) { workspaceInstallAppFunc = originalWorkspaceInstallAppFunc } appCommandMock.On("RunAddCommand", mock.Anything, mock.Anything, mock.Anything, mock.Anything). - Return(context.Background(), types.SUCCESS, newDevApp.App, nil) + Return(ctx, types.SUCCESS, newDevApp.App, nil) clientsMock.ApiInterface.On("WorkflowsTriggersCreate", mock.Anything, mock.Anything, mock.Anything). Return(types.DeployedTrigger{}, nil) // Define default mocks @@ -499,7 +499,7 @@ func TestTriggersCreateCommand_AppSelection(t *testing.T) { appSelectTeardown() workspaceInstallAppTeardown() }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { appCommandMock.AssertCalled(t, "RunAddCommand", mock.Anything, mock.Anything, &newDevApp, mock.Anything) clientsMock.ApiInterface.AssertCalled(t, "WorkflowsTriggersCreate", mock.Anything, mock.Anything, mock.Anything) }, @@ -517,7 +517,7 @@ func TestTriggersCreateCommand_AppSelection(t *testing.T) { workspaceInstallAppFunc = originalWorkspaceInstallAppFunc } appCommandMock.On("RunAddCommand", mock.Anything, mock.Anything, mock.Anything, mock.Anything). - Return(context.Background(), types.SUCCESS, newDevApp.App, nil) + Return(ctx, types.SUCCESS, newDevApp.App, nil) clientsMock.ApiInterface.On("WorkflowsTriggersCreate", mock.Anything, mock.Anything, mock.Anything). Return(types.DeployedTrigger{}, nil) // Define default mocks @@ -527,7 +527,7 @@ func TestTriggersCreateCommand_AppSelection(t *testing.T) { appSelectTeardown() workspaceInstallAppTeardown() }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { appCommandMock.AssertCalled(t, "RunAddCommand", mock.Anything, mock.Anything, &newProdApp, mock.Anything) clientsMock.ApiInterface.AssertCalled(t, "WorkflowsTriggersCreate", mock.Anything, mock.Anything, mock.Anything) }, diff --git a/cmd/triggers/delete_test.go b/cmd/triggers/delete_test.go index 2d637fd3..8b76d2af 100644 --- a/cmd/triggers/delete_test.go +++ b/cmd/triggers/delete_test.go @@ -71,13 +71,13 @@ func TestTriggersDeleteCommand(t *testing.T) { clientsMock.AddDefaultMocks() // TODO this can probably be replaced by a helper that sets up an apps.json file in // the right place on the afero memfs instance - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, Teardown: func() { appSelectTeardown() }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertCalled(t, "WorkflowsTriggersDelete", mock.Anything, mock.Anything, fakeTriggerID) }, }, @@ -89,13 +89,13 @@ func TestTriggersDeleteCommand(t *testing.T) { clientsMock.ApiInterface.On("WorkflowsTriggersDelete", mock.Anything, mock.Anything, mock.Anything).Return(errors.New("invalid_auth")) // TODO: testing chicken and egg: we need the default mocks in place before we can use any of the `clients` methods clientsMock.AddDefaultMocks() - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, Teardown: func() { appSelectTeardown() }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertCalled(t, "WorkflowsTriggersDelete", mock.Anything, mock.Anything, fakeTriggerID) }, }, @@ -130,7 +130,7 @@ func TestTriggersDeleteCommand_AppSelection(t *testing.T) { clientsMock.AddDefaultMocks() // TODO this can probably be replaced by a helper that sets up an apps.json file in // the right place on the afero memfs instance - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") appSelectTeardown = setupMockDeleteAppSelection(newDevApp) @@ -146,7 +146,7 @@ func TestTriggersDeleteCommand_AppSelection(t *testing.T) { clientsMock.AddDefaultMocks() // TODO this can probably be replaced by a helper that sets up an apps.json file in // the right place on the afero memfs instance - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") appSelectTeardown = setupMockDeleteAppSelection(newProdApp) diff --git a/cmd/triggers/info_test.go b/cmd/triggers/info_test.go index c4046e16..6a6901e1 100644 --- a/cmd/triggers/info_test.go +++ b/cmd/triggers/info_test.go @@ -50,7 +50,7 @@ func TestTriggersInfoCommand(t *testing.T) { ExpectedOutputs: []string{ "Trigger Info", }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertCalled(t, "WorkflowsTriggersInfo", mock.Anything, mock.Anything, fakeTriggerID) }, Teardown: func() { @@ -83,13 +83,13 @@ func TestTriggersInfoCommand(t *testing.T) { clientsMock.ApiInterface.On("TriggerPermissionsList", mock.Anything, mock.Anything, mock.Anything). Return(types.EVERYONE, []string{}, nil).Once() clientsMock.AddDefaultMocks() - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, Teardown: func() { appSelectTeardown() }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertCalled(t, "WorkflowsTriggersInfo", mock.Anything, mock.Anything, fakeTriggerID) }, }, @@ -108,13 +108,13 @@ func TestTriggersInfoCommand(t *testing.T) { clientsMock.ApiInterface.On("TriggerPermissionsList", mock.Anything, mock.Anything, mock.Anything). Return(types.EVERYONE, []string{}, nil).Once() clientsMock.AddDefaultMocks() - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, Teardown: func() { appSelectTeardown() }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertCalled(t, "WorkflowsTriggersInfo", mock.Anything, mock.Anything, fakeTriggerID) }, }, @@ -126,13 +126,13 @@ func TestTriggersInfoCommand(t *testing.T) { clientsMock.ApiInterface.On("WorkflowsTriggersInfo", mock.Anything, mock.Anything, mock.Anything).Return(types.DeployedTrigger{}, errors.New("invalid_auth")) // TODO: testing chicken and egg: we need the default mocks in place before we can use any of the `clients` methods clientsMock.AddDefaultMocks() - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, Teardown: func() { appSelectTeardown() }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertCalled(t, "WorkflowsTriggersInfo", mock.Anything, mock.Anything, fakeTriggerID) }, }, @@ -146,7 +146,7 @@ func TestTriggersInfoCommand(t *testing.T) { clientsMock.ApiInterface.On("TriggerPermissionsList", mock.Anything, mock.Anything, mock.Anything). Return(types.EVERYONE, []string{}, nil).Once() clientsMock.AddDefaultMocks() - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, Teardown: func() { @@ -158,7 +158,7 @@ func TestTriggersInfoCommand(t *testing.T) { "Hint:\n", "Warning:\n", }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertCalled(t, "WorkflowsTriggersInfo", mock.Anything, mock.Anything, fakeTriggerID) }, }, @@ -197,7 +197,7 @@ func TestTriggersInfoCommand_AppSelection(t *testing.T) { clientsMock.AddDefaultMocks() // TODO this can probably be replaced by a helper that sets up an apps.json file in // the right place on the afero memfs instance - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") appSelectTeardown = setupMockInfoAppSelection(newDevApp) @@ -213,7 +213,7 @@ func TestTriggersInfoCommand_AppSelection(t *testing.T) { clientsMock.AddDefaultMocks() // TODO this can probably be replaced by a helper that sets up an apps.json file in // the right place on the afero memfs instance - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") appSelectTeardown = setupMockInfoAppSelection(newProdApp) diff --git a/cmd/triggers/list_test.go b/cmd/triggers/list_test.go index 96be2299..236d2324 100644 --- a/cmd/triggers/list_test.go +++ b/cmd/triggers/list_test.go @@ -56,7 +56,7 @@ func TestTriggersListCommand(t *testing.T) { "Listing triggers installed to the app...", "There are no triggers installed for the app", }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertCalled(t, "WorkflowsTriggersList", mock.Anything, mock.Anything, triggerListRequestArgs) }, }, @@ -93,7 +93,7 @@ func TestTriggersListCommand(t *testing.T) { fmt.Sprintf("%s %s (%s)", fakeTriggerName, fakeTriggerID, "shortcut"), "everyone in the workspace", }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertCalled(t, "WorkflowsTriggersList", mock.Anything, mock.Anything, triggerListRequestArgs) }, }, @@ -130,7 +130,7 @@ func TestTriggersListCommand(t *testing.T) { fmt.Sprintf("%s %s (%s)", fakeTriggerName, fakeTriggerID, "shortcut"), "everyone in all workspaces in this org granted to this app", }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertCalled(t, "WorkflowsTriggersList", mock.Anything, mock.Anything, triggerListRequestArgs) }, }, @@ -168,7 +168,7 @@ func TestTriggersListCommand(t *testing.T) { fmt.Sprintf("%s %s (%s)", fakeTriggerName, fakeTriggerID, "shortcut"), fmt.Sprintf("Trigger ID: %s (%s)", fakeTriggerID, "scheduled"), }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertCalled(t, "WorkflowsTriggersList", mock.Anything, mock.Anything, triggerListRequestArgs) }, }, diff --git a/cmd/triggers/update_test.go b/cmd/triggers/update_test.go index 3cd0449d..d552bd50 100644 --- a/cmd/triggers/update_test.go +++ b/cmd/triggers/update_test.go @@ -59,7 +59,7 @@ func TestTriggersUpdateCommand(t *testing.T) { Teardown: func() { appSelectTeardown() }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { expectedTriggerRequest := api.TriggerUpdateRequest{ TriggerId: fakeTriggerID, TriggerRequest: api.TriggerRequest{ @@ -79,7 +79,7 @@ func TestTriggersUpdateCommand(t *testing.T) { clientsMock.AddDefaultMocks() // TODO this can probably be replaced by a helper that sets up an apps.json file in // the right place on the afero memfs instance - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") appSelectTeardown = setupMockUpdateAppSelection(newProdApp) @@ -95,7 +95,7 @@ func TestTriggersUpdateCommand(t *testing.T) { clientsMock.AddDefaultMocks() // TODO this can probably be replaced by a helper that sets up an apps.json file in // the right place on the afero memfs instance - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") appSelectTeardown = setupMockUpdateAppSelection(newDevApp) @@ -119,13 +119,13 @@ func TestTriggersUpdateCommand(t *testing.T) { clientsMock.AddDefaultMocks() // TODO this can probably be replaced by a helper that sets up an apps.json file in // the right place on the afero memfs instance - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, Teardown: func() { appSelectTeardown() }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { expectedTriggerRequest := api.TriggerUpdateRequest{ TriggerId: fakeTriggerID, TriggerRequest: api.TriggerRequest{ @@ -155,13 +155,13 @@ func TestTriggersUpdateCommand(t *testing.T) { clientsMock.AddDefaultMocks() // TODO this can probably be replaced by a helper that sets up an apps.json file in // the right place on the afero memfs instance - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, Teardown: func() { appSelectTeardown() }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { expectedTriggerRequest := api.TriggerUpdateRequest{ TriggerId: fakeTriggerID, TriggerRequest: api.TriggerRequest{ @@ -196,13 +196,13 @@ func TestTriggersUpdateCommand(t *testing.T) { clientsMock.AddDefaultMocks() // TODO this can probably be replaced by a helper that sets up an apps.json file in // the right place on the afero memfs instance - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, Teardown: func() { appSelectTeardown() }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { expectedTriggerRequest := api.TriggerUpdateRequest{ TriggerId: fakeTriggerID, TriggerRequest: api.TriggerRequest{ @@ -235,13 +235,13 @@ func TestTriggersUpdateCommand(t *testing.T) { Return(types.EVERYONE, []string{}, nil).Once() // TODO: testing chicken and egg: we need the default mocks in place before we can use any of the `clients` methods clientsMock.AddDefaultMocks() - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, Teardown: func() { appSelectTeardown() }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { expectedTriggerRequest := api.TriggerUpdateRequest{ TriggerId: fakeTriggerID, TriggerRequest: api.TriggerRequest{ @@ -264,7 +264,7 @@ func TestTriggersUpdateCommand(t *testing.T) { clientsMock.ApiInterface.On("WorkflowsTriggersUpdate", mock.Anything, mock.Anything, mock.Anything).Return(types.DeployedTrigger{}, errors.New("invalid_auth")) // TODO: testing chicken and egg: we need the default mocks in place before we can use any of the `clients` methods clientsMock.AddDefaultMocks() - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, Teardown: func() { @@ -284,7 +284,7 @@ func TestTriggersUpdateCommand(t *testing.T) { Return(types.EVERYONE, []string{}, nil).Once() // TODO: testing chicken and egg: we need the default mocks in place before we can use any of the `clients` methods clientsMock.AddDefaultMocks() - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") jsonPayload := `{ "type":"scheduled", @@ -300,7 +300,7 @@ func TestTriggersUpdateCommand(t *testing.T) { Teardown: func() { appSelectTeardown() }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { expectedTriggerRequest := api.TriggerUpdateRequest{ TriggerId: fakeTriggerID, TriggerRequest: api.TriggerRequest{ @@ -322,7 +322,7 @@ func TestTriggersUpdateCommand(t *testing.T) { appSelectTeardown = setupMockUpdateAppSelection(installedProdApp) // TODO: testing chicken and egg: we need the default mocks in place before we can use any of the `clients` methods clientsMock.AddDefaultMocks() - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, Teardown: func() { @@ -341,7 +341,7 @@ func TestTriggersUpdateCommand(t *testing.T) { // TODO: testing chicken and egg: we need the default mocks in place before we can use any of the `clients` methods clientsMock.AddDefaultMocks() clientsMock.HookExecutor.On("Execute", mock.Anything).Return(`{`, nil) - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") var content = `export default {}` err = afero.WriteFile(clients.Fs, "triggers/shortcut.ts", []byte(content), 0600) @@ -353,7 +353,7 @@ func TestTriggersUpdateCommand(t *testing.T) { appSelectTeardown() }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.HookExecutor.AssertCalled(t, "Execute", mock.Anything) }, }, @@ -424,14 +424,14 @@ func TestTriggersUpdateCommand_MissingParameters(t *testing.T) { Return(types.EVERYONE, []string{}, nil).Once() // TODO: testing chicken and egg: we need the default mocks in place before we can use any of the `clients` methods clientsMock.AddDefaultMocks() - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, Teardown: func() { appSelectTeardown() promptForInteractivityTeardown() }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertCalled(t, "WorkflowsTriggersUpdate", mock.Anything, mock.Anything, triggerRequestMissingInputs) clientsMock.ApiInterface.AssertCalled(t, "WorkflowsTriggersUpdate", mock.Anything, mock.Anything, triggerRequestWithInteractivityInputs) }, @@ -455,14 +455,14 @@ func TestTriggersUpdateCommand_MissingParameters(t *testing.T) { clientsMock.ApiInterface.On("WorkflowsTriggersUpdate", mock.Anything, mock.Anything, triggerRequestWithInteractivityInputs).Return(types.DeployedTrigger{}, errors.New("internal_error")) // TODO: testing chicken and egg: we need the default mocks in place before we can use any of the `clients` methods clientsMock.AddDefaultMocks() - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, Teardown: func() { appSelectTeardown() promptForInteractivityTeardown() }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertCalled(t, "WorkflowsTriggersUpdate", mock.Anything, mock.Anything, triggerRequestMissingInputs) clientsMock.ApiInterface.AssertCalled(t, "WorkflowsTriggersUpdate", mock.Anything, mock.Anything, triggerRequestWithInteractivityInputs) }, @@ -484,14 +484,14 @@ func TestTriggersUpdateCommand_MissingParameters(t *testing.T) { clientsMock.ApiInterface.On("WorkflowsTriggersUpdate", mock.Anything, mock.Anything, mock.Anything).Return(types.DeployedTrigger{}, extendedErr) // TODO: testing chicken and egg: we need the default mocks in place before we can use any of the `clients` methods clientsMock.AddDefaultMocks() - err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) + err := clients.AppClient().SaveDeployed(ctx, fakeApp) require.NoError(t, err, "Cant write apps.json") }, Teardown: func() { appSelectTeardown() promptForInteractivityTeardown() }, - ExpectedAsserts: func(t *testing.T, clientsMock *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { clientsMock.ApiInterface.AssertCalled(t, "WorkflowsTriggersUpdate", mock.Anything, mock.Anything, mock.Anything) }, }, diff --git a/internal/pkg/platform/activity_test.go b/internal/pkg/platform/activity_test.go index ea312a54..1a721e47 100644 --- a/internal/pkg/platform/activity_test.go +++ b/internal/pkg/platform/activity_test.go @@ -24,6 +24,7 @@ import ( "github.com/slackapi/slack-cli/internal/logger" "github.com/slackapi/slack-cli/internal/shared" "github.com/slackapi/slack-cli/internal/shared/types" + "github.com/slackapi/slack-cli/internal/slackcontext" "github.com/slackapi/slack-cli/internal/slackerror" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" @@ -97,8 +98,8 @@ func TestPlatformActivity_StreamingLogs(t *testing.T) { for name, tt := range map[string]struct { Setup func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) context.Context Args types.ActivityArgs - ExpectedAsserts func(*testing.T, *shared.ClientsMock) // Optional - ExpectedError error // Optional + ExpectedAsserts func(*testing.T, context.Context, *shared.ClientsMock) // Optional + ExpectedError error // Optional }{ "should return error if context contains no token": { Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) context.Context { @@ -129,7 +130,7 @@ func TestPlatformActivity_StreamingLogs(t *testing.T) { cm.ApiInterface.On("Activity", mock.Anything, mock.Anything, mock.Anything).Return(api.ActivityResult{}, nil) return ctx }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { cm.ApiInterface.AssertNumberOfCalls(t, "Activity", 1) }, }, @@ -147,29 +148,29 @@ func TestPlatformActivity_StreamingLogs(t *testing.T) { }() return ctx }, - ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { // with the above polling/canceling setup, expectation is activity called only once. cm.ApiInterface.AssertNumberOfCalls(t, "Activity", 1) }, }, } { t.Run(name, func(t *testing.T) { - ctx := context.Background() - ctx = context.WithValue(ctx, config.CONTEXT_TOKEN, "sometoken") // Create mocks + ctxMock := slackcontext.MockContext(context.Background()) + ctxMock = context.WithValue(ctxMock, config.CONTEXT_TOKEN, "sometoken") clientsMock := shared.NewClientsMock() // Create clients that is mocked for testing clients := shared.NewClientFactory(clientsMock.MockClientFactory()) // Setup custom per-test mocks (higher priority than default mocks) if tt.Setup != nil { - ctx = tt.Setup(t, ctx, clientsMock) + ctxMock = tt.Setup(t, ctxMock, clientsMock) } // Setup generic test suite mocks clientsMock.ApiInterface.On("ValidateSession", mock.Anything, mock.Anything).Return(api.AuthSession{}, nil) // Setup default mock actions clientsMock.AddDefaultMocks() - err := Activity(ctx, clients, &logger.Logger{}, tt.Args) + err := Activity(ctxMock, clients, &logger.Logger{}, tt.Args) if tt.ExpectedError != nil { assert.Contains(t, err.Error(), tt.ExpectedError.Error(), err) } else { @@ -177,7 +178,7 @@ func TestPlatformActivity_StreamingLogs(t *testing.T) { } // Assert mocks or other custom assertions if tt.ExpectedAsserts != nil { - tt.ExpectedAsserts(t, clientsMock) + tt.ExpectedAsserts(t, ctxMock, clientsMock) } }) } diff --git a/test/testutil/commandtests.go b/test/testutil/commandtests.go index 4f5f147c..9ee1d320 100644 --- a/test/testutil/commandtests.go +++ b/test/testutil/commandtests.go @@ -34,7 +34,7 @@ type CommandTests map[string]struct { CmdArgs []string // Required, Example: ["my-app", "--template", "slack-samples/deno-starter-template", "--verbose"] ExpectedOutputs []string // Optional ExpectedStdoutOutputs []string // Optional - ExpectedAsserts func(*testing.T, *shared.ClientsMock) // Optional + ExpectedAsserts func(*testing.T, context.Context, *shared.ClientsMock) // Optional ExpectedError error // Optional ExpectedErrorStrings []string // Optional } @@ -105,7 +105,7 @@ func TableTestCommand(t *testing.T, commandTests CommandTests, newCommandFunc fu // Assert mocks or other custom assertions if tt.ExpectedAsserts != nil { - tt.ExpectedAsserts(t, clientsMock) + tt.ExpectedAsserts(t, ctxMock, clientsMock) } if tt.Teardown != nil {