Skip to content

Commit 7ef1ac9

Browse files
authored
refactor(tests): use consistent naming in table tests with the slice pattern (#315)
refactor(tests): use tests/tc naming in table tests using the slice pattern
1 parent 2853d95 commit 7ef1ac9

23 files changed

+242
-242
lines changed

internal/api/app_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,8 @@ func TestClient_DeveloperAppInstall_RequestAppApproval(t *testing.T) {
484484
requestJSON: `{"app":"A1234","reason":"This request has been automatically generated according to project environment settings."}`,
485485
},
486486
}
487-
for _, tt := range tests {
488-
t.Run(tt.name, func(t *testing.T) {
487+
for _, tc := range tests {
488+
t.Run(tc.name, func(t *testing.T) {
489489
ctx := slackcontext.MockContext(t.Context())
490490

491491
// prepare
@@ -495,14 +495,14 @@ func TestClient_DeveloperAppInstall_RequestAppApproval(t *testing.T) {
495495
result := fmt.Sprintf(
496496
`{"ok":false,"error":"%s","team_id":"%s"}`,
497497
slackerror.ErrAppApprovalRequestEligible,
498-
tt.teamID,
498+
tc.teamID,
499499
)
500500
_, err := fmt.Fprintln(w, result)
501501
require.NoError(t, err)
502502
}
503503

504504
if strings.Contains(r.URL.Path, appApprovalRequestCreateMethod) {
505-
expectedJSON := tt.requestJSON
505+
expectedJSON := tc.requestJSON
506506
payload, err := io.ReadAll(r.Body)
507507
require.NoError(t, err)
508508
require.Equal(t, expectedJSON, string(payload))
@@ -518,7 +518,7 @@ func TestClient_DeveloperAppInstall_RequestAppApproval(t *testing.T) {
518518
iostreamMock.On("PrintTrace", mock.Anything, mock.Anything, mock.Anything).Return()
519519

520520
// execute
521-
_, _, err := c.DeveloperAppInstall(ctx, iostreamMock, "token", tt.app, []string{}, []string{}, tt.orgGrantWorkspaceID, true)
521+
_, _, err := c.DeveloperAppInstall(ctx, iostreamMock, "token", tc.app, []string{}, []string{}, tc.orgGrantWorkspaceID, true)
522522
require.NoError(t, err)
523523
})
524524
}

internal/api/debug_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ func Test_RedactPII(t *testing.T) {
105105
expected: `Operating System (OS): darwin`,
106106
},
107107
}
108-
for _, tt := range tests {
109-
t.Run(tt.name, func(t *testing.T) {
110-
redacted := goutils.RedactPII(tt.text)
111-
require.Equal(t, redacted, tt.expected)
108+
for _, tc := range tests {
109+
t.Run(tc.name, func(t *testing.T) {
110+
redacted := goutils.RedactPII(tc.text)
111+
require.Equal(t, redacted, tc.expected)
112112
})
113113
}
114114
}

internal/app/app_client_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -692,14 +692,14 @@ func TestAppClient_CleanupAppsJSONFiles(t *testing.T) {
692692
},
693693
}
694694

695-
for _, tt := range tests {
695+
for _, tc := range tests {
696696
ac, _, _, pathToAppsJSON, pathToDevAppsJSON, teardown := setup(t)
697697
defer teardown(t)
698698
ctx := slackcontext.MockContext(t.Context())
699699

700-
err := afero.WriteFile(ac.fs, pathToAppsJSON, tt.appsJSON, 0600)
700+
err := afero.WriteFile(ac.fs, pathToAppsJSON, tc.appsJSON, 0600)
701701
require.NoError(t, err)
702-
err = afero.WriteFile(ac.fs, pathToDevAppsJSON, tt.devAppsJSON, 0600)
702+
err = afero.WriteFile(ac.fs, pathToDevAppsJSON, tc.devAppsJSON, 0600)
703703
require.NoError(t, err)
704704

705705
_, err = ac.fs.Stat(pathToAppsJSON)

internal/app/app_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,10 @@ func Test_RegexReplaceAppNameInManifest(t *testing.T) {
159159
expectedSrc: testdata.ManifestSDKTSAppName,
160160
},
161161
}
162-
for _, tt := range tests {
163-
t.Run(tt.name, func(t *testing.T) {
164-
actualSrc := regexReplaceAppNameInManifest(tt.src, tt.appName)
165-
require.Equal(t, tt.expectedSrc, actualSrc)
162+
for _, tc := range tests {
163+
t.Run(tc.name, func(t *testing.T) {
164+
actualSrc := regexReplaceAppNameInManifest(tc.src, tc.appName)
165+
require.Equal(t, tc.expectedSrc, actualSrc)
166166
})
167167
}
168168
}

internal/goutils/slices_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ func Test_AppendStringIfNotMember(t *testing.T) {
4646
expectedSlice: []string{"one"},
4747
},
4848
}
49-
for _, tt := range tests {
50-
t.Run(tt.name, func(t *testing.T) {
51-
actualSlice := AppendStringIfNotMember(tt.originalSlice, tt.newElement)
52-
require.ElementsMatch(t, tt.expectedSlice, actualSlice)
49+
for _, tc := range tests {
50+
t.Run(tc.name, func(t *testing.T) {
51+
actualSlice := AppendStringIfNotMember(tc.originalSlice, tc.newElement)
52+
require.ElementsMatch(t, tc.expectedSlice, actualSlice)
5353
})
5454
}
5555
}
@@ -68,10 +68,10 @@ func Test_Contains(t *testing.T) {
6868
{name: "not_case_sensitive_fail", listToCheck: []string{"hi", "hey", "hello", "apple", "pear"}, toFind: "Peach", isCaseSensitive: false, want: false},
6969
{name: "not_case_sensitive_substring", listToCheck: []string{"hi", "hey hello"}, toFind: "hey", isCaseSensitive: false, want: false},
7070
}
71-
for _, tt := range tests {
72-
t.Run(tt.name, func(t *testing.T) {
73-
if got := Contains(tt.listToCheck, tt.toFind, tt.isCaseSensitive); got != tt.want {
74-
t.Errorf("method() = %v, want %v", got, tt.want)
71+
for _, tc := range tests {
72+
t.Run(tc.name, func(t *testing.T) {
73+
if got := Contains(tc.listToCheck, tc.toFind, tc.isCaseSensitive); got != tc.want {
74+
t.Errorf("method() = %v, want %v", got, tc.want)
7575
}
7676
})
7777
}

internal/goutils/strings_test.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ func Test_HashString(t *testing.T) {
5353
expected: true,
5454
},
5555
}
56-
for _, tt := range tests {
57-
t.Run(tt.name, func(t *testing.T) {
58-
hash1, err1 := HashString(tt.text1)
59-
hash2, err2 := HashString(tt.text2)
60-
require.Equal(t, hash1 == hash2, tt.expected)
56+
for _, tc := range tests {
57+
t.Run(tc.name, func(t *testing.T) {
58+
hash1, err1 := HashString(tc.text1)
59+
hash2, err2 := HashString(tc.text2)
60+
require.Equal(t, hash1 == hash2, tc.expected)
6161
require.NoError(t, err1)
6262
require.NoError(t, err2)
6363
})
@@ -121,10 +121,10 @@ func Test_ExtractFirstJSONFromString(t *testing.T) {
121121
expected: "",
122122
},
123123
}
124-
for _, tt := range tests {
125-
t.Run(tt.name, func(t *testing.T) {
126-
actualRes := ExtractFirstJSONFromString(tt.text)
127-
require.Equal(t, tt.expected, actualRes)
124+
for _, tc := range tests {
125+
t.Run(tc.name, func(t *testing.T) {
126+
actualRes := ExtractFirstJSONFromString(tc.text)
127+
require.Equal(t, tc.expected, actualRes)
128128
})
129129
}
130130
}
@@ -155,10 +155,10 @@ func Test_addLogWhenValExist(t *testing.T) {
155155
expected: "hello world: [slack]\n",
156156
},
157157
}
158-
for _, tt := range tests {
159-
t.Run(tt.name, func(t *testing.T) {
160-
output := AddLogWhenValExist(tt.title, tt.val)
161-
require.Equal(t, output, tt.expected)
158+
for _, tc := range tests {
159+
t.Run(tc.name, func(t *testing.T) {
160+
output := AddLogWhenValExist(tc.title, tc.val)
161+
require.Equal(t, output, tc.expected)
162162
})
163163
}
164164
}
@@ -380,10 +380,10 @@ func Test_RedactPII(t *testing.T) {
380380
expected: `slack variables remove ...`,
381381
},
382382
}
383-
for _, tt := range tests {
384-
t.Run(tt.name, func(t *testing.T) {
385-
redacted := RedactPII(tt.text)
386-
require.Equal(t, tt.expected, redacted)
383+
for _, tc := range tests {
384+
t.Run(tc.name, func(t *testing.T) {
385+
redacted := RedactPII(tc.text)
386+
require.Equal(t, tc.expected, redacted)
387387
})
388388
}
389389
}
@@ -414,10 +414,10 @@ func Test_UpperCaseTrimAll(t *testing.T) {
414414
expected: "HELLO,WORLD",
415415
},
416416
}
417-
for _, tt := range tests {
418-
t.Run(tt.name, func(t *testing.T) {
419-
output := UpperCaseTrimAll(tt.namedEntities)
420-
require.Equal(t, output, tt.expected)
417+
for _, tc := range tests {
418+
t.Run(tc.name, func(t *testing.T) {
419+
output := UpperCaseTrimAll(tc.namedEntities)
420+
require.Equal(t, output, tc.expected)
421421
})
422422
}
423423
}
@@ -444,10 +444,10 @@ func Test_ToHTTPS(t *testing.T) {
444444
expected: "https://www.xyz.com",
445445
},
446446
}
447-
for _, tt := range tests {
448-
t.Run(tt.name, func(t *testing.T) {
449-
output := ToHTTPS(tt.urlAddr)
450-
require.Equal(t, output, tt.expected)
447+
for _, tc := range tests {
448+
t.Run(tc.name, func(t *testing.T) {
449+
output := ToHTTPS(tc.urlAddr)
450+
require.Equal(t, output, tc.expected)
451451
})
452452
}
453453
}

internal/pkg/externalauth/prompt_provider_auth_select_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,18 @@ func TestPrompt_ProviderAuthSelectPrompt_no_selected_auth(t *testing.T) {
8282
},
8383
}
8484

85-
for _, tt := range tests {
85+
for _, tc := range tests {
8686
var mockProviderFlag string
8787
ctx := slackcontext.MockContext(t.Context())
8888
clientsMock := shared.NewClientsMock()
8989
clients := shared.NewClientFactory(clientsMock.MockClientFactory())
9090
clientsMock.Config.Flags.StringVar(&mockProviderFlag, "provider", "", "mock provider flag")
91-
if tt.ProviderFlag != "" {
92-
_ = clientsMock.Config.Flags.Set("provider", tt.ProviderFlag)
91+
if tc.ProviderFlag != "" {
92+
_ = clientsMock.Config.Flags.Set("provider", tc.ProviderFlag)
9393
}
9494
clientsMock.IO.On("SelectPrompt", mock.Anything, "Select a provider", mock.Anything, iostreams.MatchPromptConfig(iostreams.SelectPromptConfig{
9595
Flag: clients.Config.Flags.Lookup("provider"),
96-
})).Return(tt.Selection, nil)
96+
})).Return(tc.Selection, nil)
9797

9898
clientsMock.AddDefaultMocks()
9999

@@ -149,15 +149,15 @@ func TestPrompt_ProviderAuthSelectPrompt_with_selected_auth(t *testing.T) {
149149
},
150150
}
151151

152-
for _, tt := range tests {
152+
for _, tc := range tests {
153153
var mockProviderFlag string
154154
ctx := slackcontext.MockContext(t.Context())
155155
clientsMock := shared.NewClientsMock()
156156
clients := shared.NewClientFactory(clientsMock.MockClientFactory())
157157
clientsMock.Config.Flags.StringVar(&mockProviderFlag, "provider", "", "mock provider flag")
158158
clientsMock.IO.On("SelectPrompt", mock.Anything, "Select a provider", mock.Anything, iostreams.MatchPromptConfig(iostreams.SelectPromptConfig{
159159
Flag: clientsMock.Config.Flags.Lookup("provider"),
160-
})).Return(tt.Selection, nil)
160+
})).Return(tc.Selection, nil)
161161
clientsMock.AddDefaultMocks()
162162

163163
selectedProvider, err := ProviderAuthSelectPrompt(ctx, clients, workflowsInfo)

internal/pkg/externalauth/prompt_provider_select_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ func TestPrompt_ProviderSelectPrompt_no_token(t *testing.T) {
7272
},
7373
}
7474

75-
for _, tt := range tests {
75+
for _, tc := range tests {
7676
var mockProviderFlag string
7777
ctx := slackcontext.MockContext(t.Context())
7878
clientsMock := shared.NewClientsMock()
7979
clients := shared.NewClientFactory(clientsMock.MockClientFactory())
8080
clientsMock.Config.Flags.StringVar(&mockProviderFlag, "provider", "", "mock provider flag")
8181
clientsMock.IO.On("SelectPrompt", mock.Anything, "Select a provider", mock.Anything, iostreams.MatchPromptConfig(iostreams.SelectPromptConfig{
8282
Flag: clientsMock.Config.Flags.Lookup("provider"),
83-
})).Return(tt.Selection, nil)
83+
})).Return(tc.Selection, nil)
8484
clientsMock.AddDefaultMocks()
8585

8686
selectedProvider, err := ProviderSelectPrompt(ctx, clients, authorizationInfoLists)
@@ -134,18 +134,18 @@ func TestPrompt_ProviderSelectPrompt_with_token(t *testing.T) {
134134
},
135135
}
136136

137-
for _, tt := range tests {
137+
for _, tc := range tests {
138138
var mockProviderFlag string
139139
ctx := slackcontext.MockContext(t.Context())
140140
clientsMock := shared.NewClientsMock()
141141
clients := shared.NewClientFactory(clientsMock.MockClientFactory())
142142
clientsMock.Config.Flags.StringVar(&mockProviderFlag, "provider", "", "mock provider flag")
143-
if tt.ProviderFlag != "" {
144-
_ = clientsMock.Config.Flags.Set("provider", tt.ProviderFlag)
143+
if tc.ProviderFlag != "" {
144+
_ = clientsMock.Config.Flags.Set("provider", tc.ProviderFlag)
145145
}
146146
clientsMock.IO.On("SelectPrompt", mock.Anything, "Select a provider", mock.Anything, iostreams.MatchPromptConfig(iostreams.SelectPromptConfig{
147147
Flag: clientsMock.Config.Flags.Lookup("provider"),
148-
})).Return(tt.Selection, nil)
148+
})).Return(tc.Selection, nil)
149149
clientsMock.AddDefaultMocks()
150150

151151
selectedProvider, err := ProviderSelectPrompt(ctx, clients, authorizationInfoLists)

internal/pkg/externalauth/prompt_token_select_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,17 @@ func TestPrompt_TokenSelectPrompt_with_token(t *testing.T) {
8282
}
8383

8484
var externalAccountFlag string
85-
for _, tt := range tests {
85+
for _, tc := range tests {
8686
ctx := slackcontext.MockContext(t.Context())
8787
clientsMock := shared.NewClientsMock()
8888
clients := shared.NewClientFactory(clientsMock.MockClientFactory())
8989
clientsMock.Config.Flags.StringVar(&externalAccountFlag, "external-account", "", "mock external-account flag")
90-
if tt.ExternalAccountFlag != "" {
91-
_ = clientsMock.Config.Flags.Set("external-account", tt.ExternalAccountFlag)
90+
if tc.ExternalAccountFlag != "" {
91+
_ = clientsMock.Config.Flags.Set("external-account", tc.ExternalAccountFlag)
9292
}
9393
clientsMock.IO.On("SelectPrompt", mock.Anything, "Select an external account", mock.Anything, iostreams.MatchPromptConfig(iostreams.SelectPromptConfig{
9494
Flag: clientsMock.Config.Flags.Lookup("external-account"),
95-
})).Return(tt.Selection, nil)
95+
})).Return(tc.Selection, nil)
9696
clientsMock.AddDefaultMocks()
9797

9898
selectedToken, err := TokenSelectPrompt(ctx, clients, authorizationInfo)

internal/pkg/externalauth/prompt_workflow_select_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,18 +142,18 @@ func TestPrompt_WorkflowSelectPrompt_with_workflows(t *testing.T) {
142142
},
143143
}
144144

145-
for _, tt := range tests {
145+
for _, tc := range tests {
146146
var mockWorkflowFlag string
147147
ctx := slackcontext.MockContext(t.Context())
148148
clientsMock := shared.NewClientsMock()
149149
clients := shared.NewClientFactory(clientsMock.MockClientFactory())
150150
clientsMock.Config.Flags.StringVar(&mockWorkflowFlag, "workflow", "", "mock workflow flag")
151-
if tt.WorkflowFlag != "" {
152-
_ = clientsMock.Config.Flags.Set("workflow", tt.WorkflowFlag)
151+
if tc.WorkflowFlag != "" {
152+
_ = clientsMock.Config.Flags.Set("workflow", tc.WorkflowFlag)
153153
}
154154
clientsMock.IO.On("SelectPrompt", mock.Anything, "Select a workflow", mock.Anything, iostreams.MatchPromptConfig(iostreams.SelectPromptConfig{
155155
Flag: clientsMock.Config.Flags.Lookup("workflow"),
156-
})).Return(tt.Selection, nil)
156+
})).Return(tc.Selection, nil)
157157
clientsMock.AddDefaultMocks()
158158

159159
selectedWorkflow, err := WorkflowSelectPrompt(ctx, clients, authorizationInfoLists)

0 commit comments

Comments
 (0)