Skip to content
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

chore: enable thelper linter #20405

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ linters:
- misspell
- staticcheck
- testifylint
- thelper
- unparam
- unused
- usestdlibvars
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2246,6 +2246,7 @@ func TestSetApplicationSetStatusCondition(t *testing.T) {
},
},
testfunc: func(t *testing.T, appset v1alpha1.ApplicationSet) {
t.Helper()
assert.Len(t, appset.Status.Conditions, 3)
},
},
Expand Down Expand Up @@ -2281,6 +2282,7 @@ func TestSetApplicationSetStatusCondition(t *testing.T) {
},
},
testfunc: func(t *testing.T, appset v1alpha1.ApplicationSet) {
t.Helper()
assert.Len(t, appset.Status.Conditions, 3)

isProgressingCondition := false
Expand Down Expand Up @@ -2343,6 +2345,7 @@ func TestSetApplicationSetStatusCondition(t *testing.T) {
},
},
testfunc: func(t *testing.T, appset v1alpha1.ApplicationSet) {
t.Helper()
assert.Len(t, appset.Status.Conditions, 4)

isProgressingCondition := false
Expand Down Expand Up @@ -2389,6 +2392,7 @@ func TestSetApplicationSetStatusCondition(t *testing.T) {
}

func applicationsUpdateSyncPolicyTest(t *testing.T, applicationsSyncPolicy v1alpha1.ApplicationsSyncPolicy, recordBuffer int, allowPolicyOverride bool) v1alpha1.Application {
t.Helper()
scheme := runtime.NewScheme()
err := v1alpha1.AddToScheme(scheme)
require.NoError(t, err)
Expand Down Expand Up @@ -2550,6 +2554,7 @@ func TestUpdatePerformedWithSyncPolicyCreateOnlyAndAllowPolicyOverrideFalse(t *t
}

func applicationsDeleteSyncPolicyTest(t *testing.T, applicationsSyncPolicy v1alpha1.ApplicationsSyncPolicy, recordBuffer int, allowPolicyOverride bool) v1alpha1.ApplicationList {
t.Helper()
scheme := runtime.NewScheme()
err := v1alpha1.AddToScheme(scheme)
require.NoError(t, err)
Expand Down
1 change: 1 addition & 0 deletions applicationset/generators/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ func TestMergeGenerate(t *testing.T) {
}

func toAPIExtensionsJSON(t *testing.T, g interface{}) *apiextensionsv1.JSON {
t.Helper()
resVal, err := json.Marshal(g)
if err != nil {
t.Error("unable to unmarshal json", g)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
)

func defaultHandlerCloud(t *testing.T) func(http.ResponseWriter, *http.Request) {
t.Helper()
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
var err error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
)

func defaultHandler(t *testing.T) func(http.ResponseWriter, *http.Request) {
t.Helper()
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
var err error
Expand Down
1 change: 1 addition & 0 deletions applicationset/services/pull_request/gitea_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
)

func giteaMockHandler(t *testing.T) func(http.ResponseWriter, *http.Request) {
t.Helper()
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
fmt.Println(r.RequestURI)
Expand Down
1 change: 1 addition & 0 deletions applicationset/services/pull_request/gitlab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
)

func writeMRListResponse(t *testing.T, w io.Writer) {
t.Helper()
f, err := os.Open("fixtures/gitlab_mr_list_response.json")
if err != nil {
t.Fatalf("error opening fixture file: %v", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
)

func defaultHandler(t *testing.T) func(http.ResponseWriter, *http.Request) {
t.Helper()
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
var err error
Expand Down Expand Up @@ -82,6 +83,7 @@ func defaultHandler(t *testing.T) func(http.ResponseWriter, *http.Request) {
}

func verifyDefaultRepo(t *testing.T, err error, repos []*Repository) {
t.Helper()
require.NoError(t, err)
assert.Len(t, repos, 1)
assert.Equal(t, Repository{
Expand Down
1 change: 1 addition & 0 deletions applicationset/services/scm_provider/gitea_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
)

func giteaMockHandler(t *testing.T) func(http.ResponseWriter, *http.Request) {
t.Helper()
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
switch r.RequestURI {
Expand Down
1 change: 1 addition & 0 deletions applicationset/services/scm_provider/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
)

func githubMockHandler(t *testing.T) func(http.ResponseWriter, *http.Request) {
t.Helper()
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
switch r.RequestURI {
Expand Down
1 change: 1 addition & 0 deletions applicationset/services/scm_provider/gitlab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
)

func gitlabMockHandler(t *testing.T) func(http.ResponseWriter, *http.Request) {
t.Helper()
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
switch r.RequestURI {
Expand Down
1 change: 1 addition & 0 deletions controller/appcontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2196,6 +2196,7 @@ func TestAlreadyAttemptSync(t *testing.T) {
}

func assertDurationAround(t *testing.T, expected time.Duration, actual time.Duration) {
t.Helper()
delta := time.Second / 2
assert.GreaterOrEqual(t, expected, actual-delta)
assert.LessOrEqual(t, expected, actual+delta)
Expand Down
1 change: 1 addition & 0 deletions controller/metrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ func assertMetricsPrinted(t *testing.T, expectedLines, body string) {

// assertMetricsNotPrinted
func assertMetricsNotPrinted(t *testing.T, expectedLines, body string) {
t.Helper()
for _, line := range strings.Split(expectedLines, "\n") {
if line == "" {
continue
Expand Down
10 changes: 10 additions & 0 deletions controller/sharding/sharding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,7 @@ func TestGetClusterSharding(t *testing.T) {
{
name: "Default sharding with statefulset",
envsSetter: func(t *testing.T) {
t.Helper()
t.Setenv(common.EnvControllerReplicas, "1")
},
cleanup: func() {},
Expand All @@ -847,6 +848,7 @@ func TestGetClusterSharding(t *testing.T) {
{
name: "Default sharding with deployment",
envsSetter: func(t *testing.T) {
t.Helper()
t.Setenv(common.EnvAppControllerName, common.DefaultApplicationControllerName)
},
cleanup: func() {},
Expand All @@ -858,6 +860,7 @@ func TestGetClusterSharding(t *testing.T) {
{
name: "Default sharding with deployment and multiple replicas",
envsSetter: func(t *testing.T) {
t.Helper()
t.Setenv(common.EnvAppControllerName, "argocd-application-controller-multi-replicas")
},
cleanup: func() {},
Expand All @@ -869,6 +872,7 @@ func TestGetClusterSharding(t *testing.T) {
{
name: "Statefulset multiple replicas",
envsSetter: func(t *testing.T) {
t.Helper()
t.Setenv(common.EnvControllerReplicas, "3")
osHostnameFunction = func() (string, error) { return "example-shard-3", nil }
},
Expand All @@ -883,6 +887,7 @@ func TestGetClusterSharding(t *testing.T) {
{
name: "Explicit shard with statefulset and 1 replica",
envsSetter: func(t *testing.T) {
t.Helper()
t.Setenv(common.EnvControllerReplicas, "1")
t.Setenv(common.EnvControllerShard, "3")
},
Expand All @@ -895,6 +900,7 @@ func TestGetClusterSharding(t *testing.T) {
{
name: "Explicit shard with statefulset and 2 replica - and to high shard",
envsSetter: func(t *testing.T) {
t.Helper()
t.Setenv(common.EnvControllerReplicas, "2")
t.Setenv(common.EnvControllerShard, "3")
},
Expand All @@ -907,6 +913,7 @@ func TestGetClusterSharding(t *testing.T) {
{
name: "Explicit shard with statefulset and 2 replica",
envsSetter: func(t *testing.T) {
t.Helper()
t.Setenv(common.EnvControllerReplicas, "2")
t.Setenv(common.EnvControllerShard, "1")
},
Expand All @@ -919,6 +926,7 @@ func TestGetClusterSharding(t *testing.T) {
{
name: "Explicit shard with deployment",
envsSetter: func(t *testing.T) {
t.Helper()
t.Setenv(common.EnvControllerShard, "3")
},
cleanup: func() {},
Expand All @@ -930,6 +938,7 @@ func TestGetClusterSharding(t *testing.T) {
{
name: "Explicit shard with deployment and multiple replicas will read from configmap",
envsSetter: func(t *testing.T) {
t.Helper()
t.Setenv(common.EnvAppControllerName, "argocd-application-controller-multi-replicas")
t.Setenv(common.EnvControllerShard, "3")
},
Expand All @@ -942,6 +951,7 @@ func TestGetClusterSharding(t *testing.T) {
{
name: "Dynamic sharding but missing deployment",
envsSetter: func(t *testing.T) {
t.Helper()
t.Setenv(common.EnvAppControllerName, "missing-deployment")
},
cleanup: func() {},
Expand Down
1 change: 1 addition & 0 deletions controller/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ func TestAppRevisionsMultiSource(t *testing.T) {
}

func toJSON(t *testing.T, obj *unstructured.Unstructured) string {
t.Helper()
data, err := json.Marshal(obj)
require.NoError(t, err)
return string(data)
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/application/v1alpha1/applicationset_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func TestApplicationSetSetConditions(t *testing.T) {
testAppSetCond(ApplicationSetConditionResourcesUpToDate, "bar", tenMinsAgo, ApplicationSetConditionStatusTrue, ApplicationSetReasonApplicationSetUpToDate),
},
validate: func(t *testing.T, a *ApplicationSet) {
t.Helper()
assert.Equal(t, fiveMinsAgo, a.Status.Conditions[0].LastTransitionTime)
assert.Equal(t, tenMinsAgo, a.Status.Conditions[1].LastTransitionTime)
},
Expand All @@ -120,6 +121,7 @@ func TestApplicationSetSetConditions(t *testing.T) {
testAppSetCond(ApplicationSetConditionResourcesUpToDate, "bar", nil, ApplicationSetConditionStatusFalse, ApplicationSetReasonApplicationSetUpToDate),
},
validate: func(t *testing.T, a *ApplicationSet) {
t.Helper()
// SetConditions should add timestamps for new conditions.
assert.True(t, a.Status.Conditions[0].LastTransitionTime.Time.After(fiveMinsAgo.Time))
assert.True(t, a.Status.Conditions[1].LastTransitionTime.Time.After(fiveMinsAgo.Time))
Expand All @@ -141,6 +143,7 @@ func TestApplicationSetSetConditions(t *testing.T) {
testAppSetCond(ApplicationSetConditionResourcesUpToDate, "bar", tenMinsAgo, ApplicationSetConditionStatusTrue, ApplicationSetReasonApplicationSetUpToDate),
},
validate: func(t *testing.T, a *ApplicationSet) {
t.Helper()
assert.Equal(t, tenMinsAgo.Time, a.Status.Conditions[0].LastTransitionTime.Time)
},
},
Expand All @@ -161,6 +164,7 @@ func TestApplicationSetSetConditions(t *testing.T) {
}

func assertAppSetConditions(t *testing.T, expected []ApplicationSetCondition, actual []ApplicationSetCondition) {
t.Helper()
assert.Equal(t, len(expected), len(actual))
for i := range expected {
assert.Equal(t, expected[i].Type, actual[i].Type)
Expand Down
7 changes: 7 additions & 0 deletions pkg/apis/application/v1alpha1/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2982,6 +2982,7 @@ func TestSetConditions(t *testing.T) {
testCond(ApplicationConditionSharedResourceWarning, "bar", tenMinsAgo),
},
validate: func(t *testing.T, a *Application) {
t.Helper()
assert.Equal(t, fiveMinsAgo, a.Status.Conditions[0].LastTransitionTime)
assert.Equal(t, tenMinsAgo, a.Status.Conditions[1].LastTransitionTime)
},
Expand All @@ -3002,6 +3003,7 @@ func TestSetConditions(t *testing.T) {
testCond(ApplicationConditionSharedResourceWarning, "bar", nil),
},
validate: func(t *testing.T, a *Application) {
t.Helper()
// SetConditions should add timestamps for new conditions.
assert.True(t, a.Status.Conditions[0].LastTransitionTime.Time.After(fiveMinsAgo.Time))
assert.True(t, a.Status.Conditions[1].LastTransitionTime.Time.After(fiveMinsAgo.Time))
Expand All @@ -3024,6 +3026,7 @@ func TestSetConditions(t *testing.T) {
testCond(ApplicationConditionSharedResourceWarning, "bar", tenMinsAgo),
},
validate: func(t *testing.T, a *Application) {
t.Helper()
assert.Equal(t, tenMinsAgo.Time, a.Status.Conditions[0].LastTransitionTime.Time)
},
},
Expand Down Expand Up @@ -3059,6 +3062,7 @@ func TestSetConditions(t *testing.T) {
testCond(ApplicationConditionSharedResourceWarning, "bar", tenMinsAgo),
},
validate: func(t *testing.T, a *Application) {
t.Helper()
assert.Equal(t, tenMinsAgo.Time, a.Status.Conditions[0].LastTransitionTime.Time)
assert.Equal(t, tenMinsAgo.Time, a.Status.Conditions[1].LastTransitionTime.Time)
},
Expand All @@ -3082,6 +3086,7 @@ func TestSetConditions(t *testing.T) {
testCond(ApplicationConditionSharedResourceWarning, "bar changed message", fiveMinsAgo),
},
validate: func(t *testing.T, a *Application) {
t.Helper()
assert.Equal(t, tenMinsAgo.Time, a.Status.Conditions[0].LastTransitionTime.Time)
assert.Equal(t, fiveMinsAgo.Time, a.Status.Conditions[1].LastTransitionTime.Time)
},
Expand All @@ -3100,6 +3105,7 @@ func TestSetConditions(t *testing.T) {
testCond(ApplicationConditionSharedResourceWarning, "bar", tenMinsAgo),
},
validate: func(t *testing.T, a *Application) {
t.Helper()
assert.Equal(t, tenMinsAgo.Time, a.Status.Conditions[0].LastTransitionTime.Time)
},
},
Expand All @@ -3121,6 +3127,7 @@ func TestSetConditions(t *testing.T) {
// difficult to strictly assert on as they can use time.Now(). Elements in each array are assumed
// to match positions.
func assertConditions(t *testing.T, expected []ApplicationCondition, actual []ApplicationCondition) {
t.Helper()
assert.Equal(t, len(expected), len(actual))
for i := range expected {
assert.Equal(t, expected[i].Type, actual[i].Type)
Expand Down
1 change: 1 addition & 0 deletions reposerver/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ func TestCachedManifestResponse_HashBehavior(t *testing.T) {
}

func getInMemoryCacheContents(t *testing.T, inMemCache *cacheutil.InMemoryCache) map[string]*CachedManifestResponse {
t.Helper()
items, err := inMemCache.Items(func() interface{} { return &CachedManifestResponse{} })
if err != nil {
t.Fatal(err)
Expand Down
1 change: 1 addition & 0 deletions reposerver/cache/mocks/reposervercache.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions reposerver/metrics/githandlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func TestEdgeCasesAndErrorHandling(t *testing.T) {
{
name: "lsRemoteParallelismLimitSemaphore is nil",
testFunc: func(t *testing.T) {
t.Helper()
lsRemoteParallelismLimitSemaphore = nil
assert.NotPanics(t, func() {
NewGitClientEventHandlers(&MetricsServer{})
Expand All @@ -37,6 +38,7 @@ func TestEdgeCasesAndErrorHandling(t *testing.T) {
lsRemoteParallelismLimitSemaphore = nil
},
testFunc: func(t *testing.T) {
t.Helper()
assert.NotPanics(t, func() {
NewGitClientEventHandlers(&MetricsServer{})
})
Expand All @@ -51,6 +53,7 @@ func TestEdgeCasesAndErrorHandling(t *testing.T) {
lsRemoteParallelismLimitSemaphore = nil
},
testFunc: func(t *testing.T) {
t.Helper()
assert.NotPanics(t, func() {
NewGitClientEventHandlers(&MetricsServer{})
})
Expand Down Expand Up @@ -88,6 +91,7 @@ func TestSemaphoreFunctionality(t *testing.T) {
lsRemoteParallelismLimitSemaphore = nil
},
testFunc: func(t *testing.T) {
t.Helper()
assert.NotPanics(t, func() {
NewGitClientEventHandlers(&MetricsServer{})
})
Expand All @@ -102,6 +106,7 @@ func TestSemaphoreFunctionality(t *testing.T) {
lsRemoteParallelismLimitSemaphore = nil
},
testFunc: func(t *testing.T) {
t.Helper()
assert.NotPanics(t, func() {
NewGitClientEventHandlers(&MetricsServer{})
})
Expand Down
Loading