Skip to content

Commit 66766a9

Browse files
authored
refactor(tests): use consistent naming in table tests with the map pattern (#316)
1 parent 14fe964 commit 66766a9

File tree

106 files changed

+1510
-1510
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+1510
-1510
lines changed

cmd/app/link_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ func Test_Apps_LinkAppHeaderSection(t *testing.T) {
722722
},
723723
},
724724
}
725-
for name, tt := range tests {
725+
for name, tc := range tests {
726726
t.Run(name, func(t *testing.T) {
727727
// Create mocks
728728
ctx := slackcontext.MockContext(t.Context())
@@ -733,14 +733,14 @@ func Test_Apps_LinkAppHeaderSection(t *testing.T) {
733733
clients := shared.NewClientFactory(clientsMock.MockClientFactory())
734734

735735
// Run the test
736-
LinkAppHeaderSection(ctx, clients, tt.shouldConfirm)
736+
LinkAppHeaderSection(ctx, clients, tc.shouldConfirm)
737737

738738
// Assertions
739739
output := clientsMock.GetCombinedOutput()
740-
for _, expectedOutput := range tt.expectedOutputs {
740+
for _, expectedOutput := range tc.expectedOutputs {
741741
require.Contains(t, output, expectedOutput)
742742
}
743-
for _, unexpectedOutput := range tt.unexpectedOutputs {
743+
for _, unexpectedOutput := range tc.unexpectedOutputs {
744744
require.NotContains(t, output, unexpectedOutput)
745745
}
746746
})

cmd/app/list_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,14 @@ func TestAppsListFormat(t *testing.T) {
215215
},
216216
}
217217

218-
for name, tt := range tests {
218+
for name, tc := range tests {
219219
t.Run(name, func(t *testing.T) {
220-
listFlags = tt.Flags
221-
formattedList := formatListSuccess(tt.Apps)
220+
listFlags = tc.Flags
221+
formattedList := formatListSuccess(tc.Apps)
222222
for ii, value := range formattedList {
223223
formattedList[ii] = strings.TrimRight(value, ":")
224224
}
225-
for _, value := range tt.Expected {
225+
for _, value := range tc.Expected {
226226
assert.Contains(t, strings.Join(formattedList, "\n"), value)
227227
}
228228
})

cmd/collaborators/collaborators_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,28 +98,28 @@ func TestCollaboratorsCommand(t *testing.T) {
9898
},
9999
}
100100

101-
for name, tt := range tests {
101+
for name, tc := range tests {
102102
t.Run(name, func(t *testing.T) {
103103
ctx := slackcontext.MockContext(t.Context())
104104
appSelectMock := prompts.NewAppSelectMock()
105105
appSelectPromptFunc = appSelectMock.AppSelectPrompt
106-
appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowHostedOnly, prompts.ShowInstalledAndUninstalledApps).Return(prompts.SelectedApp{App: tt.app, Auth: types.SlackAuth{}}, nil)
106+
appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowHostedOnly, prompts.ShowInstalledAndUninstalledApps).Return(prompts.SelectedApp{App: tc.app, Auth: types.SlackAuth{}}, nil)
107107
clientsMock := shared.NewClientsMock()
108108
clientsMock.AddDefaultMocks()
109109
clientsMock.API.On("ListCollaborators", mock.Anything, mock.Anything, mock.Anything).
110-
Return(tt.collaborators, nil)
110+
Return(tc.collaborators, nil)
111111
clients := shared.NewClientFactory(clientsMock.MockClientFactory(), func(clients *shared.ClientFactory) {
112112
clients.SDKConfig = hooks.NewSDKConfigMock()
113113
})
114114

115115
err := NewCommand(clients).ExecuteContext(ctx)
116116
require.NoError(t, err)
117-
clientsMock.API.AssertCalled(t, "ListCollaborators", mock.Anything, mock.Anything, tt.app.AppID)
117+
clientsMock.API.AssertCalled(t, "ListCollaborators", mock.Anything, mock.Anything, tc.app.AppID)
118118
clientsMock.IO.AssertCalled(t, "PrintTrace", mock.Anything, slacktrace.CollaboratorListSuccess, mock.Anything)
119119
clientsMock.IO.AssertCalled(t, "PrintTrace", mock.Anything, slacktrace.CollaboratorListCount, []string{
120-
fmt.Sprintf("%d", len(tt.collaborators)),
120+
fmt.Sprintf("%d", len(tc.collaborators)),
121121
})
122-
for _, collaborator := range tt.collaborators {
122+
for _, collaborator := range tc.collaborators {
123123
clientsMock.IO.AssertCalled(t, "PrintTrace", mock.Anything, slacktrace.CollaboratorListCollaborator, []string{
124124
collaborator.ID,
125125
collaborator.UserName,
@@ -128,7 +128,7 @@ func TestCollaboratorsCommand(t *testing.T) {
128128
})
129129
}
130130
output := clientsMock.GetCombinedOutput()
131-
for _, expectedOutput := range tt.expectedOutputs {
131+
for _, expectedOutput := range tc.expectedOutputs {
132132
require.Contains(t, output, expectedOutput)
133133
}
134134
})

cmd/collaborators/list_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,28 +98,28 @@ func TestListCommand(t *testing.T) {
9898
},
9999
}
100100

101-
for name, tt := range tests {
101+
for name, tc := range tests {
102102
t.Run(name, func(t *testing.T) {
103103
ctx := slackcontext.MockContext(t.Context())
104104
appSelectMock := prompts.NewAppSelectMock()
105105
appSelectPromptFunc = appSelectMock.AppSelectPrompt
106-
appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowHostedOnly, prompts.ShowInstalledAndUninstalledApps).Return(prompts.SelectedApp{App: tt.app, Auth: types.SlackAuth{}}, nil)
106+
appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowHostedOnly, prompts.ShowInstalledAndUninstalledApps).Return(prompts.SelectedApp{App: tc.app, Auth: types.SlackAuth{}}, nil)
107107
clientsMock := shared.NewClientsMock()
108108
clientsMock.AddDefaultMocks()
109109
clientsMock.API.On("ListCollaborators", mock.Anything, mock.Anything, mock.Anything).
110-
Return(tt.collaborators, nil)
110+
Return(tc.collaborators, nil)
111111
clients := shared.NewClientFactory(clientsMock.MockClientFactory(), func(clients *shared.ClientFactory) {
112112
clients.SDKConfig = hooks.NewSDKConfigMock()
113113
})
114114

115115
err := NewListCommand(clients).ExecuteContext(ctx)
116116
require.NoError(t, err)
117-
clientsMock.API.AssertCalled(t, "ListCollaborators", mock.Anything, mock.Anything, tt.app.AppID)
117+
clientsMock.API.AssertCalled(t, "ListCollaborators", mock.Anything, mock.Anything, tc.app.AppID)
118118
clientsMock.IO.AssertCalled(t, "PrintTrace", mock.Anything, slacktrace.CollaboratorListSuccess, mock.Anything)
119119
clientsMock.IO.AssertCalled(t, "PrintTrace", mock.Anything, slacktrace.CollaboratorListCount, []string{
120-
fmt.Sprintf("%d", len(tt.collaborators)),
120+
fmt.Sprintf("%d", len(tc.collaborators)),
121121
})
122-
for _, collaborator := range tt.collaborators {
122+
for _, collaborator := range tc.collaborators {
123123
clientsMock.IO.AssertCalled(t, "PrintTrace", mock.Anything, slacktrace.CollaboratorListCollaborator, []string{
124124
collaborator.ID,
125125
collaborator.UserName,
@@ -128,7 +128,7 @@ func TestListCommand(t *testing.T) {
128128
})
129129
}
130130
output := clientsMock.GetCombinedOutput()
131-
for _, expectedOutput := range tt.expectedOutputs {
131+
for _, expectedOutput := range tc.expectedOutputs {
132132
require.Contains(t, output, expectedOutput)
133133
}
134134
})

cmd/datastore/bulk_delete_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func TestBulkDeleteCommandPreRun(t *testing.T) {
102102
expectedError: slackerror.New(slackerror.ErrAppNotHosted),
103103
},
104104
}
105-
for name, tt := range tests {
105+
for name, tc := range tests {
106106
t.Run(name, func(t *testing.T) {
107107
clientsMock := shared.NewClientsMock()
108108
manifestMock := &app.ManifestMockObject{}
@@ -112,27 +112,27 @@ func TestBulkDeleteCommandPreRun(t *testing.T) {
112112
mock.Anything,
113113
mock.Anything,
114114
).Return(
115-
tt.mockManifestResponse,
116-
tt.mockManifestError,
115+
tc.mockManifestResponse,
116+
tc.mockManifestError,
117117
)
118118
clientsMock.AppClient.Manifest = manifestMock
119119
projectConfigMock := config.NewProjectConfigMock()
120120
projectConfigMock.On(
121121
"GetManifestSource",
122122
mock.Anything,
123123
).Return(
124-
tt.mockManifestSource,
124+
tc.mockManifestSource,
125125
nil,
126126
)
127127
clientsMock.Config.ProjectConfig = projectConfigMock
128128
clients := shared.NewClientFactory(clientsMock.MockClientFactory(), func(cf *shared.ClientFactory) {
129-
cf.Config.ForceFlag = tt.mockFlagForce
130-
cf.SDKConfig.WorkingDirectory = tt.mockWorkingDirectory
129+
cf.Config.ForceFlag = tc.mockFlagForce
130+
cf.SDKConfig.WorkingDirectory = tc.mockWorkingDirectory
131131
})
132132
cmd := NewBulkDeleteCommand(clients)
133133
err := cmd.PreRunE(cmd, nil)
134-
if tt.expectedError != nil {
135-
assert.Equal(t, slackerror.ToSlackError(tt.expectedError).Code, slackerror.ToSlackError(err).Code)
134+
if tc.expectedError != nil {
135+
assert.Equal(t, slackerror.ToSlackError(tc.expectedError).Code, slackerror.ToSlackError(err).Code)
136136
} else {
137137
assert.NoError(t, err)
138138
}
@@ -173,12 +173,12 @@ func TestBulkDeleteCommand(t *testing.T) {
173173
},
174174
},
175175
}
176-
for name, tt := range tests {
176+
for name, tc := range tests {
177177
t.Run(name, func(t *testing.T) {
178178
ctx := slackcontext.MockContext(t.Context())
179179
clientsMock := setupDatastoreMocks()
180-
if tt.Setup != nil {
181-
tt.Setup(clientsMock)
180+
if tc.Setup != nil {
181+
tc.Setup(clientsMock)
182182
}
183183
clients := shared.NewClientFactory(clientsMock.MockClientFactory())
184184

@@ -198,12 +198,12 @@ func TestBulkDeleteCommand(t *testing.T) {
198198
// Create mocked command
199199
err := cmd.ExecuteContext(ctx)
200200
if assert.NoError(t, err) {
201-
bulkDeleteMock.AssertCalled(t, "BulkDelete", mock.Anything, mock.Anything, mock.Anything, tt.Query)
201+
bulkDeleteMock.AssertCalled(t, "BulkDelete", mock.Anything, mock.Anything, mock.Anything, tc.Query)
202202
}
203203

204204
// Cleanup when done
205-
if tt.Teardown != nil {
206-
tt.Teardown()
205+
if tc.Teardown != nil {
206+
tc.Teardown()
207207
}
208208
})
209209
}

cmd/datastore/bulk_get_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func TestBulkGetCommandPreRun(t *testing.T) {
102102
expectedError: slackerror.New(slackerror.ErrAppNotHosted),
103103
},
104104
}
105-
for name, tt := range tests {
105+
for name, tc := range tests {
106106
t.Run(name, func(t *testing.T) {
107107
clientsMock := shared.NewClientsMock()
108108
manifestMock := &app.ManifestMockObject{}
@@ -112,27 +112,27 @@ func TestBulkGetCommandPreRun(t *testing.T) {
112112
mock.Anything,
113113
mock.Anything,
114114
).Return(
115-
tt.mockManifestResponse,
116-
tt.mockManifestError,
115+
tc.mockManifestResponse,
116+
tc.mockManifestError,
117117
)
118118
clientsMock.AppClient.Manifest = manifestMock
119119
projectConfigMock := config.NewProjectConfigMock()
120120
projectConfigMock.On(
121121
"GetManifestSource",
122122
mock.Anything,
123123
).Return(
124-
tt.mockManifestSource,
124+
tc.mockManifestSource,
125125
nil,
126126
)
127127
clientsMock.Config.ProjectConfig = projectConfigMock
128128
clients := shared.NewClientFactory(clientsMock.MockClientFactory(), func(cf *shared.ClientFactory) {
129-
cf.Config.ForceFlag = tt.mockFlagForce
130-
cf.SDKConfig.WorkingDirectory = tt.mockWorkingDirectory
129+
cf.Config.ForceFlag = tc.mockFlagForce
130+
cf.SDKConfig.WorkingDirectory = tc.mockWorkingDirectory
131131
})
132132
cmd := NewBulkGetCommand(clients)
133133
err := cmd.PreRunE(cmd, nil)
134-
if tt.expectedError != nil {
135-
assert.Equal(t, slackerror.ToSlackError(tt.expectedError).Code, slackerror.ToSlackError(err).Code)
134+
if tc.expectedError != nil {
135+
assert.Equal(t, slackerror.ToSlackError(tc.expectedError).Code, slackerror.ToSlackError(err).Code)
136136
} else {
137137
assert.NoError(t, err)
138138
}
@@ -173,12 +173,12 @@ func TestBulkGetCommand(t *testing.T) {
173173
},
174174
},
175175
}
176-
for name, tt := range tests {
176+
for name, tc := range tests {
177177
t.Run(name, func(t *testing.T) {
178178
ctx := slackcontext.MockContext(t.Context())
179179
clientsMock := setupDatastoreMocks()
180-
if tt.Setup != nil {
181-
tt.Setup(clientsMock)
180+
if tc.Setup != nil {
181+
tc.Setup(clientsMock)
182182
}
183183
clients := shared.NewClientFactory(clientsMock.MockClientFactory())
184184

@@ -198,12 +198,12 @@ func TestBulkGetCommand(t *testing.T) {
198198
// Perform test
199199
err := cmd.ExecuteContext(ctx)
200200
if assert.NoError(t, err) {
201-
bulkGetMock.AssertCalled(t, "BulkGet", mock.Anything, mock.Anything, mock.Anything, tt.Query)
201+
bulkGetMock.AssertCalled(t, "BulkGet", mock.Anything, mock.Anything, mock.Anything, tc.Query)
202202
}
203203

204204
// Cleanup when done
205-
if tt.Teardown != nil {
206-
tt.Teardown()
205+
if tc.Teardown != nil {
206+
tc.Teardown()
207207
}
208208
})
209209
}

cmd/datastore/bulk_put_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func TestBulkPutCommandPreRun(t *testing.T) {
107107
expectedError: slackerror.New(slackerror.ErrAppNotHosted),
108108
},
109109
}
110-
for name, tt := range tests {
110+
for name, tc := range tests {
111111
t.Run(name, func(t *testing.T) {
112112
clientsMock := shared.NewClientsMock()
113113
manifestMock := &app.ManifestMockObject{}
@@ -117,27 +117,27 @@ func TestBulkPutCommandPreRun(t *testing.T) {
117117
mock.Anything,
118118
mock.Anything,
119119
).Return(
120-
tt.mockManifestResponse,
121-
tt.mockManifestError,
120+
tc.mockManifestResponse,
121+
tc.mockManifestError,
122122
)
123123
clientsMock.AppClient.Manifest = manifestMock
124124
projectConfigMock := config.NewProjectConfigMock()
125125
projectConfigMock.On(
126126
"GetManifestSource",
127127
mock.Anything,
128128
).Return(
129-
tt.mockManifestSource,
129+
tc.mockManifestSource,
130130
nil,
131131
)
132132
clientsMock.Config.ProjectConfig = projectConfigMock
133133
clients := shared.NewClientFactory(clientsMock.MockClientFactory(), func(cf *shared.ClientFactory) {
134-
cf.Config.ForceFlag = tt.mockFlagForce
135-
cf.SDKConfig.WorkingDirectory = tt.mockWorkingDirectory
134+
cf.Config.ForceFlag = tc.mockFlagForce
135+
cf.SDKConfig.WorkingDirectory = tc.mockWorkingDirectory
136136
})
137137
cmd := NewBulkPutCommand(clients)
138138
err := cmd.PreRunE(cmd, nil)
139-
if tt.expectedError != nil {
140-
assert.Equal(t, slackerror.ToSlackError(tt.expectedError).Code, slackerror.ToSlackError(err).Code)
139+
if tc.expectedError != nil {
140+
assert.Equal(t, slackerror.ToSlackError(tc.expectedError).Code, slackerror.ToSlackError(err).Code)
141141
} else {
142142
assert.NoError(t, err)
143143
}
@@ -190,12 +190,12 @@ func TestBulkPutCommand(t *testing.T) {
190190
},
191191
},
192192
}
193-
for name, tt := range tests {
193+
for name, tc := range tests {
194194
t.Run(name, func(t *testing.T) {
195195
ctx := slackcontext.MockContext(t.Context())
196196
clientsMock := setupDatastoreMocks()
197-
if tt.Setup != nil {
198-
tt.Setup(clientsMock)
197+
if tc.Setup != nil {
198+
tc.Setup(clientsMock)
199199
}
200200
clients := shared.NewClientFactory(clientsMock.MockClientFactory())
201201

@@ -215,12 +215,12 @@ func TestBulkPutCommand(t *testing.T) {
215215
// Perform test
216216
err := cmd.ExecuteContext(ctx)
217217
if assert.NoError(t, err) {
218-
bulkPutMock.AssertCalled(t, "BulkPut", mock.Anything, mock.Anything, mock.Anything, tt.Query)
218+
bulkPutMock.AssertCalled(t, "BulkPut", mock.Anything, mock.Anything, mock.Anything, tc.Query)
219219
}
220220

221221
// Cleanup when done
222-
if tt.Teardown != nil {
223-
tt.Teardown()
222+
if tc.Teardown != nil {
223+
tc.Teardown()
224224
}
225225
})
226226
}

0 commit comments

Comments
 (0)