Skip to content

Commit 5f3a0e2

Browse files
🌱 Enable golangci-lint test presets (#3594)
* enable test preset Leaves some opinionated linters disabled with reasons. Signed-off-by: Spencer Schrock <[email protected]> * fix tparallel issues. Signed-off-by: Spencer Schrock <[email protected]> --------- Signed-off-by: Spencer Schrock <[email protected]>
1 parent b15b47a commit 5f3a0e2

File tree

10 files changed

+23
-4
lines changed

10 files changed

+23
-4
lines changed

.golangci.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ issues:
2121
skip-files:
2222
- cron/data/request.pb.go # autogenerated
2323
linters:
24-
disable-all: true
2524
enable:
2625
- asciicheck
2726
- dogsled
@@ -70,8 +69,13 @@ linters:
7069
- usestdlibvars
7170
- whitespace
7271
- wrapcheck
72+
disable:
73+
- exhaustruct # initializing every struct makes tests longer without much benefit (spencerschrock)
74+
- paralleltest # need to investigate rate limit issues before re-enabling? (#2527)
75+
- testpackage # tests don't need their own package (spencerschrock)
7376
presets:
7477
- bugs
78+
- test
7579
linters-settings:
7680
errcheck:
7781
check-type-assertions: true

checks/raw/pinned_dependencies_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ func TestGithubWorkflowPinning(t *testing.T) {
102102
}
103103

104104
func TestGithubWorkflowPinningPattern(t *testing.T) {
105+
t.Parallel()
105106
tests := []struct {
106107
desc string
107108
uses string

clients/cii_response_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ func TestBadgeResponse_AsJSON(t *testing.T) {
8686
}
8787

8888
t.Run(tt.name, func(t *testing.T) {
89+
t.Parallel()
8990
resp := BadgeResponse{
9091
BadgeLevel: tt.fields.BadgeLevel,
9192
}

clients/githubrepo/roundtripper/rate_limit_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ func TestRoundTrip(t *testing.T) {
6161
}
6262

6363
t.Run("Successful response", func(t *testing.T) {
64+
t.Parallel()
6465
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, ts.URL+"/success", nil)
6566
if err != nil {
6667
t.Fatalf("Failed to create request: %v", err)
@@ -77,6 +78,7 @@ func TestRoundTrip(t *testing.T) {
7778
})
7879

7980
t.Run("Retry-After header set", func(t *testing.T) {
81+
t.Parallel()
8082
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, ts.URL+"/retry", nil)
8183
if err != nil {
8284
t.Fatalf("Failed to create request: %v", err)

dependencydiff/dependencydiff_test.go

-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ func Test_initRepoAndClientByChecks(t *testing.T) {
5757
for _, tt := range tests {
5858
tt := tt
5959
t.Run(tt.name, func(t *testing.T) {
60-
t.Parallel()
6160
err := initRepoAndClientByChecks(&tt.dCtx, tt.srcRepo)
6261
if (err != nil) != tt.wantErr {
6362
t.Errorf("initClientByChecks() error = {%v}, want error: %v", err, tt.wantErr)
@@ -84,7 +83,6 @@ func Test_initRepoAndClientByChecks(t *testing.T) {
8483
}
8584

8685
func Test_getScorecardCheckResults(t *testing.T) {
87-
//nolint
8886
tests := []struct {
8987
name string
9088
dCtx dependencydiffContext
@@ -104,7 +102,6 @@ func Test_getScorecardCheckResults(t *testing.T) {
104102
for _, tt := range tests {
105103
tt := tt
106104
t.Run(tt.name, func(t *testing.T) {
107-
t.Parallel()
108105
err := getScorecardCheckResults(&tt.dCtx)
109106
if (err != nil) != tt.wantErr {
110107
t.Errorf("getScorecardCheckResults() error = {%v}, want error: %v", err, tt.wantErr)

errors/public_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ func TestWithMessage(t *testing.T) {
4848
},
4949
}
5050
for _, tt := range tests {
51+
tt := tt
5152
t.Run(tt.name, func(t *testing.T) {
53+
t.Parallel()
5254
if err := WithMessage(tt.args.e, tt.args.msg); (err != nil) != tt.wantErr {
5355
t.Errorf("WithMessage() error = %v, wantErr %v", err, tt.wantErr)
5456
}
@@ -96,7 +98,9 @@ func TestGetName(t *testing.T) {
9698
},
9799
}
98100
for _, tt := range tests {
101+
tt := tt
99102
t.Run(tt.name, func(t *testing.T) {
103+
t.Parallel()
100104
if got := GetName(tt.args.err); !strings.EqualFold(got, tt.want) {
101105
t.Errorf("GetName() = %v, want %v", got, tt.want)
102106
}

log/log_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func TestNewLogger(t *testing.T) {
5555
}
5656

5757
func TestParseLevel(t *testing.T) {
58+
t.Parallel()
5859
tests := []struct {
5960
name string
6061
levelStr string

options/flags_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ func TestOptions_AddFlags(t *testing.T) {
120120
}
121121

122122
func TestOptions_AddFlags_ChecksToRun(t *testing.T) {
123+
t.Parallel()
123124
tests := []struct {
124125
name string
125126
opts *Options

policy/policy_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,9 @@ func TestGetEnabled(t *testing.T) {
346346
}
347347

348348
for _, tt := range tests {
349+
tt := tt
349350
t.Run(tt.name, func(t *testing.T) {
351+
t.Parallel()
350352
var sp *ScorecardPolicy
351353
if tt.policyFile != "" {
352354
policyBytes, err := os.ReadFile(tt.policyFile)

rule/rule_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ func TestRisk_GreaterThan(t *testing.T) {
120120
for _, tt := range tests {
121121
tt := tt
122122
t.Run(tt.name, func(t *testing.T) {
123+
t.Parallel()
123124
if got := tt.r.GreaterThan(tt.rr); got != tt.want {
124125
t.Errorf("Risk.GreaterThan() = %v, want %v", got, tt.want)
125126
}
@@ -170,6 +171,7 @@ func TestRisk_String(t *testing.T) {
170171
for _, tt := range tests {
171172
tt := tt
172173
t.Run(tt.name, func(t *testing.T) {
174+
t.Parallel()
173175
if got := tt.r.String(); got != tt.want {
174176
t.Errorf("Risk.String() = %v, want %v", got, tt.want)
175177
}
@@ -215,6 +217,7 @@ func TestRemediationEffort_String(t *testing.T) {
215217
for _, tt := range tests {
216218
tt := tt
217219
t.Run(tt.name, func(t *testing.T) {
220+
t.Parallel()
218221
if got := tt.effort.String(); got != tt.want {
219222
t.Errorf("RemediationEffort.String() = %v, want %v", got, tt.want)
220223
}
@@ -261,6 +264,7 @@ func TestRisk_UnmarshalYAML(t *testing.T) {
261264
for _, tt := range tests {
262265
tt := tt
263266
t.Run(tt.name, func(t *testing.T) {
267+
t.Parallel()
264268
var r Risk
265269
err := yaml.Unmarshal([]byte(tt.input), &r)
266270
if err != nil {
@@ -305,6 +309,7 @@ func TestRemediationEffort_UnmarshalYAML(t *testing.T) {
305309
for _, tt := range tests {
306310
tt := tt
307311
t.Run(tt.name, func(t *testing.T) {
312+
t.Parallel()
308313
var r RemediationEffort
309314
err := yaml.Unmarshal([]byte(tt.input), &r)
310315
if err != nil {
@@ -353,6 +358,7 @@ func Test_validate(t *testing.T) {
353358
for _, tt := range tests {
354359
tt := tt
355360
t.Run(tt.name, func(t *testing.T) {
361+
t.Parallel()
356362
err := validate(tt.rule)
357363
if err != nil {
358364
if tt.wantErr == nil || !cmp.Equal(tt.wantErr.Error(), err.Error()) {

0 commit comments

Comments
 (0)