Skip to content

Commit cc98925

Browse files
authored
chore: enable thelper linter (argoproj#20405)
Signed-off-by: Matthieu MOREL <[email protected]>
1 parent f031f49 commit cc98925

Some content is hidden

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

59 files changed

+146
-7
lines changed

.golangci.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ linters:
2020
- misspell
2121
- staticcheck
2222
- testifylint
23+
- thelper
2324
- unparam
2425
- unused
2526
- usestdlibvars

applicationset/controllers/applicationset_controller_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -2246,6 +2246,7 @@ func TestSetApplicationSetStatusCondition(t *testing.T) {
22462246
},
22472247
},
22482248
testfunc: func(t *testing.T, appset v1alpha1.ApplicationSet) {
2249+
t.Helper()
22492250
assert.Len(t, appset.Status.Conditions, 3)
22502251
},
22512252
},
@@ -2281,6 +2282,7 @@ func TestSetApplicationSetStatusCondition(t *testing.T) {
22812282
},
22822283
},
22832284
testfunc: func(t *testing.T, appset v1alpha1.ApplicationSet) {
2285+
t.Helper()
22842286
assert.Len(t, appset.Status.Conditions, 3)
22852287

22862288
isProgressingCondition := false
@@ -2343,6 +2345,7 @@ func TestSetApplicationSetStatusCondition(t *testing.T) {
23432345
},
23442346
},
23452347
testfunc: func(t *testing.T, appset v1alpha1.ApplicationSet) {
2348+
t.Helper()
23462349
assert.Len(t, appset.Status.Conditions, 4)
23472350

23482351
isProgressingCondition := false
@@ -2389,6 +2392,7 @@ func TestSetApplicationSetStatusCondition(t *testing.T) {
23892392
}
23902393

23912394
func applicationsUpdateSyncPolicyTest(t *testing.T, applicationsSyncPolicy v1alpha1.ApplicationsSyncPolicy, recordBuffer int, allowPolicyOverride bool) v1alpha1.Application {
2395+
t.Helper()
23922396
scheme := runtime.NewScheme()
23932397
err := v1alpha1.AddToScheme(scheme)
23942398
require.NoError(t, err)
@@ -2550,6 +2554,7 @@ func TestUpdatePerformedWithSyncPolicyCreateOnlyAndAllowPolicyOverrideFalse(t *t
25502554
}
25512555

25522556
func applicationsDeleteSyncPolicyTest(t *testing.T, applicationsSyncPolicy v1alpha1.ApplicationsSyncPolicy, recordBuffer int, allowPolicyOverride bool) v1alpha1.ApplicationList {
2557+
t.Helper()
25532558
scheme := runtime.NewScheme()
25542559
err := v1alpha1.AddToScheme(scheme)
25552560
require.NoError(t, err)

applicationset/generators/merge_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ func TestMergeGenerate(t *testing.T) {
197197
}
198198

199199
func toAPIExtensionsJSON(t *testing.T, g interface{}) *apiextensionsv1.JSON {
200+
t.Helper()
200201
resVal, err := json.Marshal(g)
201202
if err != nil {
202203
t.Error("unable to unmarshal json", g)

applicationset/services/pull_request/bitbucket_cloud_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
)
1616

1717
func defaultHandlerCloud(t *testing.T) func(http.ResponseWriter, *http.Request) {
18+
t.Helper()
1819
return func(w http.ResponseWriter, r *http.Request) {
1920
w.Header().Set("Content-Type", "application/json")
2021
var err error

applicationset/services/pull_request/bitbucket_server_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
)
1717

1818
func defaultHandler(t *testing.T) func(http.ResponseWriter, *http.Request) {
19+
t.Helper()
1920
return func(w http.ResponseWriter, r *http.Request) {
2021
w.Header().Set("Content-Type", "application/json")
2122
var err error

applicationset/services/pull_request/gitea_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
)
1515

1616
func giteaMockHandler(t *testing.T) func(http.ResponseWriter, *http.Request) {
17+
t.Helper()
1718
return func(w http.ResponseWriter, r *http.Request) {
1819
w.Header().Set("Content-Type", "application/json")
1920
fmt.Println(r.RequestURI)

applicationset/services/pull_request/gitlab_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
)
1616

1717
func writeMRListResponse(t *testing.T, w io.Writer) {
18+
t.Helper()
1819
f, err := os.Open("fixtures/gitlab_mr_list_response.json")
1920
if err != nil {
2021
t.Fatalf("error opening fixture file: %v", err)

applicationset/services/scm_provider/bitbucket_server_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
)
1515

1616
func defaultHandler(t *testing.T) func(http.ResponseWriter, *http.Request) {
17+
t.Helper()
1718
return func(w http.ResponseWriter, r *http.Request) {
1819
w.Header().Set("Content-Type", "application/json")
1920
var err error
@@ -82,6 +83,7 @@ func defaultHandler(t *testing.T) func(http.ResponseWriter, *http.Request) {
8283
}
8384

8485
func verifyDefaultRepo(t *testing.T, err error, repos []*Repository) {
86+
t.Helper()
8587
require.NoError(t, err)
8688
assert.Len(t, repos, 1)
8789
assert.Equal(t, Repository{

applicationset/services/scm_provider/gitea_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
)
1616

1717
func giteaMockHandler(t *testing.T) func(http.ResponseWriter, *http.Request) {
18+
t.Helper()
1819
return func(w http.ResponseWriter, r *http.Request) {
1920
w.Header().Set("Content-Type", "application/json")
2021
switch r.RequestURI {

applicationset/services/scm_provider/github_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
)
1515

1616
func githubMockHandler(t *testing.T) func(http.ResponseWriter, *http.Request) {
17+
t.Helper()
1718
return func(w http.ResponseWriter, r *http.Request) {
1819
w.Header().Set("Content-Type", "application/json")
1920
switch r.RequestURI {

applicationset/services/scm_provider/gitlab_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
)
1818

1919
func gitlabMockHandler(t *testing.T) func(http.ResponseWriter, *http.Request) {
20+
t.Helper()
2021
return func(w http.ResponseWriter, r *http.Request) {
2122
w.Header().Set("Content-Type", "application/json")
2223
switch r.RequestURI {

controller/appcontroller_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -2196,6 +2196,7 @@ func TestAlreadyAttemptSync(t *testing.T) {
21962196
}
21972197

21982198
func assertDurationAround(t *testing.T, expected time.Duration, actual time.Duration) {
2199+
t.Helper()
21992200
delta := time.Second / 2
22002201
assert.GreaterOrEqual(t, expected, actual-delta)
22012202
assert.LessOrEqual(t, expected, actual+delta)

controller/metrics/metrics_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ func assertMetricsPrinted(t *testing.T, expectedLines, body string) {
467467

468468
// assertMetricsNotPrinted
469469
func assertMetricsNotPrinted(t *testing.T, expectedLines, body string) {
470+
t.Helper()
470471
for _, line := range strings.Split(expectedLines, "\n") {
471472
if line == "" {
472473
continue

controller/sharding/sharding_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,7 @@ func TestGetClusterSharding(t *testing.T) {
836836
{
837837
name: "Default sharding with statefulset",
838838
envsSetter: func(t *testing.T) {
839+
t.Helper()
839840
t.Setenv(common.EnvControllerReplicas, "1")
840841
},
841842
cleanup: func() {},
@@ -847,6 +848,7 @@ func TestGetClusterSharding(t *testing.T) {
847848
{
848849
name: "Default sharding with deployment",
849850
envsSetter: func(t *testing.T) {
851+
t.Helper()
850852
t.Setenv(common.EnvAppControllerName, common.DefaultApplicationControllerName)
851853
},
852854
cleanup: func() {},
@@ -858,6 +860,7 @@ func TestGetClusterSharding(t *testing.T) {
858860
{
859861
name: "Default sharding with deployment and multiple replicas",
860862
envsSetter: func(t *testing.T) {
863+
t.Helper()
861864
t.Setenv(common.EnvAppControllerName, "argocd-application-controller-multi-replicas")
862865
},
863866
cleanup: func() {},
@@ -869,6 +872,7 @@ func TestGetClusterSharding(t *testing.T) {
869872
{
870873
name: "Statefulset multiple replicas",
871874
envsSetter: func(t *testing.T) {
875+
t.Helper()
872876
t.Setenv(common.EnvControllerReplicas, "3")
873877
osHostnameFunction = func() (string, error) { return "example-shard-3", nil }
874878
},
@@ -883,6 +887,7 @@ func TestGetClusterSharding(t *testing.T) {
883887
{
884888
name: "Explicit shard with statefulset and 1 replica",
885889
envsSetter: func(t *testing.T) {
890+
t.Helper()
886891
t.Setenv(common.EnvControllerReplicas, "1")
887892
t.Setenv(common.EnvControllerShard, "3")
888893
},
@@ -895,6 +900,7 @@ func TestGetClusterSharding(t *testing.T) {
895900
{
896901
name: "Explicit shard with statefulset and 2 replica - and to high shard",
897902
envsSetter: func(t *testing.T) {
903+
t.Helper()
898904
t.Setenv(common.EnvControllerReplicas, "2")
899905
t.Setenv(common.EnvControllerShard, "3")
900906
},
@@ -907,6 +913,7 @@ func TestGetClusterSharding(t *testing.T) {
907913
{
908914
name: "Explicit shard with statefulset and 2 replica",
909915
envsSetter: func(t *testing.T) {
916+
t.Helper()
910917
t.Setenv(common.EnvControllerReplicas, "2")
911918
t.Setenv(common.EnvControllerShard, "1")
912919
},
@@ -919,6 +926,7 @@ func TestGetClusterSharding(t *testing.T) {
919926
{
920927
name: "Explicit shard with deployment",
921928
envsSetter: func(t *testing.T) {
929+
t.Helper()
922930
t.Setenv(common.EnvControllerShard, "3")
923931
},
924932
cleanup: func() {},
@@ -930,6 +938,7 @@ func TestGetClusterSharding(t *testing.T) {
930938
{
931939
name: "Explicit shard with deployment and multiple replicas will read from configmap",
932940
envsSetter: func(t *testing.T) {
941+
t.Helper()
933942
t.Setenv(common.EnvAppControllerName, "argocd-application-controller-multi-replicas")
934943
t.Setenv(common.EnvControllerShard, "3")
935944
},
@@ -942,6 +951,7 @@ func TestGetClusterSharding(t *testing.T) {
942951
{
943952
name: "Dynamic sharding but missing deployment",
944953
envsSetter: func(t *testing.T) {
954+
t.Helper()
945955
t.Setenv(common.EnvAppControllerName, "missing-deployment")
946956
},
947957
cleanup: func() {},

controller/state_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ func TestAppRevisionsMultiSource(t *testing.T) {
547547
}
548548

549549
func toJSON(t *testing.T, obj *unstructured.Unstructured) string {
550+
t.Helper()
550551
data, err := json.Marshal(obj)
551552
require.NoError(t, err)
552553
return string(data)

pkg/apis/application/v1alpha1/applicationset_types_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ func TestApplicationSetSetConditions(t *testing.T) {
101101
testAppSetCond(ApplicationSetConditionResourcesUpToDate, "bar", tenMinsAgo, ApplicationSetConditionStatusTrue, ApplicationSetReasonApplicationSetUpToDate),
102102
},
103103
validate: func(t *testing.T, a *ApplicationSet) {
104+
t.Helper()
104105
assert.Equal(t, fiveMinsAgo, a.Status.Conditions[0].LastTransitionTime)
105106
assert.Equal(t, tenMinsAgo, a.Status.Conditions[1].LastTransitionTime)
106107
},
@@ -120,6 +121,7 @@ func TestApplicationSetSetConditions(t *testing.T) {
120121
testAppSetCond(ApplicationSetConditionResourcesUpToDate, "bar", nil, ApplicationSetConditionStatusFalse, ApplicationSetReasonApplicationSetUpToDate),
121122
},
122123
validate: func(t *testing.T, a *ApplicationSet) {
124+
t.Helper()
123125
// SetConditions should add timestamps for new conditions.
124126
assert.True(t, a.Status.Conditions[0].LastTransitionTime.Time.After(fiveMinsAgo.Time))
125127
assert.True(t, a.Status.Conditions[1].LastTransitionTime.Time.After(fiveMinsAgo.Time))
@@ -141,6 +143,7 @@ func TestApplicationSetSetConditions(t *testing.T) {
141143
testAppSetCond(ApplicationSetConditionResourcesUpToDate, "bar", tenMinsAgo, ApplicationSetConditionStatusTrue, ApplicationSetReasonApplicationSetUpToDate),
142144
},
143145
validate: func(t *testing.T, a *ApplicationSet) {
146+
t.Helper()
144147
assert.Equal(t, tenMinsAgo.Time, a.Status.Conditions[0].LastTransitionTime.Time)
145148
},
146149
},
@@ -161,6 +164,7 @@ func TestApplicationSetSetConditions(t *testing.T) {
161164
}
162165

163166
func assertAppSetConditions(t *testing.T, expected []ApplicationSetCondition, actual []ApplicationSetCondition) {
167+
t.Helper()
164168
assert.Equal(t, len(expected), len(actual))
165169
for i := range expected {
166170
assert.Equal(t, expected[i].Type, actual[i].Type)

pkg/apis/application/v1alpha1/types_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -2982,6 +2982,7 @@ func TestSetConditions(t *testing.T) {
29822982
testCond(ApplicationConditionSharedResourceWarning, "bar", tenMinsAgo),
29832983
},
29842984
validate: func(t *testing.T, a *Application) {
2985+
t.Helper()
29852986
assert.Equal(t, fiveMinsAgo, a.Status.Conditions[0].LastTransitionTime)
29862987
assert.Equal(t, tenMinsAgo, a.Status.Conditions[1].LastTransitionTime)
29872988
},
@@ -3002,6 +3003,7 @@ func TestSetConditions(t *testing.T) {
30023003
testCond(ApplicationConditionSharedResourceWarning, "bar", nil),
30033004
},
30043005
validate: func(t *testing.T, a *Application) {
3006+
t.Helper()
30053007
// SetConditions should add timestamps for new conditions.
30063008
assert.True(t, a.Status.Conditions[0].LastTransitionTime.Time.After(fiveMinsAgo.Time))
30073009
assert.True(t, a.Status.Conditions[1].LastTransitionTime.Time.After(fiveMinsAgo.Time))
@@ -3024,6 +3026,7 @@ func TestSetConditions(t *testing.T) {
30243026
testCond(ApplicationConditionSharedResourceWarning, "bar", tenMinsAgo),
30253027
},
30263028
validate: func(t *testing.T, a *Application) {
3029+
t.Helper()
30273030
assert.Equal(t, tenMinsAgo.Time, a.Status.Conditions[0].LastTransitionTime.Time)
30283031
},
30293032
},
@@ -3059,6 +3062,7 @@ func TestSetConditions(t *testing.T) {
30593062
testCond(ApplicationConditionSharedResourceWarning, "bar", tenMinsAgo),
30603063
},
30613064
validate: func(t *testing.T, a *Application) {
3065+
t.Helper()
30623066
assert.Equal(t, tenMinsAgo.Time, a.Status.Conditions[0].LastTransitionTime.Time)
30633067
assert.Equal(t, tenMinsAgo.Time, a.Status.Conditions[1].LastTransitionTime.Time)
30643068
},
@@ -3082,6 +3086,7 @@ func TestSetConditions(t *testing.T) {
30823086
testCond(ApplicationConditionSharedResourceWarning, "bar changed message", fiveMinsAgo),
30833087
},
30843088
validate: func(t *testing.T, a *Application) {
3089+
t.Helper()
30853090
assert.Equal(t, tenMinsAgo.Time, a.Status.Conditions[0].LastTransitionTime.Time)
30863091
assert.Equal(t, fiveMinsAgo.Time, a.Status.Conditions[1].LastTransitionTime.Time)
30873092
},
@@ -3100,6 +3105,7 @@ func TestSetConditions(t *testing.T) {
31003105
testCond(ApplicationConditionSharedResourceWarning, "bar", tenMinsAgo),
31013106
},
31023107
validate: func(t *testing.T, a *Application) {
3108+
t.Helper()
31033109
assert.Equal(t, tenMinsAgo.Time, a.Status.Conditions[0].LastTransitionTime.Time)
31043110
},
31053111
},
@@ -3121,6 +3127,7 @@ func TestSetConditions(t *testing.T) {
31213127
// difficult to strictly assert on as they can use time.Now(). Elements in each array are assumed
31223128
// to match positions.
31233129
func assertConditions(t *testing.T, expected []ApplicationCondition, actual []ApplicationCondition) {
3130+
t.Helper()
31243131
assert.Equal(t, len(expected), len(actual))
31253132
for i := range expected {
31263133
assert.Equal(t, expected[i].Type, actual[i].Type)

reposerver/cache/cache_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ func TestCachedManifestResponse_HashBehavior(t *testing.T) {
261261
}
262262

263263
func getInMemoryCacheContents(t *testing.T, inMemCache *cacheutil.InMemoryCache) map[string]*CachedManifestResponse {
264+
t.Helper()
264265
items, err := inMemCache.Items(func() interface{} { return &CachedManifestResponse{} })
265266
if err != nil {
266267
t.Fatal(err)

reposerver/cache/mocks/reposervercache.go

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

reposerver/metrics/githandlers_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func TestEdgeCasesAndErrorHandling(t *testing.T) {
2222
{
2323
name: "lsRemoteParallelismLimitSemaphore is nil",
2424
testFunc: func(t *testing.T) {
25+
t.Helper()
2526
lsRemoteParallelismLimitSemaphore = nil
2627
assert.NotPanics(t, func() {
2728
NewGitClientEventHandlers(&MetricsServer{})
@@ -37,6 +38,7 @@ func TestEdgeCasesAndErrorHandling(t *testing.T) {
3738
lsRemoteParallelismLimitSemaphore = nil
3839
},
3940
testFunc: func(t *testing.T) {
41+
t.Helper()
4042
assert.NotPanics(t, func() {
4143
NewGitClientEventHandlers(&MetricsServer{})
4244
})
@@ -51,6 +53,7 @@ func TestEdgeCasesAndErrorHandling(t *testing.T) {
5153
lsRemoteParallelismLimitSemaphore = nil
5254
},
5355
testFunc: func(t *testing.T) {
56+
t.Helper()
5457
assert.NotPanics(t, func() {
5558
NewGitClientEventHandlers(&MetricsServer{})
5659
})
@@ -88,6 +91,7 @@ func TestSemaphoreFunctionality(t *testing.T) {
8891
lsRemoteParallelismLimitSemaphore = nil
8992
},
9093
testFunc: func(t *testing.T) {
94+
t.Helper()
9195
assert.NotPanics(t, func() {
9296
NewGitClientEventHandlers(&MetricsServer{})
9397
})
@@ -102,6 +106,7 @@ func TestSemaphoreFunctionality(t *testing.T) {
102106
lsRemoteParallelismLimitSemaphore = nil
103107
},
104108
testFunc: func(t *testing.T) {
109+
t.Helper()
105110
assert.NotPanics(t, func() {
106111
NewGitClientEventHandlers(&MetricsServer{})
107112
})

0 commit comments

Comments
 (0)