-
Notifications
You must be signed in to change notification settings - Fork 24
test: mock context in TableTestCommand.ExpectedAsserts #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4add4cc
6c8907a
f7b9014
b8f68e9
9c816be
5f69d23
c4b7697
ad91292
8b92a2a
d0aa8ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -95,15 +95,15 @@ func Test_Apps_Link(t *testing.T) { | |
| ).Return(api.GetAppStatusResult{}, nil) | ||
| }, | ||
| CmdArgs: []string{}, | ||
| ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { | ||
| ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { | ||
| expectedApp := types.App{ | ||
| AppID: mockLinkAppID1, | ||
| TeamDomain: mockLinkSlackAuth1.TeamDomain, | ||
| TeamID: mockLinkSlackAuth1.TeamID, | ||
| EnterpriseID: mockLinkSlackAuth1.EnterpriseID, | ||
| } | ||
| actualApp, err := cm.AppClient.GetDeployed( | ||
| context.Background(), | ||
| ctx, | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: The main motivation of this PR is to replace
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replacing these instances with the shared mock |
||
| mockLinkSlackAuth1.TeamID, | ||
| ) | ||
| require.NoError(t, err) | ||
|
|
@@ -153,7 +153,7 @@ func Test_Apps_Link(t *testing.T) { | |
| ).Return(api.GetAppStatusResult{}, nil) | ||
| }, | ||
| CmdArgs: []string{}, | ||
| ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { | ||
| ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { | ||
| expectedApp := types.App{ | ||
| AppID: mockLinkAppID2, | ||
| TeamDomain: mockLinkSlackAuth2.TeamDomain, | ||
|
|
@@ -162,7 +162,7 @@ func Test_Apps_Link(t *testing.T) { | |
| UserID: mockLinkSlackAuth2.UserID, | ||
| } | ||
| actualApp, err := cm.AppClient.GetLocal( | ||
| context.Background(), | ||
| ctx, | ||
| mockLinkSlackAuth2.TeamID, | ||
| ) | ||
| require.NoError(t, err) | ||
|
|
@@ -220,15 +220,15 @@ func Test_Apps_Link(t *testing.T) { | |
| ).Return(api.GetAppStatusResult{}, nil) | ||
| }, | ||
| CmdArgs: []string{}, | ||
| ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { | ||
| ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { | ||
| expectedApp := types.App{ | ||
| AppID: mockLinkAppID1, | ||
| TeamDomain: mockLinkSlackAuth1.TeamDomain, | ||
| TeamID: mockLinkSlackAuth1.TeamID, | ||
| EnterpriseID: mockLinkSlackAuth1.EnterpriseID, | ||
| } | ||
| actualApp, err := cm.AppClient.GetDeployed( | ||
| context.Background(), | ||
| ctx, | ||
| mockLinkSlackAuth1.TeamID, | ||
| ) | ||
| require.NoError(t, err) | ||
|
|
@@ -289,21 +289,21 @@ func Test_Apps_Link(t *testing.T) { | |
| ).Return(api.GetAppStatusResult{}, nil) | ||
| }, | ||
| CmdArgs: []string{}, | ||
| ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { | ||
| ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { | ||
| expectedApp := types.App{ | ||
| AppID: mockLinkAppID1, | ||
| TeamDomain: mockLinkSlackAuth1.TeamDomain, | ||
| TeamID: mockLinkSlackAuth1.TeamID, | ||
| EnterpriseID: mockLinkSlackAuth1.EnterpriseID, | ||
| } | ||
| actualApp, err := cm.AppClient.GetDeployed( | ||
| context.Background(), | ||
| ctx, | ||
| mockLinkSlackAuth1.TeamID, | ||
| ) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, expectedApp, actualApp) | ||
| unsavedApp, err := cm.AppClient.GetLocal( | ||
| context.Background(), | ||
| ctx, | ||
| mockLinkSlackAuth1.TeamID, | ||
| ) | ||
| require.NoError(t, err) | ||
|
|
@@ -365,7 +365,7 @@ func Test_Apps_Link(t *testing.T) { | |
| ).Return(api.GetAppStatusResult{}, nil) | ||
| }, | ||
| CmdArgs: []string{"--force"}, | ||
| ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { | ||
| ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { | ||
| expectedApp := types.App{ | ||
| AppID: mockLinkAppID1, | ||
| TeamDomain: mockLinkSlackAuth2.TeamDomain, | ||
|
|
@@ -374,7 +374,7 @@ func Test_Apps_Link(t *testing.T) { | |
| UserID: mockLinkSlackAuth2.UserID, | ||
| } | ||
| actualApp, err := cm.AppClient.GetLocal( | ||
| context.Background(), | ||
| ctx, | ||
| mockLinkSlackAuth2.TeamID, | ||
| ) | ||
| require.NoError(t, err) | ||
|
|
@@ -481,15 +481,15 @@ func Test_Apps_Link(t *testing.T) { | |
| ).Return(api.GetAppStatusResult{}, nil) | ||
| }, | ||
| CmdArgs: []string{}, | ||
| ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { | ||
| ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { | ||
| expectedApp := types.App{ | ||
| AppID: mockLinkAppID1, | ||
| TeamDomain: mockLinkSlackAuth1.TeamDomain, | ||
| TeamID: mockLinkSlackAuth1.TeamID, | ||
| EnterpriseID: mockLinkSlackAuth1.EnterpriseID, | ||
| } | ||
| actualApp, err := cm.AppClient.GetDeployed( | ||
| context.Background(), | ||
| ctx, | ||
| mockLinkSlackAuth1.TeamID, | ||
| ) | ||
| require.NoError(t, err) | ||
|
|
@@ -518,9 +518,7 @@ func Test_Apps_Link(t *testing.T) { | |
| ).Return(false, nil) | ||
| }, | ||
| CmdArgs: []string{}, | ||
| ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { | ||
| ctx := t.Context() | ||
|
|
||
| ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { | ||
| // Assert manifest confirmation prompt accepted | ||
| cm.IO.AssertCalled(t, "ConfirmPrompt", | ||
| mock.Anything, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,13 +39,13 @@ func TestAddCommand(t *testing.T) { | |
| appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{App: types.App{AppID: "A123"}, Auth: types.SlackAuth{}}, nil) | ||
| // Set experiment flag | ||
| cm.Config.ExperimentsFlag = append(cm.Config.ExperimentsFlag, "read-only-collaborators") | ||
| cm.Config.LoadExperiments(context.Background(), cm.IO.PrintDebug) | ||
| cm.Config.LoadExperiments(ctx, cm.IO.PrintDebug) | ||
| // Mock API call | ||
| cm.ApiInterface.On("AddCollaborator", mock.Anything, mock.Anything, | ||
| "A123", | ||
| types.SlackUser{ID: "U123", PermissionType: types.READER}).Return(nil) | ||
| }, | ||
| ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { | ||
| ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { | ||
| cm.ApiInterface.AssertCalled(t, "AddCollaborator", mock.Anything, mock.Anything, | ||
| "A123", | ||
| types.SlackUser{ID: "U123", PermissionType: types.READER}) | ||
|
|
@@ -63,14 +63,14 @@ func TestAddCommand(t *testing.T) { | |
| appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{App: types.App{AppID: "A123"}, Auth: types.SlackAuth{}}, nil) | ||
| // Set experiment flag | ||
| cm.Config.ExperimentsFlag = append(cm.Config.ExperimentsFlag, "read-only-collaborators") | ||
| cm.Config.LoadExperiments(context.Background(), cm.IO.PrintDebug) | ||
| cm.Config.LoadExperiments(ctx, cm.IO.PrintDebug) | ||
| // Mock API call | ||
| cm.ApiInterface.On("AddCollaborator", mock.Anything, mock.Anything, | ||
| "A123", | ||
| types.SlackUser{Email: "[email protected]", PermissionType: types.OWNER}).Return(nil) | ||
| addFlags.permissionType = "owner" | ||
| }, | ||
| ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { | ||
| ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { | ||
| cm.ApiInterface.AssertCalled(t, "AddCollaborator", mock.Anything, mock.Anything, | ||
| "A123", | ||
| types.SlackUser{Email: "[email protected]", PermissionType: types.OWNER}) | ||
|
|
@@ -90,7 +90,7 @@ func TestAddCommand(t *testing.T) { | |
| cm.ApiInterface.On("AddCollaborator", mock.Anything, mock.Anything, mock.Anything, mock.Anything). | ||
| Return(nil) | ||
| }, | ||
| ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { | ||
| ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { | ||
| cm.ApiInterface.AssertCalled(t, "AddCollaborator", mock.Anything, mock.Anything, | ||
| "A123", | ||
| types.SlackUser{Email: "[email protected]", PermissionType: types.OWNER}) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,7 +59,7 @@ func TestRemoveCommand(t *testing.T) { | |
| cm.ApiInterface.On("RemoveCollaborator", mock.Anything, mock.Anything, mock.Anything, mock.Anything). | ||
| Return(nil) | ||
| }, | ||
| ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { | ||
| ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { | ||
| collaborator := types.SlackUser{ | ||
| ID: "USLACKBOT", | ||
| } | ||
|
|
@@ -83,7 +83,7 @@ func TestRemoveCommand(t *testing.T) { | |
| cm.IO.On("SelectPrompt", mock.Anything, "Remove a collaborator", mock.Anything, mock.Anything). | ||
| Return(iostreams.SelectPromptResponse{Prompt: true, Index: 1}, nil) | ||
| }, | ||
| ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { | ||
| ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { | ||
| cm.ApiInterface.AssertCalled(t, "RemoveCollaborator", mock.Anything, mock.Anything, "A001", mockCollaborators[1]) | ||
| cm.IO.AssertCalled(t, "PrintTrace", mock.Anything, slacktrace.CollaboratorRemoveSuccess, mock.Anything) | ||
| cm.IO.AssertCalled(t, "PrintTrace", mock.Anything, slacktrace.CollaboratorRemoveCollaborator, []string{"[email protected]"}) | ||
|
|
@@ -106,7 +106,7 @@ func TestRemoveCommand(t *testing.T) { | |
| cm.IO.On("ConfirmPrompt", mock.Anything, "Are you sure you want to remove yourself?", mock.Anything, mock.Anything). | ||
| Return(false, nil) | ||
| }, | ||
| ExpectedAsserts: func(t *testing.T, cm *shared.ClientsMock) { | ||
| ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { | ||
| cm.ApiInterface.AssertNotCalled(t, "RemoveCollaborator", mock.Anything, mock.Anything, mock.Anything, mock.Anything) | ||
| }, | ||
| ExpectedError: slackerror.New(slackerror.ErrProcessInterrupted), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: Every reference to
ExpectedAsserts: func(...)had to be updated to includectx. 🔁There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another tedious change - thanks for rolling up the sleeves - but this matches actual command execution so much better 🙏 ✨