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

🌱 Enable golangci-lint test presets #3594

Merged
merged 4 commits into from
Oct 27, 2023
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
6 changes: 5 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ issues:
skip-files:
- cron/data/request.pb.go # autogenerated
linters:
disable-all: true
enable:
- asciicheck
- dogsled
Expand Down Expand Up @@ -70,8 +69,13 @@ linters:
- usestdlibvars
- whitespace
- wrapcheck
disable:
- exhaustruct # initializing every struct makes tests longer without much benefit (spencerschrock)
- paralleltest # need to investigate rate limit issues before re-enabling? (#2527)
- testpackage # tests don't need their own package (spencerschrock)
presets:
- bugs
- test
linters-settings:
errcheck:
check-type-assertions: true
Expand Down
1 change: 1 addition & 0 deletions checks/raw/pinned_dependencies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func TestGithubWorkflowPinning(t *testing.T) {
}

func TestGithubWorkflowPinningPattern(t *testing.T) {
t.Parallel()
tests := []struct {
desc string
uses string
Expand Down
1 change: 1 addition & 0 deletions clients/cii_response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func TestBadgeResponse_AsJSON(t *testing.T) {
}

t.Run(tt.name, func(t *testing.T) {
t.Parallel()
resp := BadgeResponse{
BadgeLevel: tt.fields.BadgeLevel,
}
Expand Down
2 changes: 2 additions & 0 deletions clients/githubrepo/roundtripper/rate_limit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func TestRoundTrip(t *testing.T) {
}

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

t.Run("Retry-After header set", func(t *testing.T) {
t.Parallel()
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, ts.URL+"/retry", nil)
if err != nil {
t.Fatalf("Failed to create request: %v", err)
Expand Down
3 changes: 0 additions & 3 deletions dependencydiff/dependencydiff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ func Test_initRepoAndClientByChecks(t *testing.T) {
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
err := initRepoAndClientByChecks(&tt.dCtx, tt.srcRepo)
if (err != nil) != tt.wantErr {
t.Errorf("initClientByChecks() error = {%v}, want error: %v", err, tt.wantErr)
Expand All @@ -84,7 +83,6 @@ func Test_initRepoAndClientByChecks(t *testing.T) {
}

func Test_getScorecardCheckResults(t *testing.T) {
//nolint
tests := []struct {
name string
dCtx dependencydiffContext
Expand All @@ -104,7 +102,6 @@ func Test_getScorecardCheckResults(t *testing.T) {
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
err := getScorecardCheckResults(&tt.dCtx)
if (err != nil) != tt.wantErr {
t.Errorf("getScorecardCheckResults() error = {%v}, want error: %v", err, tt.wantErr)
Expand Down
4 changes: 4 additions & 0 deletions errors/public_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ func TestWithMessage(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if err := WithMessage(tt.args.e, tt.args.msg); (err != nil) != tt.wantErr {
t.Errorf("WithMessage() error = %v, wantErr %v", err, tt.wantErr)
}
Expand Down Expand Up @@ -96,7 +98,9 @@ func TestGetName(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := GetName(tt.args.err); !strings.EqualFold(got, tt.want) {
t.Errorf("GetName() = %v, want %v", got, tt.want)
}
Expand Down
1 change: 1 addition & 0 deletions log/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func TestNewLogger(t *testing.T) {
}

func TestParseLevel(t *testing.T) {
t.Parallel()
tests := []struct {
name string
levelStr string
Expand Down
1 change: 1 addition & 0 deletions options/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func TestOptions_AddFlags(t *testing.T) {
}

func TestOptions_AddFlags_ChecksToRun(t *testing.T) {
t.Parallel()
tests := []struct {
name string
opts *Options
Expand Down
2 changes: 2 additions & 0 deletions policy/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,9 @@ func TestGetEnabled(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
var sp *ScorecardPolicy
if tt.policyFile != "" {
policyBytes, err := os.ReadFile(tt.policyFile)
Expand Down
6 changes: 6 additions & 0 deletions rule/rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func TestRisk_GreaterThan(t *testing.T) {
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := tt.r.GreaterThan(tt.rr); got != tt.want {
t.Errorf("Risk.GreaterThan() = %v, want %v", got, tt.want)
}
Expand Down Expand Up @@ -170,6 +171,7 @@ func TestRisk_String(t *testing.T) {
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := tt.r.String(); got != tt.want {
t.Errorf("Risk.String() = %v, want %v", got, tt.want)
}
Expand Down Expand Up @@ -215,6 +217,7 @@ func TestRemediationEffort_String(t *testing.T) {
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := tt.effort.String(); got != tt.want {
t.Errorf("RemediationEffort.String() = %v, want %v", got, tt.want)
}
Expand Down Expand Up @@ -261,6 +264,7 @@ func TestRisk_UnmarshalYAML(t *testing.T) {
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
var r Risk
err := yaml.Unmarshal([]byte(tt.input), &r)
if err != nil {
Expand Down Expand Up @@ -305,6 +309,7 @@ func TestRemediationEffort_UnmarshalYAML(t *testing.T) {
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
var r RemediationEffort
err := yaml.Unmarshal([]byte(tt.input), &r)
if err != nil {
Expand Down Expand Up @@ -353,6 +358,7 @@ func Test_validate(t *testing.T) {
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
err := validate(tt.rule)
if err != nil {
if tt.wantErr == nil || !cmp.Equal(tt.wantErr.Error(), err.Error()) {
Expand Down