diff --git a/cmd/app/add_test.go b/cmd/app/add_test.go index 4945057c..678a9208 100644 --- a/cmd/app/add_test.go +++ b/cmd/app/add_test.go @@ -76,12 +76,12 @@ func TestAppAddCommandPreRun(t *testing.T) { testutil.TableTestCommand(t, testutil.CommandTests{ "errors if not run in a project directory": { ExpectedError: slackerror.New(slackerror.ErrInvalidAppDirectory), - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { }, }, "proceeds if run in a project directory": { ExpectedError: nil, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { cf.SDKConfig.WorkingDirectory = "." }, }, @@ -100,8 +100,7 @@ func TestAppAddCommandPreRun(t *testing.T) { Message: "Cannot install apps with manifests sourced from app settings", }, }), - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { - ctx := context.Background() + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { cf.SDKConfig.WorkingDirectory = "." cm.AddDefaultMocks() cm.Config.ExperimentsFlag = append(cm.Config.ExperimentsFlag, experiment.BoltFrameworks) @@ -113,8 +112,7 @@ func TestAppAddCommandPreRun(t *testing.T) { }, "proceeds if manifest.source is local with the bolt experiment": { ExpectedError: nil, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { - ctx := context.Background() + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { cf.SDKConfig.WorkingDirectory = "." cm.AddDefaultMocks() cm.Config.ExperimentsFlag = append(cm.Config.ExperimentsFlag, experiment.BoltFrameworks) @@ -137,7 +135,7 @@ func TestAppAddCommand(t *testing.T) { "adds a new deployed app": { CmdArgs: []string{}, ExpectedOutputs: []string{"Creating app manifest", "Installing"}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { prepareAddMocks(t, cf, cm) // Mock TeamSelector prompt to return "team1" @@ -209,7 +207,7 @@ func TestAppAddCommand(t *testing.T) { "updates an existing deployed app": { CmdArgs: []string{}, ExpectedOutputs: []string{"Updated app manifest"}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { prepareAddMocks(t, cf, cm) // Mock TeamSelector prompt to return "team1" @@ -291,7 +289,7 @@ func TestAppAddCommand(t *testing.T) { "errors if authentication for the team is missing": { CmdArgs: []string{}, ExpectedError: slackerror.New(slackerror.ErrCredentialsNotFound), - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { prepareAddMocks(t, cf, cm) appSelectMock := prompts.NewAppSelectMock() teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt @@ -301,7 +299,7 @@ func TestAppAddCommand(t *testing.T) { "adds a new deployed app to an org with a workspace grant": { CmdArgs: []string{"--" + cmdutil.OrgGrantWorkspaceFlag, "T123"}, ExpectedOutputs: []string{"Creating app manifest", "Installing"}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { prepareAddMocks(t, cf, cm) // Select workspace appSelectMock := prompts.NewAppSelectMock() @@ -361,7 +359,7 @@ func TestAppAddCommand(t *testing.T) { "When admin approval request is pending, outputs instructions": { CmdArgs: []string{"--" + cmdutil.OrgGrantWorkspaceFlag, "T123"}, ExpectedOutputs: []string{"Creating app manifest", "Installing", "Your request to install the app is pending", "complete installation by re-running"}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { prepareAddMocks(t, cf, cm) // Select workspace appSelectMock := prompts.NewAppSelectMock() @@ -417,7 +415,7 @@ func TestAppAddCommand(t *testing.T) { "When admin approval request is cancelled, outputs instructions": { CmdArgs: []string{"--" + cmdutil.OrgGrantWorkspaceFlag, "T123"}, ExpectedOutputs: []string{"Creating app manifest", "Installing", "Your request to install the app has been cancelled"}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { prepareAddMocks(t, cf, cm) // Select workspace appSelectMock := prompts.NewAppSelectMock() diff --git a/cmd/app/delete_test.go b/cmd/app/delete_test.go index a7015ce5..1d962c27 100644 --- a/cmd/app/delete_test.go +++ b/cmd/app/delete_test.go @@ -15,6 +15,7 @@ package app import ( + "context" "fmt" "testing" @@ -49,7 +50,7 @@ func TestAppsDeleteCommand(t *testing.T) { testutil.TableTestCommand(t, testutil.CommandTests{ "happy path; delete the deployed app": { CmdArgs: []string{}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { prepareCommonDeleteMocks(t, cf, cm) // Mock App Selection appSelectMock := prompts.NewAppSelectMock() @@ -83,7 +84,7 @@ func TestAppsDeleteCommand(t *testing.T) { }, "happy path; delete the local app": { CmdArgs: []string{}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { prepareCommonDeleteMocks(t, cf, cm) // Mock App Selection appSelectMock := prompts.NewAppSelectMock() @@ -116,7 +117,7 @@ func TestAppsDeleteCommand(t *testing.T) { }, "sad path; deleting the deployed app fails": { CmdArgs: []string{}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { prepareCommonDeleteMocks(t, cf, cm) // Mock App Selection appSelectMock := prompts.NewAppSelectMock() @@ -143,7 +144,7 @@ func TestAppsDeleteCommand(t *testing.T) { "errors if authentication for the team is missing": { CmdArgs: []string{}, ExpectedError: slackerror.New(slackerror.ErrCredentialsNotFound), - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { prepareCommonDeleteMocks(t, cf, cm) cm.ApiInterface.On("ValidateSession", mock.Anything, mock.Anything).Return(api.AuthSession{}, nil) appSelectMock := prompts.NewAppSelectMock() diff --git a/cmd/app/link_test.go b/cmd/app/link_test.go index 6224b0ad..b2fd09f4 100644 --- a/cmd/app/link_test.go +++ b/cmd/app/link_test.go @@ -54,7 +54,7 @@ var mockLinkSlackAuth2 = types.SlackAuth{ func Test_Apps_Link(t *testing.T) { testutil.TableTestCommand(t, testutil.CommandTests{ "saves information about the provided deployed app": { - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { cm.AuthInterface.On("Auths", mock.Anything).Return([]types.SlackAuth{ mockLinkSlackAuth2, mockLinkSlackAuth1, @@ -111,7 +111,7 @@ func Test_Apps_Link(t *testing.T) { }, }, "saves information about the provided local app": { - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { cm.AuthInterface.On("Auths", mock.Anything).Return([]types.SlackAuth{ mockLinkSlackAuth2, mockLinkSlackAuth1, @@ -170,8 +170,7 @@ func Test_Apps_Link(t *testing.T) { }, }, "avoids overwriting an app saved in json without confirmation": { - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { - ctx := context.Background() + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { cm.AuthInterface.On("Auths", mock.Anything).Return([]types.SlackAuth{ mockLinkSlackAuth1, mockLinkSlackAuth2, @@ -240,8 +239,7 @@ func Test_Apps_Link(t *testing.T) { WithRemediation("Remove the app from this project or try again with --force"), }, "avoids overwriting a matching app id for the team without confirmation": { - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { - ctx := context.Background() + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { cm.AuthInterface.On("Auths", mock.Anything).Return([]types.SlackAuth{ mockLinkSlackAuth1, mockLinkSlackAuth2, @@ -316,8 +314,7 @@ func Test_Apps_Link(t *testing.T) { WithRemediation("Remove the app from this project or try again with --force"), }, "completes overwriting an app saved in json with confirmation": { - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { - ctx := context.Background() + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { cm.AuthInterface.On("Auths", mock.Anything).Return([]types.SlackAuth{ mockLinkSlackAuth1, mockLinkSlackAuth2, @@ -385,7 +382,7 @@ func Test_Apps_Link(t *testing.T) { }, }, "refuses to write an app with app id not existing upstream": { - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { cm.AuthInterface.On("Auths", mock.Anything).Return([]types.SlackAuth{ mockLinkSlackAuth1, mockLinkSlackAuth2, @@ -433,7 +430,7 @@ func Test_Apps_Link(t *testing.T) { ExpectedError: slackerror.New(slackerror.ErrAppNotFound), }, "accept manifest source prompt and saves information about the provided deployed app": { - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { cm.AuthInterface.On("Auths", mock.Anything).Return([]types.SlackAuth{ mockLinkSlackAuth2, mockLinkSlackAuth1, @@ -506,7 +503,7 @@ func Test_Apps_Link(t *testing.T) { }, }, "decline manifest source prompt should not link app": { - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { cm.AddDefaultMocks() setupAppLinkCommandMocks(t, cm, cf) // Set manifest source to project to trigger confirmation prompt diff --git a/cmd/app/uninstall_test.go b/cmd/app/uninstall_test.go index 64eb27c6..aeb1181e 100644 --- a/cmd/app/uninstall_test.go +++ b/cmd/app/uninstall_test.go @@ -47,7 +47,7 @@ func TestAppsUninstall(t *testing.T) { testutil.TableTestCommand(t, testutil.CommandTests{ "Successfully uninstall": { - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { prepareCommonUninstallMocks(clients, clientsMock) clientsMock.ApiInterface.On("UninstallApp", mock.Anything, mock.Anything, fakeAppID, fakeAppTeamID). Return(nil).Once() @@ -57,7 +57,7 @@ func TestAppsUninstall(t *testing.T) { }, }, "Successfully uninstall with a get-manifest hook error": { - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { prepareCommonUninstallMocks(clients, clientsMock) clientsMock.ApiInterface.On("UninstallApp", mock.Anything, mock.Anything, fakeAppID, fakeAppTeamID). Return(nil).Once() @@ -72,7 +72,7 @@ func TestAppsUninstall(t *testing.T) { }, "Fail to uninstall due to API error": { ExpectedError: slackerror.New("something went wrong"), - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { prepareCommonUninstallMocks(clients, clientsMock) clientsMock.ApiInterface.On("UninstallApp", mock.Anything, mock.Anything, fakeAppID, fakeAppTeamID). Return(slackerror.New("something went wrong")).Once() @@ -81,7 +81,7 @@ func TestAppsUninstall(t *testing.T) { "errors if authentication for the team is missing": { CmdArgs: []string{}, ExpectedError: slackerror.New(slackerror.ErrCredentialsNotFound), - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { prepareCommonUninstallMocks(cf, cm) appSelectMock := prompts.NewAppSelectMock() uninstallAppSelectPromptFunc = appSelectMock.AppSelectPrompt diff --git a/cmd/auth/login_test.go b/cmd/auth/login_test.go index 33fec190..968e83b5 100644 --- a/cmd/auth/login_test.go +++ b/cmd/auth/login_test.go @@ -15,6 +15,7 @@ package auth import ( + "context" "testing" "github.com/slackapi/slack-cli/internal/api" @@ -52,7 +53,7 @@ func TestLoginCommmand(t *testing.T) { "deprecated auth flag is noted in outputs": { CmdArgs: []string{"--auth", "xoxp-example"}, ExpectedOutputs: []string{deprecatedUserTokenMessage}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { cm.ApiInterface.On("ValidateSession", mock.Anything, mock.Anything).Return(api.AuthSession{ UserID: &mockOrgAuth.UserID, TeamID: &mockOrgAuth.TeamID, @@ -79,7 +80,7 @@ func TestLoginCommmand(t *testing.T) { "suggests creating a new app if not in a project": { CmdArgs: []string{"--ticket=example", "--challenge=tictactoe"}, ExpectedStdoutOutputs: []string{"Get started by creating a new app"}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { cm.ApiInterface.On( "ExchangeAuthTicket", mock.Anything, @@ -109,7 +110,7 @@ func TestLoginCommmand(t *testing.T) { "suggests listing existing apps from the project": { CmdArgs: []string{"--ticket", "example", "--challenge", "tictactoe"}, ExpectedStdoutOutputs: []string{"Review existing installations of the app"}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { cm.ApiInterface.On( "ExchangeAuthTicket", mock.Anything, @@ -139,7 +140,7 @@ func TestLoginCommmand(t *testing.T) { }, "happy path login with prompt flow should pass challenge code to ExchangeAuthTicket API": { CmdArgs: []string{}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { cm.ApiInterface.On("GenerateAuthTicket", mock.Anything, mock.Anything, mock.Anything).Return(api.GenerateAuthTicketResult{}, nil) cm.IO.On("InputPrompt", mock.Anything, "Enter challenge code", iostreams.InputPromptConfig{ Required: true, @@ -162,7 +163,7 @@ func TestLoginCommmand(t *testing.T) { }, "should explode if ExchangeAuthTicket API fails": { CmdArgs: []string{}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { cm.ApiInterface.On("GenerateAuthTicket", mock.Anything, mock.Anything, mock.Anything).Return(api.GenerateAuthTicketResult{}, nil) cm.IO.On("InputPrompt", mock.Anything, "Enter challenge code", iostreams.InputPromptConfig{ Required: true, diff --git a/cmd/auth/logout_test.go b/cmd/auth/logout_test.go index fa9c37a8..445f75ab 100644 --- a/cmd/auth/logout_test.go +++ b/cmd/auth/logout_test.go @@ -15,6 +15,7 @@ package auth import ( + "context" "testing" "github.com/slackapi/slack-cli/internal/iostreams" @@ -34,7 +35,7 @@ func TestLogoutCommand(t *testing.T) { }, "logout of all teams": { CmdArgs: []string{"--all"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.AuthInterface.On("ResolveApiHost", mock.Anything, mock.Anything, mock.Anything).Return("api.slack.com") clientsMock.AuthInterface.On("ResolveLogstashHost", mock.Anything, mock.Anything, mock.Anything).Return("logstash.slack.com") clientsMock.AuthInterface.On("Auths", mock.Anything).Return(fakeAuthsByTeamSlice, nil) @@ -58,7 +59,7 @@ func TestLogoutCommand(t *testing.T) { }, "logout of single team by named domain via flag": { CmdArgs: []string{"--team", "team1"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.AuthInterface.On("ResolveApiHost", mock.Anything, mock.Anything, mock.Anything).Return("api.slack.com") clientsMock.AuthInterface.On("ResolveLogstashHost", mock.Anything, mock.Anything, mock.Anything).Return("logstash.slack.com") clientsMock.AuthInterface.On("Auths", mock.Anything).Return(fakeAuthsByTeamSlice, nil) @@ -82,7 +83,7 @@ func TestLogoutCommand(t *testing.T) { }, "logout of single team by id via flag": { CmdArgs: []string{"--team", "T2"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.AuthInterface.On("ResolveApiHost", mock.Anything, mock.Anything, mock.Anything).Return("api.slack.com") clientsMock.AuthInterface.On("ResolveLogstashHost", mock.Anything, mock.Anything, mock.Anything).Return("logstash.slack.com") clientsMock.IO.On("SelectPrompt", mock.Anything, "Select an authorization to revoke", mock.Anything, iostreams.MatchPromptConfig(iostreams.SelectPromptConfig{ @@ -114,7 +115,7 @@ func TestLogoutCommand(t *testing.T) { }, "require a known team value is used in flag": { CmdArgs: []string{"--team", "randomteamdomain"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clientsFactory *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.AuthInterface.On("Auths", mock.Anything).Return(fakeAuthsByTeamSlice, nil) clientsMock.IO.On("SelectPrompt", mock.Anything, "Select an authorization to revoke", mock.Anything, iostreams.MatchPromptConfig(iostreams.SelectPromptConfig{ Flag: clientsMock.Config.Flags.Lookup("team"), @@ -131,7 +132,7 @@ func TestLogoutCommand(t *testing.T) { }, "logout of a workspace by prompt": { CmdArgs: []string{}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.AuthInterface.On("ResolveApiHost", mock.Anything, mock.Anything, mock.Anything).Return("api.slack.com") clientsMock.AuthInterface.On("ResolveLogstashHost", mock.Anything, mock.Anything, mock.Anything).Return("logstash.slack.com") clientsMock.AuthInterface.On("Auths", mock.Anything).Return(fakeAuthsByTeamSlice, nil) @@ -159,7 +160,7 @@ func TestLogoutCommand(t *testing.T) { }, "automatically logout of the only available workspace available": { CmdArgs: []string{}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.AuthInterface.On("ResolveApiHost", mock.Anything, mock.Anything, mock.Anything).Return("api.slack.com") clientsMock.AuthInterface.On("ResolveLogstashHost", mock.Anything, mock.Anything, mock.Anything).Return("logstash.slack.com") clientsMock.AuthInterface.On("Auths", mock.Anything).Return([]types.SlackAuth{ @@ -179,7 +180,7 @@ func TestLogoutCommand(t *testing.T) { }, "verify the only available auth matches a team flag": { CmdArgs: []string{"--team", "anotherteam"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.AuthInterface.On("Auths", mock.Anything).Return([]types.SlackAuth{ fakeAuthsByTeamSlice[0], }, nil) @@ -198,7 +199,7 @@ func TestLogoutCommand(t *testing.T) { }, "confirm authorizations are revoked if none exist": { CmdArgs: []string{}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.AuthInterface.On("Auths", mock.Anything).Return([]types.SlackAuth{}, nil) }, ExpectedOutputs: []string{"All authorizations successfully revoked"}, @@ -209,7 +210,7 @@ func TestLogoutCommand(t *testing.T) { }, "error if a team flag is provided without auths": { CmdArgs: []string{"--team", "someteam"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.AuthInterface.On("Auths", mock.Anything).Return([]types.SlackAuth{}, nil) clientsMock.IO.On("SelectPrompt", mock.Anything, "Select an authorization to revoke", mock.Anything, iostreams.MatchPromptConfig(iostreams.SelectPromptConfig{ Flag: clientsMock.Config.Flags.Lookup("team"), diff --git a/cmd/auth/revoke_test.go b/cmd/auth/revoke_test.go index cab2bd5c..e0cc37e0 100644 --- a/cmd/auth/revoke_test.go +++ b/cmd/auth/revoke_test.go @@ -15,6 +15,7 @@ package auth import ( + "context" "testing" "github.com/slackapi/slack-cli/internal/iostreams" @@ -30,7 +31,7 @@ func TestRevokeCommand(t *testing.T) { testutil.TableTestCommand(t, testutil.CommandTests{ "revoke a token passed by flag": { CmdArgs: []string{"--token", "xoxp-example-1234"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.IO.On("PasswordPrompt", mock.Anything, "Enter a token to revoke", iostreams.MatchPromptConfig(iostreams.PasswordPromptConfig{ Flag: clientsMock.Config.Flags.Lookup("token"), })).Return(iostreams.PasswordPromptResponse{ @@ -46,7 +47,7 @@ func TestRevokeCommand(t *testing.T) { }, "require a set token value with the flag": { CmdArgs: []string{"--token", ""}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.IO.On("PasswordPrompt", mock.Anything, "Enter a token to revoke", iostreams.MatchPromptConfig(iostreams.PasswordPromptConfig{ Flag: clientsMock.Config.Flags.Lookup("token"), })).Return(iostreams.PasswordPromptResponse{}, slackerror.New(slackerror.ErrMissingFlag)) @@ -58,7 +59,7 @@ func TestRevokeCommand(t *testing.T) { }, "revoke a token input by prompt": { CmdArgs: []string{}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.IO.On("PasswordPrompt", mock.Anything, "Enter a token to revoke", iostreams.MatchPromptConfig(iostreams.PasswordPromptConfig{ Flag: clientsMock.Config.Flags.Lookup("token"), })).Return(iostreams.PasswordPromptResponse{ @@ -74,7 +75,7 @@ func TestRevokeCommand(t *testing.T) { }, "verify errors are gracefully handled during the revoke": { CmdArgs: []string{}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.IO.On("PasswordPrompt", mock.Anything, "Enter a token to revoke", iostreams.MatchPromptConfig(iostreams.PasswordPromptConfig{ Flag: clientsMock.Config.Flags.Lookup("token"), })).Return(iostreams.PasswordPromptResponse{ diff --git a/cmd/collaborators/add_test.go b/cmd/collaborators/add_test.go index c7f1f9be..32945485 100644 --- a/cmd/collaborators/add_test.go +++ b/cmd/collaborators/add_test.go @@ -31,7 +31,7 @@ func TestAddCommand(t *testing.T) { testutil.TableTestCommand(t, testutil.CommandTests{ "add an experimental reader collaborator from user id": { CmdArgs: []string{"U123", "--permission-type", "reader"}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { cm.AddDefaultMocks() // Mock App Selection appSelectMock := prompts.NewAppSelectMock() @@ -55,7 +55,7 @@ func TestAddCommand(t *testing.T) { }, "add an owner collaborator from collaborator email": { CmdArgs: []string{"joe.smith@company.com", "--permission-type", "owner"}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { cm.AddDefaultMocks() // Mock App Selection appSelectMock := prompts.NewAppSelectMock() @@ -80,7 +80,7 @@ func TestAddCommand(t *testing.T) { }, "default to owner if permission type is not specified": { CmdArgs: []string{"joe.smith@company.com"}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { cm.AddDefaultMocks() // Mock App Selection appSelectMock := prompts.NewAppSelectMock() diff --git a/cmd/collaborators/remove_test.go b/cmd/collaborators/remove_test.go index e7cfd87a..70f31076 100644 --- a/cmd/collaborators/remove_test.go +++ b/cmd/collaborators/remove_test.go @@ -15,6 +15,7 @@ package collaborators import ( + "context" "testing" "github.com/slackapi/slack-cli/internal/iostreams" @@ -50,7 +51,7 @@ func TestRemoveCommand(t *testing.T) { testutil.TableTestCommand(t, testutil.CommandTests{ "always attempts to remove the collaborator provided via argument": { CmdArgs: []string{"USLACKBOT"}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { appSelectMock := prompts.NewAppSelectMock() teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt appSelectMock.On("TeamAppSelectPrompt"). @@ -69,7 +70,7 @@ func TestRemoveCommand(t *testing.T) { }, "still attempts to remove the collaborator provided via prompt": { CmdArgs: []string{}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { appSelectMock := prompts.NewAppSelectMock() teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt appSelectMock.On("TeamAppSelectPrompt"). @@ -90,7 +91,7 @@ func TestRemoveCommand(t *testing.T) { }, "avoids removing the user performing the command without confirmation": { CmdArgs: []string{}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { appSelectMock := prompts.NewAppSelectMock() teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt appSelectMock.On("TeamAppSelectPrompt"). diff --git a/cmd/collaborators/update_test.go b/cmd/collaborators/update_test.go index c8924c49..7a090ddb 100644 --- a/cmd/collaborators/update_test.go +++ b/cmd/collaborators/update_test.go @@ -31,7 +31,7 @@ func TestUpdateCommand(t *testing.T) { "given user ID, update a collaborator to be a reader": { CmdArgs: []string{"U123", "--permission-type", "reader"}, ExpectedOutputs: []string{"U123 successfully updated as a reader collaborator on this app"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.AddDefaultMocks() // Mock App Selection appSelectMock := prompts.NewAppSelectMock() @@ -49,7 +49,7 @@ func TestUpdateCommand(t *testing.T) { "given email, update a collaborator to be an owner": { CmdArgs: []string{"joe.smith@company.com", "--permission-type", "owner"}, ExpectedOutputs: []string{"joe.smith@company.com successfully updated as an owner collaborator on this app"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.AddDefaultMocks() // Mock App Selection appSelectMock := prompts.NewAppSelectMock() @@ -67,7 +67,7 @@ func TestUpdateCommand(t *testing.T) { "permission type must be specified": { CmdArgs: []string{"joe.smith@company.com"}, ExpectedOutputs: []string{"Specify a permission type for your collaborator"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.AddDefaultMocks() // Set experiment flag clientsMock.Config.ExperimentsFlag = append(clientsMock.Config.ExperimentsFlag, "read-only-collaborators") @@ -77,7 +77,7 @@ func TestUpdateCommand(t *testing.T) { "user ID must be provided": { CmdArgs: []string{}, ExpectedErrorStrings: []string{"accepts 1 arg(s), received 0"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.AddDefaultMocks() // Set experiment flag clientsMock.Config.ExperimentsFlag = append(clientsMock.Config.ExperimentsFlag, "read-only-collaborators") diff --git a/cmd/datastore/bulk_put_test.go b/cmd/datastore/bulk_put_test.go index c9cf6f84..d5749372 100644 --- a/cmd/datastore/bulk_put_test.go +++ b/cmd/datastore/bulk_put_test.go @@ -230,7 +230,7 @@ func TestBulkPutCommandImport(t *testing.T) { `{"datastore":"Todos"}`, `--from-file=my-file`, }, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { *cm = *setupDatastoreMocks() cm.ApiInterface.On("AppsDatastoreBulkPut", mock.Anything, mock.Anything, mock.Anything). Return(types.AppDatastoreBulkPutResult{}, nil) @@ -260,7 +260,7 @@ func TestBulkPutCommandImport(t *testing.T) { `--from-file=my-file`, }, ExpectedOutputs: []string{"Some items failed to be imported"}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { *cm = *setupDatastoreMocks() cm.ApiInterface.On("AppsDatastoreBulkPut", mock.Anything, mock.Anything, mock.Anything). Return(types.AppDatastoreBulkPutResult{}, nil) @@ -303,7 +303,7 @@ func TestBulkPutCommandImport(t *testing.T) { `--from-file=my-file`, }, ExpectedOutputs: []string{"Import will be limited to the first 5000 items in the file"}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { *cm = *setupDatastoreMocks() cm.ApiInterface.On("AppsDatastoreBulkPut", mock.Anything, mock.Anything, mock.Anything). Return(types.AppDatastoreBulkPutResult{}, nil) @@ -326,7 +326,7 @@ func TestBulkPutCommandImport(t *testing.T) { `{"datastore":"Todos"}`, `--from-file=my-file`, }, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { *cm = *setupDatastoreMocks() itemsFile, err := cm.Fs.Create("my-file") diff --git a/cmd/datastore/count_test.go b/cmd/datastore/count_test.go index 311e501d..c64bd56d 100644 --- a/cmd/datastore/count_test.go +++ b/cmd/datastore/count_test.go @@ -15,6 +15,7 @@ package datastore import ( + "context" "testing" "github.com/slackapi/slack-cli/internal/app" @@ -130,7 +131,7 @@ func TestCountCommand(t *testing.T) { testutil.TableTestCommand(t, testutil.CommandTests{ "default to the empty expression when no expression is passed": { CmdArgs: []string{"--datastore", "tasks"}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { cm.ApiInterface.On("AppsDatastoreCount", mock.Anything, mock.Anything, mock.Anything). Return(types.AppDatastoreCountResult{Datastore: "tasks", Count: 12}, nil) }, @@ -149,7 +150,7 @@ func TestCountCommand(t *testing.T) { }, "pass an empty expression through arguments": { CmdArgs: []string{`{"datastore":"tasks"}`}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { cm.ApiInterface.On("AppsDatastoreCount", mock.Anything, mock.Anything, mock.Anything). Return(types.AppDatastoreCountResult{Datastore: "tasks", Count: 12}, nil) }, @@ -170,7 +171,7 @@ func TestCountCommand(t *testing.T) { CmdArgs: []string{ `{"datastore":"tasks","expression":"#task_id < :num","expression_attributes":{"#task_id":"task_id"},"expression_values":{":num":"3"}}`, }, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { cm.ApiInterface.On("AppsDatastoreCount", mock.Anything, mock.Anything, mock.Anything). Return(types.AppDatastoreCountResult{Datastore: "tasks", Count: 12}, nil) }, @@ -201,7 +202,7 @@ func TestCountCommand(t *testing.T) { CmdArgs: []string{ `{"datastore":"Todos","app":"A001","expression":"#task_id < :num AND #status = :progress","expression_attributes":{"#task_id":"task_id","#status":"status"},"expression_values":{":num":"3",":progress":"wip"}}`, }, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { cm.ApiInterface.On("AppsDatastoreCount", mock.Anything, mock.Anything, mock.Anything). Return(types.AppDatastoreCountResult{Datastore: "tasks", Count: 12}, nil) }, @@ -232,7 +233,7 @@ func TestCountCommand(t *testing.T) { }, "pass an empty expression through prompts": { CmdArgs: []string{"--unstable"}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { manifestMock := &app.ManifestMockObject{} manifestMock.On("GetManifestRemote", mock.Anything, mock.Anything, mock.Anything).Return(types.SlackYaml{ AppManifest: types.AppManifest{ @@ -271,7 +272,7 @@ func TestCountCommand(t *testing.T) { }, "pass an extended expression through prompts": { CmdArgs: []string{"--unstable"}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { manifestMock := &app.ManifestMockObject{} manifestMock.On("GetManifestRemote", mock.Anything, mock.Anything, mock.Anything).Return(types.SlackYaml{ AppManifest: types.AppManifest{ diff --git a/cmd/datastore/query_test.go b/cmd/datastore/query_test.go index 090a3d77..e858fdaf 100644 --- a/cmd/datastore/query_test.go +++ b/cmd/datastore/query_test.go @@ -392,7 +392,7 @@ func TestQueryCommandExport(t *testing.T) { `{"datastore":"Todos"}`, `--to-file=my-file`, }, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { *cm = *setupDatastoreMocks() _, err := prepareExportMockData(cm, 10, 2) assert.NoError(t, err) @@ -421,7 +421,7 @@ func TestQueryCommandExport(t *testing.T) { `--to-file=my-file`, }, ExpectedOutputs: []string{"Export will be limited to the first 10000 items in the datastore"}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { *cm = *setupDatastoreMocks() _, err := prepareExportMockData(cm, 10010, 100) assert.NoError(t, err) diff --git a/cmd/docgen/docgen_test.go b/cmd/docgen/docgen_test.go index 994263b9..c283e159 100644 --- a/cmd/docgen/docgen_test.go +++ b/cmd/docgen/docgen_test.go @@ -15,6 +15,7 @@ package docgen import ( + "context" "errors" "path/filepath" "testing" @@ -32,7 +33,7 @@ func TestNewDocsCommand(t *testing.T) { testutil.TableTestCommand(t, testutil.CommandTests{ "when no path argument": { CmdArgs: []string{}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { cm.Fs.On("MkdirAll", mock.Anything, mock.Anything).Return(nil) }, ExpectedOutputs: []string{ @@ -76,7 +77,7 @@ func TestNewDocsCommand(t *testing.T) { }, "when path argument exists": { CmdArgs: []string{"markdown-docs"}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { cm.Fs.On("MkdirAll", mock.Anything, mock.Anything).Return(nil) }, ExpectedOutputs: []string{ @@ -118,7 +119,7 @@ func TestNewDocsCommand(t *testing.T) { }, }, "when Getwd returns error": { - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { cm.Fs.On("MkdirAll", mock.Anything, mock.Anything).Return(nil) cm.Os.On("Getwd").Return("", errors.New("somehow there is no cwd")) }, @@ -152,7 +153,7 @@ func TestNewDocsCommand(t *testing.T) { }, }, "when creating the default docs directory fails": { - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { cm.Fs.On( "MkdirAll", filepath.Join(slackdeps.MockWorkingDirectory, "docs"), @@ -165,7 +166,7 @@ func TestNewDocsCommand(t *testing.T) { ExpectedErrorStrings: []string{"no write permission"}, }, "when creating the default commands directory fails": { - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { cm.Fs.On( "MkdirAll", filepath.Join(slackdeps.MockWorkingDirectory, "docs"), @@ -185,7 +186,7 @@ func TestNewDocsCommand(t *testing.T) { ExpectedErrorStrings: []string{"no write permission"}, }, "when generating docs fails": { - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { cm.Cobra.On( "GenMarkdownTree", mock.Anything, diff --git a/cmd/env/add_test.go b/cmd/env/add_test.go index 10a38828..c3aceafe 100644 --- a/cmd/env/add_test.go +++ b/cmd/env/add_test.go @@ -144,7 +144,7 @@ func Test_Env_AddCommand(t *testing.T) { testutil.TableTestCommand(t, testutil.CommandTests{ "add a variable using arguments": { CmdArgs: []string{"ENV_NAME", "ENV_VALUE"}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + 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) { @@ -168,7 +168,7 @@ func Test_Env_AddCommand(t *testing.T) { }, "provide a variable name by argument and value by prompt": { CmdArgs: []string{"ENV_NAME"}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { setupEnvAddCommandMocks(cm, cf) cm.IO.On( "PasswordPrompt", @@ -199,7 +199,7 @@ func Test_Env_AddCommand(t *testing.T) { }, "provide a variable name by argument and value by flag": { CmdArgs: []string{"ENV_NAME", "--value", "example_value"}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { setupEnvAddCommandMocks(cm, cf) cm.IO.On( "PasswordPrompt", @@ -230,7 +230,7 @@ func Test_Env_AddCommand(t *testing.T) { }, "provide both variable name and value by prompt": { CmdArgs: []string{}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { setupEnvAddCommandMocks(cm, cf) cm.IO.On( "InputPrompt", diff --git a/cmd/env/list_test.go b/cmd/env/list_test.go index c7183318..b261f53f 100644 --- a/cmd/env/list_test.go +++ b/cmd/env/list_test.go @@ -15,6 +15,7 @@ package env import ( + "context" "testing" "github.com/slackapi/slack-cli/internal/app" @@ -129,7 +130,7 @@ func Test_Env_ListCommandPreRun(t *testing.T) { func Test_Env_ListCommand(t *testing.T) { testutil.TableTestCommand(t, testutil.CommandTests{ "list variables using arguments": { - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { cm.ApiInterface.On( "ListVariables", mock.Anything, diff --git a/cmd/env/remove_test.go b/cmd/env/remove_test.go index 29051996..b24d1b4e 100644 --- a/cmd/env/remove_test.go +++ b/cmd/env/remove_test.go @@ -15,6 +15,7 @@ package env import ( + "context" "testing" "github.com/slackapi/slack-cli/internal/app" @@ -131,7 +132,7 @@ func Test_Env_RemoveCommand(t *testing.T) { testutil.TableTestCommand(t, testutil.CommandTests{ "remove a variable using arguments": { CmdArgs: []string{"ENV_NAME"}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { cm.ApiInterface.On( "ListVariables", mock.Anything, @@ -174,7 +175,7 @@ func Test_Env_RemoveCommand(t *testing.T) { }, "remove a variable using prompt": { CmdArgs: []string{}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { cm.ApiInterface.On( "ListVariables", mock.Anything, @@ -233,7 +234,7 @@ func Test_Env_RemoveCommand(t *testing.T) { }, "exit without errors when prompting zero environment variables": { CmdArgs: []string{}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { cm.ApiInterface.On( "ListVariables", mock.Anything, diff --git a/cmd/externalauth/add_secret_test.go b/cmd/externalauth/add_secret_test.go index 348d4e6d..6ae691e7 100644 --- a/cmd/externalauth/add_secret_test.go +++ b/cmd/externalauth/add_secret_test.go @@ -139,7 +139,7 @@ func TestExternalAuthAddClientSecretCommand(t *testing.T) { testutil.TableTestCommand(t, testutil.CommandTests{ "no params": { CmdArgs: []string{}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.ApiInterface.On("AppsAuthExternalList", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(types.ExternalAuthorizationInfoLists{ @@ -173,7 +173,7 @@ func TestExternalAuthAddClientSecretCommand(t *testing.T) { }, "with --provider": { CmdArgs: []string{"--provider", "provider_a"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.ApiInterface.On("AppsAuthExternalList", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(types.ExternalAuthorizationInfoLists{ @@ -208,7 +208,7 @@ func TestExternalAuthAddClientSecretCommand(t *testing.T) { }, "with --secret": { CmdArgs: []string{"--secret", "secret"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.ApiInterface.On("AppsAuthExternalList", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(types.ExternalAuthorizationInfoLists{ @@ -241,7 +241,7 @@ func TestExternalAuthAddClientSecretCommand(t *testing.T) { }, "with --provider and --secret": { CmdArgs: []string{"--provider", "provider_a", "--secret", "secret"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.ApiInterface.On("AppsAuthExternalList", mock.Anything, mock.Anything, mock.Anything). Return(types.ExternalAuthorizationInfoLists{ @@ -273,7 +273,7 @@ func TestExternalAuthAddClientSecretCommand(t *testing.T) { }, "when list api returns error": { CmdArgs: []string{"--provider", "provider_a", "--secret", "secret"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.ApiInterface.On("AppsAuthExternalList", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(types.ExternalAuthorizationInfoLists{ diff --git a/cmd/externalauth/add_test.go b/cmd/externalauth/add_test.go index 691f23ad..b4c93ba2 100644 --- a/cmd/externalauth/add_test.go +++ b/cmd/externalauth/add_test.go @@ -139,7 +139,7 @@ func TestExternalAuthAddCommand(t *testing.T) { "no params": { CmdArgs: []string{}, ExpectedOutputs: []string{}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.ApiInterface.On("AppsAuthExternalList", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(types.ExternalAuthorizationInfoLists{ @@ -167,7 +167,7 @@ func TestExternalAuthAddCommand(t *testing.T) { "no params and no client secret set": { CmdArgs: []string{}, ExpectedErrorStrings: []string{"No client secret exists"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.ApiInterface.On("AppsAuthExternalList", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(types.ExternalAuthorizationInfoLists{ @@ -195,7 +195,7 @@ func TestExternalAuthAddCommand(t *testing.T) { "with provider_key": { CmdArgs: []string{"--provider", "provider_a"}, ExpectedOutputs: []string{}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.ApiInterface.On("AppsAuthExternalList", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(types.ExternalAuthorizationInfoLists{ @@ -223,7 +223,7 @@ func TestExternalAuthAddCommand(t *testing.T) { "with no client secret set": { CmdArgs: []string{"--provider", "provider_a"}, ExpectedErrorStrings: []string{"No client secret exists"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.ApiInterface.On("AppsAuthExternalList", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(types.ExternalAuthorizationInfoLists{ @@ -251,7 +251,7 @@ func TestExternalAuthAddCommand(t *testing.T) { }, "when list api returns error": { CmdArgs: []string{"--provider", "provider_a"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.ApiInterface.On("AppsAuthExternalList", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(types.ExternalAuthorizationInfoLists{ diff --git a/cmd/externalauth/remove_test.go b/cmd/externalauth/remove_test.go index 1f1b06fd..85ca6210 100644 --- a/cmd/externalauth/remove_test.go +++ b/cmd/externalauth/remove_test.go @@ -140,7 +140,7 @@ func TestExternalAuthRemoveCommand(t *testing.T) { "no params": { CmdArgs: []string{}, ExpectedOutputs: []string{}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.ApiInterface.On("AppsAuthExternalList", mock.Anything, mock.Anything, mock.Anything). Return(types.ExternalAuthorizationInfoLists{ @@ -167,7 +167,7 @@ func TestExternalAuthRemoveCommand(t *testing.T) { "with --provider": { CmdArgs: []string{"--provider", "provider_a"}, ExpectedOutputs: []string{}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.ApiInterface.On("AppsAuthExternalList", mock.Anything, mock.Anything, mock.Anything). Return(types.ExternalAuthorizationInfoLists{ @@ -192,7 +192,7 @@ func TestExternalAuthRemoveCommand(t *testing.T) { "with --all": { CmdArgs: []string{"--all"}, ExpectedOutputs: []string{}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.ApiInterface.On("AppsAuthExternalList", mock.Anything, mock.Anything, mock.Anything). Return(types.ExternalAuthorizationInfoLists{ @@ -217,7 +217,7 @@ func TestExternalAuthRemoveCommand(t *testing.T) { "with --all and --provider": { CmdArgs: []string{"--all", "--provider", "provider_a"}, ExpectedOutputs: []string{}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.ApiInterface.On("AppsAuthExternalList", mock.Anything, mock.Anything, mock.Anything). Return(types.ExternalAuthorizationInfoLists{ @@ -242,7 +242,7 @@ func TestExternalAuthRemoveCommand(t *testing.T) { }, "with --all but no auth present": { CmdArgs: []string{"--all"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.ApiInterface.On("AppsAuthExternalList", mock.Anything, mock.Anything, mock.Anything). Return(types.ExternalAuthorizationInfoLists{ diff --git a/cmd/externalauth/select_auth_test.go b/cmd/externalauth/select_auth_test.go index f7c4c7d8..9a5ff9a9 100644 --- a/cmd/externalauth/select_auth_test.go +++ b/cmd/externalauth/select_auth_test.go @@ -15,6 +15,7 @@ package externalauth import ( + "context" "errors" "testing" @@ -241,7 +242,7 @@ func TestExternalAuthSelectAuthCommand(t *testing.T) { testutil.TableTestCommand(t, testutil.CommandTests{ "list api returns error": { CmdArgs: []string{}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.ApiInterface.On("AppsAuthExternalList", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(types.ExternalAuthorizationInfoLists{}, errors.New("test error")) @@ -253,7 +254,7 @@ func TestExternalAuthSelectAuthCommand(t *testing.T) { }, "list with no tokens and no params": { CmdArgs: []string{}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.ApiInterface.On("AppsAuthExternalList", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(sampleListReturnWithoutTokens, nil) @@ -268,7 +269,7 @@ func TestExternalAuthSelectAuthCommand(t *testing.T) { }, "list with no tokens and workflow flag": { CmdArgs: []string{"--workflow", "#/workflows/workflow_callback"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.ApiInterface.On("AppsAuthExternalList", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(sampleListReturnWithoutTokens, nil) @@ -286,7 +287,7 @@ func TestExternalAuthSelectAuthCommand(t *testing.T) { }, "list with no workflows and no params": { CmdArgs: []string{}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.ApiInterface.On("AppsAuthExternalList", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(sampleListReturnWithoutWorkflows, nil) @@ -301,7 +302,7 @@ func TestExternalAuthSelectAuthCommand(t *testing.T) { }, "list with no workflows and workflow flag": { CmdArgs: []string{"--workflow", "#/workflows/workflow_callback"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.ApiInterface.On("AppsAuthExternalList", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(sampleListReturnWithoutWorkflows, nil) @@ -319,7 +320,7 @@ func TestExternalAuthSelectAuthCommand(t *testing.T) { }, "list with workflows and no param": { CmdArgs: []string{}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.ApiInterface.On("AppsAuthExternalList", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(sampleListReturnWithWorkflows, nil) @@ -345,7 +346,7 @@ func TestExternalAuthSelectAuthCommand(t *testing.T) { }, "list with workflows and invalid workflow param": { CmdArgs: []string{"--workflow", "#/workflows/workflow_callback"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.ApiInterface.On("AppsAuthExternalList", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(sampleListReturnWithWorkflows, nil) @@ -377,7 +378,7 @@ func TestExternalAuthSelectAuthCommand(t *testing.T) { }, "list with workflows and valid workflow param": { CmdArgs: []string{"--workflow", "#/workflows/my_callback_id2"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.ApiInterface.On("AppsAuthExternalList", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(sampleListReturnWithWorkflows, nil) @@ -402,7 +403,7 @@ func TestExternalAuthSelectAuthCommand(t *testing.T) { }, "list with workflows and valid workflow invalid provider": { CmdArgs: []string{"--workflow", "#/workflows/my_callback_id2", "--provider", "test_provider"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.ApiInterface.On("AppsAuthExternalList", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(sampleListReturnWithWorkflows, nil) @@ -426,7 +427,7 @@ func TestExternalAuthSelectAuthCommand(t *testing.T) { }, "list with workflows and valid workflow valid provider": { CmdArgs: []string{"--workflow", "#/workflows/my_callback_id2", "--provider", "provider_b"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.ApiInterface.On("AppsAuthExternalList", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(sampleListReturnWithWorkflows, nil) @@ -452,7 +453,7 @@ func TestExternalAuthSelectAuthCommand(t *testing.T) { }, "list with workflows and valid workflow valid provider with tokens": { CmdArgs: []string{"--workflow", "#/workflows/my_callback_id2", "--provider", "provider_a"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.ApiInterface.On("AppsAuthExternalList", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(sampleListReturnWithWorkflows, nil) @@ -484,7 +485,7 @@ func TestExternalAuthSelectAuthCommand(t *testing.T) { }, "list with workflows and valid workflow valid provider invalid account": { CmdArgs: []string{"--workflow", "#/workflows/my_callback_id2", "--provider", "provider_a", "--external-account", "test_account"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.ApiInterface.On("AppsAuthExternalList", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(sampleListReturnWithWorkflows, nil) @@ -515,7 +516,7 @@ func TestExternalAuthSelectAuthCommand(t *testing.T) { }, "list with workflows and valid workflow valid provider valid account": { CmdArgs: []string{"--workflow", "#/workflows/my_callback_id2", "--provider", "provider_a", "--external-account", "xyz2@salesforce.com"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.ApiInterface.On("AppsAuthExternalList", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(sampleListReturnWithWorkflows, nil) diff --git a/cmd/function/access_test.go b/cmd/function/access_test.go index 4325e418..1ffd6947 100644 --- a/cmd/function/access_test.go +++ b/cmd/function/access_test.go @@ -39,7 +39,7 @@ func TestFunctionDistributionCommand(t *testing.T) { ExpectedOutputs: []string{ "Function 'F1234' can be added to workflows by app collaborators", }, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { // set distribution clientsMock.ApiInterface.On("FunctionDistributionSet", mock.Anything, mock.Anything, mock.Anything, types.APP_COLLABORATORS, mock.Anything). Return([]types.FunctionDistributionUser{}, nil).Once() @@ -65,7 +65,7 @@ func TestFunctionDistributionCommand(t *testing.T) { "U00", "U01", }, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { // check if distribution type is named_entities clientsMock.ApiInterface.On("FunctionDistributionList", mock.Anything, mock.Anything, mock.Anything). Return(types.APP_COLLABORATORS, []types.FunctionDistributionUser{}, nil).Once() @@ -96,7 +96,7 @@ func TestFunctionDistributionCommand(t *testing.T) { "Function 'F1234' can be added to workflows by the following users", "U01", }, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { // check if distribution type is named_entities clientsMock.ApiInterface.On("FunctionDistributionList", mock.Anything, mock.Anything, mock.Anything). Return(types.NAMED_ENTITIES, []types.FunctionDistributionUser{{UserName: "user 0", ID: "U00"}, {UserName: "user 1", ID: "U01"}}, nil).Once() @@ -123,7 +123,7 @@ func TestFunctionDistributionCommand(t *testing.T) { "Function 'F1234' can be added to workflows by the following users", "everyone in the workspace", }, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.ApiInterface.On("FunctionDistributionList", mock.Anything, "F1234", fakeApp.AppID). Return(types.EVERYONE, []types.FunctionDistributionUser{}, nil).Once() clientsMock.AddDefaultMocks() @@ -143,7 +143,7 @@ func TestFunctionDistributionCommand(t *testing.T) { }, "attempt to read permissions with the file flag": { CmdArgs: []string{"--file", "permissions.json"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + 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) diff --git a/cmd/manifest/info_test.go b/cmd/manifest/info_test.go index bba763c4..70e730ef 100644 --- a/cmd/manifest/info_test.go +++ b/cmd/manifest/info_test.go @@ -42,7 +42,7 @@ func TestInfoCommand(t *testing.T) { testutil.TableTestCommand(t, testutil.CommandTests{ "errors when the source is project and app id is set": { CmdArgs: []string{"--source", "local", "--app", "A0001"}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { cf.SDKConfig = hooks.NewSDKConfigMock() }, ExpectedError: slackerror.New(slackerror.ErrMismatchedFlags). @@ -50,7 +50,7 @@ func TestInfoCommand(t *testing.T) { }, "errors when the source is an unexpected value": { CmdArgs: []string{"--source", "paper"}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { cf.SDKConfig = hooks.NewSDKConfigMock() cm.HookExecutor.On("Execute", mock.Anything).Return("", nil) }, @@ -59,7 +59,7 @@ func TestInfoCommand(t *testing.T) { }, "gathers the --source local from the get-manifest hook": { CmdArgs: []string{"--source", "local"}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { manifestMock := &app.ManifestMockObject{} manifestMock.On("GetManifestLocal", mock.Anything, mock.Anything).Return(types.SlackYaml{ AppManifest: types.AppManifest{ @@ -84,7 +84,7 @@ func TestInfoCommand(t *testing.T) { }, "gathers the --source remote from the apps.manifest.export method": { CmdArgs: []string{"--source", "remote"}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { appSelectMock := prompts.NewAppSelectMock() appSelectPromptFunc = appSelectMock.AppSelectPrompt appSelectMock.On("AppSelectPrompt").Return( @@ -114,8 +114,7 @@ func TestInfoCommand(t *testing.T) { }, }, "gathers manifest.source from project configurations with the bolt experiment": { - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { - ctx := context.Background() + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { appSelectMock := prompts.NewAppSelectMock() appSelectPromptFunc = appSelectMock.AppSelectPrompt appSelectMock.On("AppSelectPrompt").Return( @@ -159,8 +158,7 @@ func TestInfoCommand(t *testing.T) { fmt.Sprintf("Set \"manifest.source\" to \"%s\" in \"%s\" to continue", config.MANIFEST_SOURCE_LOCAL, filepath.Join(".slack", "config.json")), fmt.Sprintf("Read about manifest sourcing with %s", style.Commandf("manifest info --help", false)), }, "\n")), - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { - ctx := context.Background() + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { cf.SDKConfig.WorkingDirectory = "." cm.IO.AddDefaultMocks() cm.Os.AddDefaultMocks() diff --git a/cmd/manifest/manifest_test.go b/cmd/manifest/manifest_test.go index 24e8396a..8c868308 100644 --- a/cmd/manifest/manifest_test.go +++ b/cmd/manifest/manifest_test.go @@ -15,6 +15,7 @@ package manifest import ( + "context" "encoding/json" "testing" @@ -34,7 +35,7 @@ func TestManifestCommand(t *testing.T) { testutil.TableTestCommand(t, testutil.CommandTests{ "calls the manifest info command with a remote --app flag": { CmdArgs: []string{"--app", "A0001"}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { appSelectMock := prompts.NewAppSelectMock() appSelectPromptFunc = appSelectMock.AppSelectPrompt appSelectMock.On("AppSelectPrompt").Return( diff --git a/cmd/openformresponse/export_test.go b/cmd/openformresponse/export_test.go index ada48273..58c6dfcb 100644 --- a/cmd/openformresponse/export_test.go +++ b/cmd/openformresponse/export_test.go @@ -15,6 +15,7 @@ package openformresponse import ( + "context" "errors" "testing" @@ -35,7 +36,7 @@ func TestExportCommand(t *testing.T) { testutil.TableTestCommand(t, testutil.CommandTests{ "missing --workflow": { CmdArgs: []string{}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { appSelectTeardown = setupMockCreateAppSelection(installedProdApp) }, Teardown: func() { @@ -46,7 +47,7 @@ func TestExportCommand(t *testing.T) { "with --step-id, API succeeds": { CmdArgs: []string{"--workflow", "#/workflows/my_workflow", "--step-id", "stepId"}, ExpectedOutputs: []string{"Slackbot will DM you with a CSV file once it's ready"}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { appSelectTeardown = setupMockCreateAppSelection(installedProdApp) cm.ApiInterface.On("StepsResponsesExport", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) }, @@ -60,7 +61,7 @@ func TestExportCommand(t *testing.T) { "with --step-id, API fails": { CmdArgs: []string{"--workflow", "#/workflows/my_workflow", "--step-id", "stepId"}, ExpectedErrorStrings: []string{"failed"}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { appSelectTeardown = setupMockCreateAppSelection(installedProdApp) cm.ApiInterface.On("StepsResponsesExport", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(errors.New("failed")) }, diff --git a/cmd/project/init_test.go b/cmd/project/init_test.go index 2b073b5f..530c568c 100644 --- a/cmd/project/init_test.go +++ b/cmd/project/init_test.go @@ -54,7 +54,7 @@ func Test_Project_InitCommand(t *testing.T) { testutil.TableTestCommand(t, testutil.CommandTests{ "requires bolt experiment": { CmdArgs: []string{}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { // Do not set experiment flag setupProjectInitCommandMocks(t, cm, cf, false) }, @@ -62,7 +62,7 @@ func Test_Project_InitCommand(t *testing.T) { }, "init a project and do not link an existing app": { CmdArgs: []string{}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { setupProjectInitCommandMocks(t, cm, cf, true) // Do not link an existing app cm.IO.On("ConfirmPrompt", mock.Anything, app.LinkAppConfirmPromptText, mock.Anything).Return(false, nil) @@ -107,7 +107,7 @@ func Test_Project_InitCommand(t *testing.T) { }, "init a project and link an existing app": { CmdArgs: []string{}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { // Mocks auths to match against team and app cm.AuthInterface.On("Auths", mock.Anything).Return([]types.SlackAuth{ mockLinkSlackAuth2, diff --git a/cmd/project/samples_test.go b/cmd/project/samples_test.go index 8a48a122..2ec13757 100644 --- a/cmd/project/samples_test.go +++ b/cmd/project/samples_test.go @@ -33,7 +33,7 @@ func TestSamplesCommand(t *testing.T) { testutil.TableTestCommand(t, testutil.CommandTests{ "creates a template from a trusted sample": { CmdArgs: []string{}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { createPkg.GetSampleRepos = func(client createPkg.Sampler) ([]createPkg.GithubRepo, error) { repos := []createPkg.GithubRepo{ { diff --git a/cmd/triggers/access_test.go b/cmd/triggers/access_test.go index 8990dcac..9f8c6f12 100644 --- a/cmd/triggers/access_test.go +++ b/cmd/triggers/access_test.go @@ -39,7 +39,7 @@ func TestTriggersAccessCommand(t *testing.T) { "pass flags to set access to app collaborators": { CmdArgs: []string{"--trigger-id", fakeTriggerID, "--app-collaborators"}, ExpectedOutputs: []string{fmt.Sprintf("Trigger '%s'", fakeTriggerID), "app collaborator"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockAccessAppSelection(installedProdApp) // get current access type clientsMock.ApiInterface.On("TriggerPermissionsList", mock.Anything, mock.Anything, mock.Anything). @@ -69,7 +69,7 @@ func TestTriggersAccessCommand(t *testing.T) { "Trigger '%s'", fakeTriggerID), "everyone in the workspace", }, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockAccessAppSelection(installedProdApp) // get current access type clientsMock.ApiInterface.On("TriggerPermissionsList", mock.Anything, mock.Anything, mock.Anything). @@ -99,7 +99,7 @@ func TestTriggersAccessCommand(t *testing.T) { fmt.Sprintf("Trigger '%s'", fakeTriggerID), "everyone in all workspaces in this org granted to this app", }, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockAccessAppSelection(installedProdOrgApp) // get current access type clientsMock.ApiInterface.On("TriggerPermissionsList", mock.Anything, mock.Anything, mock.Anything). @@ -126,7 +126,7 @@ func TestTriggersAccessCommand(t *testing.T) { "pass flags to grant access to specific users (previous access: app collaborators)": { CmdArgs: []string{"--trigger-id", fakeTriggerID, "--users", "user1, user2", "--grant", "--include-app-collaborators=false"}, ExpectedOutputs: []string{"Users added", fmt.Sprintf("Trigger '%s'", fakeTriggerID), "these users", "USER1", "USER2"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockAccessAppSelection(installedProdApp) // get current access type clientsMock.ApiInterface.On("TriggerPermissionsList", mock.Anything, mock.Anything, mock.Anything). @@ -158,7 +158,7 @@ func TestTriggersAccessCommand(t *testing.T) { "pass flags to grant access to specific channels (previous access: app collaborators)": { CmdArgs: []string{"--trigger-id", fakeTriggerID, "--channels", "channel1, channel2", "--grant", "--include-app-collaborators=false"}, ExpectedOutputs: []string{"Channels added", fmt.Sprintf("Trigger '%s'", fakeTriggerID), "all members of these channels", "CHANNEL1", "CHANNEL2"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockAccessAppSelection(installedProdApp) // get current access type clientsMock.ApiInterface.On("TriggerPermissionsList", mock.Anything, mock.Anything, mock.Anything). @@ -189,7 +189,7 @@ func TestTriggersAccessCommand(t *testing.T) { "pass flags to grant access to specific team (previous access: app collaborators)": { CmdArgs: []string{"--trigger-id", fakeTriggerID, "--workspaces", "team1", "--grant"}, ExpectedOutputs: []string{"Workspace added", fmt.Sprintf("Trigger '%s'", fakeTriggerID), "all members of this workspace", "TEAM1"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockAccessAppSelection(installedProdApp) // get current access type clientsMock.ApiInterface.On("TriggerPermissionsList", mock.Anything, mock.Anything, mock.Anything). @@ -226,7 +226,7 @@ func TestTriggersAccessCommand(t *testing.T) { "pass flags to grant access to specific teams with include-app-collaborators flag provided (previous access: app collaborators)": { CmdArgs: []string{"--trigger-id", fakeTriggerID, "--workspaces", "team1", "--grant", "--include-app-collaborators"}, ExpectedOutputs: []string{"Workspace added", fmt.Sprintf("Trigger '%s'", fakeTriggerID), "all members of this workspace", "TEAM1"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockAccessAppSelection(installedProdApp) // get current access type clientsMock.ApiInterface.On("TriggerPermissionsList", mock.Anything, mock.Anything, mock.Anything). @@ -262,7 +262,7 @@ func TestTriggersAccessCommand(t *testing.T) { "pass flags to grant access to specific users and channels (previous access: app collaborators)": { CmdArgs: []string{"--trigger-id", fakeTriggerID, "--users", "user1, user2", "--channels", "channel1, channel2", "--grant"}, ExpectedOutputs: []string{"Users added", "Channels added", fmt.Sprintf("Trigger '%s'", fakeTriggerID), "these users", "all members of these channels", "USER1", "USER2", "CHANNEL1", "CHANNEL2"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockAccessAppSelection(installedProdApp) // get current access type clientsMock.ApiInterface.On("TriggerPermissionsList", mock.Anything, mock.Anything, mock.Anything). @@ -312,7 +312,7 @@ func TestTriggersAccessCommand(t *testing.T) { "pass flags to grant access to specific users (previous access: named_entities)": { CmdArgs: []string{"--trigger-id", fakeTriggerID, "--users", "USER2", "--grant"}, ExpectedOutputs: []string{"User added", fmt.Sprintf("Trigger '%s'", fakeTriggerID), "these users", "USER1", "USER2"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockAccessAppSelection(installedProdApp) // get current access type clientsMock.ApiInterface.On("TriggerPermissionsList", mock.Anything, mock.Anything, mock.Anything). @@ -344,7 +344,7 @@ func TestTriggersAccessCommand(t *testing.T) { "pass flags to grant access to specific channels (previous access: named_entities)": { CmdArgs: []string{"--trigger-id", fakeTriggerID, "--channels", "CHANNEL2", "--grant"}, ExpectedOutputs: []string{"Channel added", fmt.Sprintf("Trigger '%s'", fakeTriggerID), "all members of these channels", "CHANNEL1", "CHANNEL2"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockAccessAppSelection(installedProdApp) // get current access type clientsMock.ApiInterface.On("TriggerPermissionsList", mock.Anything, mock.Anything, mock.Anything). @@ -376,7 +376,7 @@ func TestTriggersAccessCommand(t *testing.T) { "pass flags to grant access to specific users, channels and workspaces (previous access: named_entities)": { CmdArgs: []string{"--trigger-id", fakeTriggerID, "--users", "user1, user2", "--channels", "channel2", "--workspaces", "team1", "--grant"}, ExpectedOutputs: []string{"Users added", "Channel added", fmt.Sprintf("Trigger '%s'", fakeTriggerID), "these users", "all members of these channels", "all members of this workspace", "USER1", "USER2", "CHANNEL1", "CHANNEL2", "TEAM1"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockAccessAppSelection(installedProdApp) // get current access type clientsMock.ApiInterface.On("TriggerPermissionsList", mock.Anything, mock.Anything, mock.Anything). @@ -418,7 +418,7 @@ func TestTriggersAccessCommand(t *testing.T) { "pass flags to revoke access from specific users (previous access: named_entities)": { CmdArgs: []string{"--trigger-id", fakeTriggerID, "--users", "USER2", "--revoke"}, ExpectedOutputs: []string{fmt.Sprintf("Trigger '%s'", fakeTriggerID), "this user", "USER1"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockAccessAppSelection(installedProdApp) // get current access type clientsMock.ApiInterface.On("TriggerPermissionsList", mock.Anything, mock.Anything, mock.Anything). @@ -447,7 +447,7 @@ func TestTriggersAccessCommand(t *testing.T) { "pass flags to revoke access from specific channels (previous access: named_entities)": { CmdArgs: []string{"--trigger-id", fakeTriggerID, "--channels", "CHANNEL2", "--revoke"}, ExpectedOutputs: []string{fmt.Sprintf("Trigger '%s'", fakeTriggerID), "all members of this channel", "CHANNEL1"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockAccessAppSelection(installedProdApp) // get current access type clientsMock.ApiInterface.On("TriggerPermissionsList", mock.Anything, mock.Anything, mock.Anything). @@ -475,7 +475,7 @@ func TestTriggersAccessCommand(t *testing.T) { "pass flags to revoke access from specific workspace (previous access: named_entities)": { CmdArgs: []string{"--trigger-id", fakeTriggerID, "--workspaces", "TEAM2", "--revoke"}, ExpectedOutputs: []string{fmt.Sprintf("Trigger '%s'", fakeTriggerID), "all members of this workspace", "TEAM1"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockAccessAppSelection(installedProdApp) // get current access type clientsMock.ApiInterface.On("TriggerPermissionsList", mock.Anything, mock.Anything, mock.Anything). @@ -503,7 +503,7 @@ func TestTriggersAccessCommand(t *testing.T) { "pass flags to revoke access from specific users and channels (previous access: named_entities)": { CmdArgs: []string{"--trigger-id", fakeTriggerID, "--users", "USER2", "--channels", "CHANNEL2", "--revoke"}, ExpectedOutputs: []string{fmt.Sprintf("Trigger '%s'", fakeTriggerID), "this user", "all members of this channel", "USER1", "CHANNEL1"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockAccessAppSelection(installedProdApp) // get current access type clientsMock.ApiInterface.On("TriggerPermissionsList", mock.Anything, mock.Anything, mock.Anything). @@ -534,7 +534,7 @@ func TestTriggersAccessCommand(t *testing.T) { "set trigger ID through prompt": { CmdArgs: []string{"--everyone"}, ExpectedOutputs: []string{fmt.Sprintf("Trigger '%s'", fakeTriggerID), "everyone"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockAccessAppSelection(installedProdApp) // trigger ID prompt lists available triggers, including current access clientsMock.ApiInterface.On("WorkflowsTriggersList", mock.Anything, mock.Anything, mock.Anything).Return( @@ -578,7 +578,7 @@ func TestTriggersAccessCommand_AppSelection(t *testing.T) { "select an non-installed app": { CmdArgs: []string{"--workflow", "#/workflows/my_workflow"}, ExpectedErrorStrings: []string{cmdutil.DeployedAppNotInstalledMsg}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.AddDefaultMocks() err := clients.AppClient().SaveDeployed(context.Background(), fakeApp) require.NoError(t, err, "Cant write apps.json") diff --git a/cmd/triggers/create_test.go b/cmd/triggers/create_test.go index 64567df5..2733a98f 100644 --- a/cmd/triggers/create_test.go +++ b/cmd/triggers/create_test.go @@ -57,7 +57,7 @@ func TestTriggersCreateCommand(t *testing.T) { "only pass --workflow": { CmdArgs: []string{"--workflow", "#/workflows/my_workflow"}, ExpectedOutputs: []string{"Trigger successfully created!", "My Trigger", "https://app.slack.com/app/" + fakeAppID + "/shortcut/" + fakeTriggerID}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockCreateAppSelection(installedProdApp) // TODO: always a) mock out calls and b) call AddDefaultMocks before making any clients.* calls fakeTrigger := createFakeTrigger(fakeTriggerID, fakeTriggerName, fakeAppID, "shortcut") @@ -90,7 +90,7 @@ func TestTriggersCreateCommand(t *testing.T) { "pass all shortcut parameters": { CmdArgs: []string{"--workflow", "#/workflows/my_workflow", "--title", "unit tests", "--description", "are the best"}, ExpectedOutputs: []string{"Trigger successfully created!", "unit tests", "https://app.slack.com/app/" + fakeAppID + "/shortcut/" + fakeTriggerID}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockCreateAppSelection(installedProdApp) // TODO: always a) mock out calls and b) call AddDefaultMocks before making any clients.* calls fakeTrigger := createFakeTrigger(fakeTriggerID, "unit tests", fakeAppID, "shortcut") @@ -121,7 +121,7 @@ func TestTriggersCreateCommand(t *testing.T) { "pass --interactivity, default name": { CmdArgs: []string{"--workflow", "#/workflows/my_workflow", "--interactivity", "--title", "unit tests", "--description", "are the best"}, ExpectedOutputs: []string{"Trigger successfully created!", "unit tests", "https://app.slack.com/app/" + fakeAppID + "/shortcut/" + fakeTriggerID}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockCreateAppSelection(installedProdApp) // TODO: always a) mock out calls and b) call AddDefaultMocks before making any clients.* calls fakeTrigger := createFakeTrigger(fakeTriggerID, "unit tests", fakeAppID, "shortcut") @@ -157,7 +157,7 @@ func TestTriggersCreateCommand(t *testing.T) { "pass --interactivity, custom name": { CmdArgs: []string{"--workflow", "#/workflows/my_workflow", "--interactivity", "--interactivity-name", "custom-interactivity", "--title", "unit tests", "--description", "are the best"}, ExpectedOutputs: []string{"Trigger successfully created!", "unit tests", "https://app.slack.com/app/" + fakeAppID + "/shortcut/" + fakeTriggerID}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockCreateAppSelection(installedProdApp) // TODO: always a) mock out calls and b) call AddDefaultMocks before making any clients.* calls fakeTrigger := createFakeTrigger(fakeTriggerID, "unit tests", fakeAppID, "shortcut") @@ -193,7 +193,7 @@ func TestTriggersCreateCommand(t *testing.T) { "api call fails": { CmdArgs: []string{"--workflow", "#/workflows/my_workflow"}, ExpectedErrorStrings: []string{"invalid_auth"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockCreateAppSelection(installedProdApp) // TODO: always a) mock out calls and b) call AddDefaultMocks before making any clients.* calls clientsMock.ApiInterface.On("WorkflowsTriggersCreate", mock.Anything, mock.Anything, mock.Anything).Return(types.DeployedTrigger{}, errors.New("invalid_auth")) @@ -209,7 +209,7 @@ func TestTriggersCreateCommand(t *testing.T) { "pass --trigger-def, scheduled trigger": { CmdArgs: []string{"--trigger-def", "trigger_def.json"}, ExpectedOutputs: []string{"Trigger successfully created!", "schedule"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockCreateAppSelection(installedProdApp) // TODO: always a) mock out calls and b) call AddDefaultMocks before making any clients.* calls fakeTrigger := createFakeTrigger(fakeTriggerID, "name", fakeAppID, "scheduled") @@ -251,7 +251,7 @@ func TestTriggersCreateCommand(t *testing.T) { "--trigger-def, file missing": { CmdArgs: []string{"--trigger-def", "foo.json"}, ExpectedErrorStrings: []string{"File not found"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { 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() @@ -266,7 +266,7 @@ func TestTriggersCreateCommand(t *testing.T) { "--trigger-def, not json": { CmdArgs: []string{"--trigger-def", "triggers/shortcut.ts"}, ExpectedOutputs: []string{}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockCreateAppSelection(installedProdApp) clientsMock.ApiInterface.On("WorkflowsTriggersCreate", mock.Anything, mock.Anything, mock.Anything).Return(types.DeployedTrigger{}, nil) clientsMock.ApiInterface.On("ListCollaborators", mock.Anything, mock.Anything, mock.Anything).Return([]types.SlackUser{{}}, nil) @@ -293,7 +293,7 @@ func TestTriggersCreateCommand(t *testing.T) { "--trigger-def, not json, `get-trigger` hook missing": { CmdArgs: []string{"--trigger-def", "triggers/shortcut.ts"}, ExpectedErrorStrings: []string{"sdk_hook_get_trigger_not_found"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { 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() @@ -352,7 +352,7 @@ func TestTriggersCreateCommand_MissingParameters(t *testing.T) { "initial api call fails, missing interactivity, succeeds on retry": { CmdArgs: []string{"--workflow", "#/workflows/my_workflow"}, ExpectedOutputs: []string{"Trigger successfully created!"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockCreateAppSelection(installedProdApp) promptForInteractivityTeardown = setupMockCreatePromptForInteractivity() // TODO: always a) mock out calls and b) call AddDefaultMocks before making any clients.* calls @@ -387,7 +387,7 @@ func TestTriggersCreateCommand_MissingParameters(t *testing.T) { "initial api call fails, missing interactivity, fails on retry": { CmdArgs: []string{"--workflow", "#/workflows/my_workflow"}, ExpectedErrorStrings: []string{"internal_error"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockCreateAppSelection(installedProdApp) promptForInteractivityTeardown = setupMockCreatePromptForInteractivity() // TODO: always a) mock out calls and b) call AddDefaultMocks before making any clients.* calls @@ -418,7 +418,7 @@ func TestTriggersCreateCommand_MissingParameters(t *testing.T) { "initial api call fails, missing a different type": { CmdArgs: []string{"--workflow", "#/workflows/my_workflow"}, ExpectedErrorStrings: []string{"invalid_trigger_inputs"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockCreateAppSelection(installedProdApp) promptForInteractivityTeardown = setupMockCreatePromptForInteractivity() // TODO: always a) mock out calls and b) call AddDefaultMocks before making any clients.* calls @@ -461,7 +461,7 @@ func TestTriggersCreateCommand_AppSelection(t *testing.T) { "selection error": { CmdArgs: []string{"--workflow", "#/workflows/my_workflow"}, ExpectedErrorStrings: []string{"selection error"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.AddDefaultMocks() appSelectTeardown = setupMockCreateAppSelection(newDevApp) appSelectMock := prompts.NewAppSelectMock() @@ -478,7 +478,7 @@ func TestTriggersCreateCommand_AppSelection(t *testing.T) { }, "select a non-installed local app": { CmdArgs: []string{"--workflow", "#/workflows/my_workflow"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { // Define app selector mock to choose local app appSelectTeardown = setupMockCreateAppSelection(newDevApp) // Define app install mock @@ -506,7 +506,7 @@ func TestTriggersCreateCommand_AppSelection(t *testing.T) { }, "select a non-installed prod app": { CmdArgs: []string{"--workflow", "#/workflows/my_workflow"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { // Define app selector mock to choose production app appSelectTeardown = setupMockCreateAppSelection(newProdApp) // Define workspace install mock diff --git a/cmd/triggers/delete_test.go b/cmd/triggers/delete_test.go index f85878db..2d637fd3 100644 --- a/cmd/triggers/delete_test.go +++ b/cmd/triggers/delete_test.go @@ -37,7 +37,7 @@ func TestTriggersDeleteCommand(t *testing.T) { "no params; use prompts to successfully delete": { CmdArgs: []string{}, ExpectedOutputs: []string{}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockDeleteAppSelection(installedProdApp) clientsMock.AddDefaultMocks() // promptForTriggerID lists available triggers @@ -53,7 +53,7 @@ func TestTriggersDeleteCommand(t *testing.T) { "app not installed": { CmdArgs: []string{"--trigger-id", fakeTriggerID}, ExpectedErrorStrings: []string{cmdutil.DeployedAppNotInstalledMsg}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockDeleteAppSelection(newProdApp) clientsMock.AddDefaultMocks() }, @@ -64,7 +64,7 @@ func TestTriggersDeleteCommand(t *testing.T) { "pass --trigger-id, success": { CmdArgs: []string{"--trigger-id", fakeTriggerID}, ExpectedOutputs: []string{"Trigger '" + fakeTriggerID + "' deleted"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockDeleteAppSelection(installedProdApp) clientsMock.ApiInterface.On("WorkflowsTriggersDelete", mock.Anything, mock.Anything, mock.Anything).Return(nil) // TODO: testing chicken and egg: we need the default mocks in place before we can use any of the `clients` methods @@ -84,7 +84,7 @@ func TestTriggersDeleteCommand(t *testing.T) { "pass --trigger-id, failure": { CmdArgs: []string{"--trigger-id", fakeTriggerID}, ExpectedErrorStrings: []string{"invalid_auth"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockDeleteAppSelection(installedProdApp) 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 @@ -112,7 +112,7 @@ func TestTriggersDeleteCommand_AppSelection(t *testing.T) { "selection error": { CmdArgs: []string{"--trigger-id", "Ft01435GGLBD"}, ExpectedErrorStrings: []string{"selection error"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.AddDefaultMocks() appSelectTeardown = setupMockDeleteAppSelection(installedProdApp) appSelectMock := prompts.NewAppSelectMock() @@ -126,7 +126,7 @@ func TestTriggersDeleteCommand_AppSelection(t *testing.T) { "select a non-installed local app": { CmdArgs: []string{"--trigger-id", "Ft01435GGLBD"}, ExpectedErrorStrings: []string{cmdutil.LocalAppNotInstalledMsg}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { 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 @@ -142,7 +142,7 @@ func TestTriggersDeleteCommand_AppSelection(t *testing.T) { "select a non-installed prod app": { CmdArgs: []string{"--trigger-id", "Ft01435GGLBD"}, ExpectedErrorStrings: []string{cmdutil.DeployedAppNotInstalledMsg}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { 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 diff --git a/cmd/triggers/info_test.go b/cmd/triggers/info_test.go index bfb39695..c4046e16 100644 --- a/cmd/triggers/info_test.go +++ b/cmd/triggers/info_test.go @@ -36,7 +36,7 @@ func TestTriggersInfoCommand(t *testing.T) { testutil.TableTestCommand(t, testutil.CommandTests{ "no params; use prompts to select a trigger": { CmdArgs: []string{}, - Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { appSelectTeardown = setupMockInfoAppSelection(installedProdApp) mockRequestTrigger := createFakeTrigger(fakeTriggerID, "test trigger", "test app", "shortcut") // promptForTriggerID lists available triggers @@ -60,7 +60,7 @@ func TestTriggersInfoCommand(t *testing.T) { "app not installed": { CmdArgs: []string{"--trigger-id", fakeTriggerID}, ExpectedErrorStrings: []string{cmdutil.DeployedAppNotInstalledMsg}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockInfoAppSelection(newProdApp) clientsMock.AddDefaultMocks() }, @@ -75,7 +75,7 @@ func TestTriggersInfoCommand(t *testing.T) { fakeTriggerID, "everyone in the workspace", }, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockInfoAppSelection(installedProdApp) mockRequestTrigger := createFakeTrigger(fakeTriggerID, "test trigger", "test app", "shortcut") clientsMock.ApiInterface.On("WorkflowsTriggersInfo", mock.Anything, mock.Anything, mock.Anything).Return(mockRequestTrigger, nil) @@ -100,7 +100,7 @@ func TestTriggersInfoCommand(t *testing.T) { fakeTriggerID, "everyone in all workspaces in this org granted to this app", }, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockInfoAppSelection(installedProdOrgApp) mockRequestTrigger := createFakeTrigger(fakeTriggerID, "test trigger", "test app", "shortcut") clientsMock.ApiInterface.On("WorkflowsTriggersInfo", mock.Anything, mock.Anything, mock.Anything).Return(mockRequestTrigger, nil) @@ -121,7 +121,7 @@ func TestTriggersInfoCommand(t *testing.T) { "pass --trigger-id, failure": { CmdArgs: []string{"--trigger-id", fakeTriggerID}, ExpectedErrorStrings: []string{"invalid_auth"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockInfoAppSelection(installedProdApp) 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 @@ -138,7 +138,7 @@ func TestTriggersInfoCommand(t *testing.T) { }, "event trigger displays hints and warnings": { CmdArgs: []string{"--trigger-id", fakeTriggerID}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockInfoAppSelection(installedProdApp) mockRequestTrigger := createFakeTrigger(fakeTriggerID, "test trigger", "test app", "event") clientsMock.ApiInterface.On("WorkflowsTriggersInfo", mock.Anything, mock.Anything, mock.Anything).Return(mockRequestTrigger, nil) @@ -175,7 +175,7 @@ func TestTriggersInfoCommand_AppSelection(t *testing.T) { "selection error": { CmdArgs: []string{"--trigger-id", "Ft01435GGLBD"}, ExpectedErrorStrings: []string{"Error"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { clientsMock.AddDefaultMocks() appSelectTeardown = setupMockInfoAppSelection(newDevApp) appSelectMock := prompts.NewAppSelectMock() @@ -193,7 +193,7 @@ func TestTriggersInfoCommand_AppSelection(t *testing.T) { "select an non-installed local app": { CmdArgs: []string{"--trigger-id", "Ft01435GGLBD"}, ExpectedErrorStrings: []string{cmdutil.LocalAppNotInstalledMsg}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { 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 @@ -209,7 +209,7 @@ func TestTriggersInfoCommand_AppSelection(t *testing.T) { "select an non-installed prod app": { CmdArgs: []string{"--trigger-id", "Ft01435GGLBD"}, ExpectedErrorStrings: []string{cmdutil.DeployedAppNotInstalledMsg}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { 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 diff --git a/cmd/triggers/list_test.go b/cmd/triggers/list_test.go index 5ebd9c65..96be2299 100644 --- a/cmd/triggers/list_test.go +++ b/cmd/triggers/list_test.go @@ -15,6 +15,7 @@ package triggers import ( + "context" "fmt" "testing" @@ -34,7 +35,7 @@ func TestTriggersListCommand(t *testing.T) { testutil.TableTestCommand(t, testutil.CommandTests{ "list no triggers": { CmdArgs: []string{}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockListAppSelection(installedProdApp) // Mock API responses @@ -62,7 +63,7 @@ func TestTriggersListCommand(t *testing.T) { "list one trigger for a workspace app": { CmdArgs: []string{}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockListAppSelection(installedProdApp) // Mock API responses @@ -99,7 +100,7 @@ func TestTriggersListCommand(t *testing.T) { "list one trigger for an org app": { CmdArgs: []string{}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockListAppSelection(installedProdOrgApp) // Mock API responses @@ -136,7 +137,7 @@ func TestTriggersListCommand(t *testing.T) { "list multiple triggers": { CmdArgs: []string{}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockListAppSelection(installedProdApp) // Mock API responses diff --git a/cmd/triggers/update_test.go b/cmd/triggers/update_test.go index 9bb68bf9..3cd0449d 100644 --- a/cmd/triggers/update_test.go +++ b/cmd/triggers/update_test.go @@ -39,7 +39,7 @@ func TestTriggersUpdateCommand(t *testing.T) { "with prompts": { CmdArgs: []string{}, ExpectedOutputs: []string{"Trigger successfully updated!", fakeTriggerName, "https://app.slack.com/app/" + fakeAppID + "/shortcut/" + fakeTriggerID}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockUpdateAppSelection(installedProdApp) clientsMock.AddDefaultMocks() // Prompt for Trigger ID @@ -75,7 +75,7 @@ func TestTriggersUpdateCommand(t *testing.T) { "hosted app not installed": { CmdArgs: []string{"--trigger-id", fakeTriggerID, "--workflow", "#/workflows/my_workflow"}, ExpectedErrorStrings: []string{cmdutil.DeployedAppNotInstalledMsg}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { 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 @@ -91,7 +91,7 @@ func TestTriggersUpdateCommand(t *testing.T) { "local app not installed": { CmdArgs: []string{"--trigger-id", fakeTriggerID, "--workflow", "#/workflows/my_workflow"}, ExpectedErrorStrings: []string{cmdutil.LocalAppNotInstalledMsg}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { 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 @@ -107,7 +107,7 @@ func TestTriggersUpdateCommand(t *testing.T) { "only pass --workflow and --trigger-id": { CmdArgs: []string{"--trigger-id", fakeTriggerID, "--workflow", "#/workflows/my_workflow"}, ExpectedOutputs: []string{"Trigger successfully updated!", fakeTriggerName, "https://app.slack.com/app/" + fakeAppID + "/shortcut/" + fakeTriggerID}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockUpdateAppSelection(installedProdApp) // TODO: always a) mock out calls and b) call AddDefaultMocks before making any clients.* calls fakeTrigger := createFakeTrigger(fakeTriggerID, fakeTriggerName, fakeAppID, "shortcut") @@ -143,7 +143,7 @@ func TestTriggersUpdateCommand(t *testing.T) { "only pass --workflow and --trigger-id, with interactivity": { CmdArgs: []string{"--trigger-id", fakeTriggerID, "--workflow", "#/workflows/my_workflow", "--interactivity"}, ExpectedOutputs: []string{"Trigger successfully updated!", fakeTriggerName, "https://app.slack.com/app/" + fakeAppID + "/shortcut/" + fakeTriggerID}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockUpdateAppSelection(installedProdApp) // TODO: always a) mock out calls and b) call AddDefaultMocks before making any clients.* calls fakeTrigger := createFakeTrigger(fakeTriggerID, fakeTriggerName, fakeAppID, "shortcut") @@ -184,7 +184,7 @@ func TestTriggersUpdateCommand(t *testing.T) { "only pass --workflow and --trigger-id, with interactivity and custom name": { CmdArgs: []string{"--trigger-id", fakeTriggerID, "--workflow", "#/workflows/my_workflow", "--interactivity", "--interactivity-name", "custom-interactivity"}, ExpectedOutputs: []string{"Trigger successfully updated!", fakeTriggerName, "https://app.slack.com/app/" + fakeAppID + "/shortcut/" + fakeTriggerID}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockUpdateAppSelection(installedProdApp) // TODO: always a) mock out calls and b) call AddDefaultMocks before making any clients.* calls fakeTrigger := createFakeTrigger(fakeTriggerID, fakeTriggerName, fakeAppID, "shortcut") @@ -225,7 +225,7 @@ func TestTriggersUpdateCommand(t *testing.T) { "pass all shortcut parameters": { CmdArgs: []string{"--trigger-id", fakeTriggerID, "--workflow", "#/workflows/my_workflow", "--title", "unit tests", "--description", "are the best"}, ExpectedOutputs: []string{"Trigger successfully updated!", "unit tests", "https://app.slack.com/app/" + fakeAppID + "/shortcut/" + fakeTriggerID}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockUpdateAppSelection(installedProdApp) // TODO: always a) mock out calls and b) call AddDefaultMocks before making any clients.* calls fakeTrigger := createFakeTrigger(fakeTriggerID, "unit tests", fakeAppID, "shortcut") @@ -259,7 +259,7 @@ func TestTriggersUpdateCommand(t *testing.T) { "api call fails": { CmdArgs: []string{"--trigger-id", fakeTriggerID, "--workflow", "#/workflows/my_workflow"}, ExpectedErrorStrings: []string{"invalid_auth"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockUpdateAppSelection(installedProdApp) 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 @@ -274,7 +274,7 @@ func TestTriggersUpdateCommand(t *testing.T) { "pass --trigger-def, scheduled trigger": { CmdArgs: []string{"--trigger-id", fakeTriggerID, "--trigger-def", "trigger_def.json"}, ExpectedOutputs: []string{"Trigger successfully updated!", "schedule"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockUpdateAppSelection(installedProdApp) // TODO: always a) mock out calls and b) call AddDefaultMocks before making any clients.* calls fakeTrigger := createFakeTrigger(fakeTriggerID, "name", fakeAppID, "scheduled") @@ -318,7 +318,7 @@ func TestTriggersUpdateCommand(t *testing.T) { "--trigger-def, file missing": { CmdArgs: []string{"--trigger-id", fakeTriggerID, "--trigger-def", "foo.json"}, ExpectedErrorStrings: []string{"File not found"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { 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() @@ -332,7 +332,7 @@ func TestTriggersUpdateCommand(t *testing.T) { "--trigger-def, not json": { CmdArgs: []string{"--trigger-id", fakeTriggerID, "--trigger-def", "triggers/shortcut.ts"}, ExpectedErrorStrings: []string{"unexpected end of JSON"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockUpdateAppSelection(installedProdApp) clientsMock.ApiInterface.On("WorkflowsTriggersUpdate", mock.Anything, mock.Anything, mock.Anything).Return(types.DeployedTrigger{}, nil) clientsMock.ApiInterface.On("ListCollaborators", mock.Anything, mock.Anything, mock.Anything).Return([]types.SlackUser{}, nil) @@ -404,7 +404,7 @@ func TestTriggersUpdateCommand_MissingParameters(t *testing.T) { "initial api call fails, missing interactivity, succeeds on retry": { CmdArgs: []string{"--trigger-id", fakeTriggerID, "--workflow", "#/workflows/my_workflow"}, ExpectedOutputs: []string{"Trigger successfully updated!"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockUpdateAppSelection(installedProdApp) promptForInteractivityTeardown = setupMockUpdatePromptForInteractivity() // TODO: always a) mock out calls and b) call AddDefaultMocks before making any clients.* calls @@ -439,7 +439,7 @@ func TestTriggersUpdateCommand_MissingParameters(t *testing.T) { "initial api call fails, missing interactivity, fails on retry": { CmdArgs: []string{"--trigger-id", fakeTriggerID, "--workflow", "#/workflows/my_workflow"}, ExpectedErrorStrings: []string{"internal_error"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockUpdateAppSelection(installedProdApp) promptForInteractivityTeardown = setupMockUpdatePromptForInteractivity() // TODO: always a) mock out calls and b) call AddDefaultMocks before making any clients.* calls @@ -470,7 +470,7 @@ func TestTriggersUpdateCommand_MissingParameters(t *testing.T) { "initial api call fails, missing a different type": { CmdArgs: []string{"--trigger-id", fakeTriggerID, "--workflow", "#/workflows/my_workflow"}, ExpectedErrorStrings: []string{"invalid_trigger_inputs"}, - Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { + Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) { appSelectTeardown = setupMockUpdateAppSelection(installedProdApp) promptForInteractivityTeardown = setupMockUpdatePromptForInteractivity() // TODO: always a) mock out calls and b) call AddDefaultMocks before making any clients.* calls diff --git a/test/testutil/commandtests.go b/test/testutil/commandtests.go index f9ad04b4..4f5f147c 100644 --- a/test/testutil/commandtests.go +++ b/test/testutil/commandtests.go @@ -15,11 +15,13 @@ package testutil import ( + "context" "fmt" "strings" "testing" "github.com/slackapi/slack-cli/internal/shared" + "github.com/slackapi/slack-cli/internal/slackcontext" "github.com/spf13/cobra" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -27,14 +29,14 @@ import ( // CommandTests describes a single test case for a command. type CommandTests map[string]struct { - Setup func(*testing.T, *shared.ClientsMock, *shared.ClientFactory) // Optional - Teardown func() // Optional - 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 - ExpectedError error // Optional - ExpectedErrorStrings []string // Optional + Setup func(*testing.T, context.Context, *shared.ClientsMock, *shared.ClientFactory) // Optional + Teardown func() // Optional + 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 + ExpectedError error // Optional + ExpectedErrorStrings []string // Optional } // TableTestCommand will run a table test collection defined by commandTests for a command created by newCommandFunc @@ -42,6 +44,7 @@ func TableTestCommand(t *testing.T, commandTests CommandTests, newCommandFunc fu for name, tt := range commandTests { t.Run(name, func(t *testing.T) { // Create mocks + ctxMock := slackcontext.MockContext(t.Context()) clientsMock := shared.NewClientsMock() // Create clients that is mocked for testing @@ -54,7 +57,7 @@ func TableTestCommand(t *testing.T, commandTests CommandTests, newCommandFunc fu // Setup custom mocks (higher priority than default mocks) if tt.Setup != nil { - tt.Setup(t, clientsMock, clients) + tt.Setup(t, ctxMock, clientsMock, clients) } // Setup default mock actions @@ -62,7 +65,7 @@ func TableTestCommand(t *testing.T, commandTests CommandTests, newCommandFunc fu // Execute the command cmd.SetArgs(tt.CmdArgs) - err := cmd.Execute() + err := cmd.ExecuteContext(ctxMock) // Test failure mode if tt.ExpectedError != nil || tt.ExpectedErrorStrings != nil {