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

🌱 disable more style linters for test files #3707

Merged
merged 5 commits into from
Dec 4, 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
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ issues:
- funlen
- goconst
- gocyclo
- goerr113
- lll
- wrapcheck
skip-files:
- cron/data/request.pb.go # autogenerated
linters:
Expand Down
6 changes: 3 additions & 3 deletions checker/check_result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ func TestCreateProportionalScoreResult(t *testing.T) {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := CreateProportionalScoreResult(tt.args.name, tt.args.reason, tt.args.b, tt.args.t); !cmp.Equal(got, tt.want) { //nolint:lll
if got := CreateProportionalScoreResult(tt.args.name, tt.args.reason, tt.args.b, tt.args.t); !cmp.Equal(got, tt.want) {
t.Errorf("CreateProportionalScoreResult() = %v, want %v", got, cmp.Diff(got, tt.want))
}
})
Expand Down Expand Up @@ -714,14 +714,14 @@ func TestCreateRuntimeErrorResult(t *testing.T) {
name: "empty",
args: args{
name: "",
e: errors.New("runtime error"), //nolint:goerr113
e: errors.New("runtime error"),
},
want: CheckResult{
Name: "",
Reason: "runtime error",
Score: -1,
Version: 2,
Error: errors.New("runtime error"), //nolint:goerr113
Error: errors.New("runtime error"),
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion checker/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestGetClients(t *testing.T) {
t.Setenv("GH_HOST", "github.corp.com")
t.Setenv("GH_TOKEN", "PAT")
}
got, repoClient, ossFuzzClient, ciiClient, vulnsClient, err := GetClients(tt.args.ctx, tt.args.repoURI, tt.args.localURI, tt.args.logger) //nolint:lll
got, repoClient, ossFuzzClient, ciiClient, vulnsClient, err := GetClients(tt.args.ctx, tt.args.repoURI, tt.args.localURI, tt.args.logger)
if (err != nil) != tt.wantErr {
t.Fatalf("GetClients() error = %v, wantErr %v", err, tt.wantErr)
}
Expand Down
1 change: 0 additions & 1 deletion checks/ci_tests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ func TestCITestsRuntimeError(t *testing.T) {

ctrl := gomock.NewController(t)
mockRepoClient := mockrepo.NewMockRepoClient(ctrl)
//nolint:goerr113
mockRepoClient.EXPECT().ListCommits().Return(nil, fmt.Errorf("some runtime error")).AnyTimes()

req := checker.CheckRequest{
Expand Down
1 change: 0 additions & 1 deletion checks/code_review_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
// TestCodeReview tests the code review checker.
func TestCodereview(t *testing.T) {
t.Parallel()
//nolint:goerr113
tests := []struct {
err error
name string
Expand Down
2 changes: 1 addition & 1 deletion checks/contributors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func TestContributors(t *testing.T) {
},
},
{
err: errors.New("error"), //nolint:goerr113
err: errors.New("error"),
name: "Error getting contributors",
contrib: []clients.User{},
expected: checker.CheckResult{
Expand Down
6 changes: 4 additions & 2 deletions checks/evaluation/ci_tests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,10 @@ func Test_prHasSuccessfulCheck(t *testing.T) {
tt := tt
dl := &scut.TestDetailLogger{}

//nolint:errcheck
got, _ := prHasSuccessfulCheck(tt.args, dl)
got, err := prHasSuccessfulCheck(tt.args, dl)
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
if got != tt.want {
t.Errorf("prHasSuccessfulCheck() = %v, want %v", got, tt.want)
}
Expand Down
1 change: 0 additions & 1 deletion checks/fileparser/listing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,6 @@ func TestOnMatchingFileContent(t *testing.T) {
t.Parallel()
x := func(path string, content []byte, args ...interface{}) (bool, error) {
if tt.shouldFuncFail {
//nolint:goerr113
return false, errors.New("test error")
}
if tt.shouldGetPredicateFail {
Expand Down
2 changes: 0 additions & 2 deletions checks/fuzzing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ func TestFuzzing(t *testing.T) {
mockFuzz.EXPECT().Search(gomock.Any()).
DoAndReturn(func(q clients.SearchRequest) (clients.SearchResponse, error) {
if tt.wantErr {
//nolint:goerr113
return clients.SearchResponse{}, errors.New("error")
}
return tt.response, nil
Expand All @@ -148,7 +147,6 @@ func TestFuzzing(t *testing.T) {
mockFuzz.EXPECT().ListFiles(gomock.Any()).Return(tt.fileName, nil).AnyTimes()
mockFuzz.EXPECT().GetFileContent(gomock.Any()).DoAndReturn(func(f string) (string, error) {
if tt.wantErr {
//nolint:goerr113
return "", errors.New("error")
}
return tt.fileContent, nil
Expand Down
2 changes: 1 addition & 1 deletion checks/maintained_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func Test_Maintained(t *testing.T) {
otheruser := clients.User{
Login: "someone-else",
}
//nolint:govet,goerr113
//nolint:govet
tests := []struct {
err error
name string
Expand Down
1 change: 0 additions & 1 deletion checks/permissions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
scut "github.com/ossf/scorecard/v4/utests"
)

//nolint:lll
func TestGithubTokenPermissions(t *testing.T) {
t.Parallel()

Expand Down
3 changes: 0 additions & 3 deletions checks/raw/fuzzing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ func Test_checkOSSFuzz(t *testing.T) {
mockFuzz.EXPECT().Search(gomock.Any()).
DoAndReturn(func(q clients.SearchRequest) (clients.SearchResponse, error) {
if tt.wantErr {
//nolint:goerr113
return clients.SearchResponse{}, errors.New("error")
}
return tt.response, nil
Expand Down Expand Up @@ -138,7 +137,6 @@ func Test_checkCFLite(t *testing.T) {
mockFuzz.EXPECT().ListFiles(gomock.Any()).Return(tt.fileName, nil).AnyTimes()
mockFuzz.EXPECT().GetFileContent(gomock.Any()).DoAndReturn(func(f string) (string, error) {
if tt.wantErr {
//nolint:goerr113
return "", errors.New("error")
}
return tt.fileContent, nil
Expand Down Expand Up @@ -490,7 +488,6 @@ func Test_checkFuzzFunc(t *testing.T) {
mockClient.EXPECT().ListFiles(gomock.Any()).Return(tt.fileName, nil).AnyTimes()
mockClient.EXPECT().GetFileContent(gomock.Any()).DoAndReturn(func(f string) ([]byte, error) {
if tt.wantErr {
//nolint:goerr113
return nil, errors.New("error")
}
return []byte(tt.fileContent), nil
Expand Down
11 changes: 6 additions & 5 deletions checks/raw/gitlab/packaging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,8 @@ func TestGitlabPackagingPackager(t *testing.T) {

moqRepoClient.EXPECT().GetFileContent(tt.filename).
DoAndReturn(func(b string) ([]byte, error) {
//nolint:errcheck
content, _ := os.ReadFile(b)
return content, nil
content, err := os.ReadFile(b)
return content, err
}).AnyTimes()

if tt.exists {
Expand All @@ -150,8 +149,10 @@ func TestGitlabPackagingPackager(t *testing.T) {
Repo: moqRepo,
}

//nolint:errcheck
packagingData, _ := Packaging(&req)
packagingData, err := Packaging(&req)
if err != nil {
t.Fatalf("unexpected err: %v", err)
}

if !tt.exists {
if len(packagingData.Packages) != 0 {
Expand Down
8 changes: 4 additions & 4 deletions checks/raw/maintained_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func TestMaintained(t *testing.T) {
})

t.Run("returns error if IsArchived fails", func(t *testing.T) {
mockRepoClient.EXPECT().IsArchived().Return(false, fmt.Errorf("some error")) //nolint:goerr113
mockRepoClient.EXPECT().IsArchived().Return(false, fmt.Errorf("some error"))

_, err := Maintained(req)
if err == nil {
Expand All @@ -88,7 +88,7 @@ func TestMaintained(t *testing.T) {

t.Run("returns error if ListCommits fails", func(t *testing.T) {
mockRepoClient.EXPECT().IsArchived().Return(false, nil)
mockRepoClient.EXPECT().ListCommits().Return(nil, fmt.Errorf("some error")) //nolint:goerr113
mockRepoClient.EXPECT().ListCommits().Return(nil, fmt.Errorf("some error"))

_, err := Maintained(req)
if err == nil {
Expand All @@ -99,7 +99,7 @@ func TestMaintained(t *testing.T) {
t.Run("returns error if ListIssues fails", func(t *testing.T) {
mockRepoClient.EXPECT().IsArchived().Return(false, nil)
mockRepoClient.EXPECT().ListCommits().Return([]clients.Commit{}, nil)
mockRepoClient.EXPECT().ListIssues().Return(nil, fmt.Errorf("some error")) //nolint:goerr113
mockRepoClient.EXPECT().ListIssues().Return(nil, fmt.Errorf("some error"))

_, err := Maintained(req)
if err == nil {
Expand All @@ -111,7 +111,7 @@ func TestMaintained(t *testing.T) {
mockRepoClient.EXPECT().IsArchived().Return(false, nil)
mockRepoClient.EXPECT().ListCommits().Return([]clients.Commit{}, nil)
mockRepoClient.EXPECT().ListIssues().Return([]clients.Issue{}, nil)
mockRepoClient.EXPECT().GetCreatedAt().Return(time.Time{}, fmt.Errorf("some error")) //nolint:goerr113
mockRepoClient.EXPECT().GetCreatedAt().Return(time.Time{}, fmt.Errorf("some error"))

_, err := Maintained(req)
if err == nil {
Expand Down
10 changes: 4 additions & 6 deletions checks/raw/pinned_dependencies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,12 @@ func TestGithubWorkflowPinningPattern(t *testing.T) {
ispinned: true,
},
{
desc: "non-github docker image pinned by digest",
//nolint:lll
desc: "non-github docker image pinned by digest",
uses: "docker://gcr.io/distroless/static-debian11@sha256:9e6f8952f12974d088f648ed6252ea1887cdd8641719c8acd36bf6d2537e71c0",
ispinned: true,
},
{
desc: "non-github docker image pinned to mutable tag",
//nolint:lll
desc: "non-github docker image pinned to mutable tag",
uses: "docker://gcr.io/distroless/static-debian11:sha256-3876708467ad6f38f263774aa107d331e8de6558a2874aa223b96fc0d9dfc820.sig",
ispinned: false,
},
Expand Down Expand Up @@ -635,7 +633,7 @@ func TestDockerfileInvalidFiles(t *testing.T) {

func TestDockerfileInsecureDownloadsLineNumber(t *testing.T) {
t.Parallel()
//nolint:govet,lll
//nolint:govet
tests := []struct {
name string
filename string
Expand Down Expand Up @@ -847,7 +845,7 @@ func TestDockerfileInsecureDownloadsLineNumber(t *testing.T) {

func TestShellscriptInsecureDownloadsLineNumber(t *testing.T) {
t.Parallel()
//nolint:govet,lll
//nolint:govet
tests := []struct {
name string
filename string
Expand Down
6 changes: 2 additions & 4 deletions checks/raw/vulnerabilities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ func TestVulnerabilities(t *testing.T) {
numberofCommits: 1,
},
{
name: "err response",
wantErr: true,
//nolint:goerr113
name: "err response",
wantErr: true,
err: errors.New("error"),
vulnsResponse: clients.VulnerabilitiesResponse{},
},
Expand Down Expand Up @@ -93,7 +92,6 @@ func TestVulnerabilities(t *testing.T) {
mockVulnClient.EXPECT().ListUnfixedVulnerabilities(context.TODO(), gomock.Any(), gomock.Any()).DoAndReturn(
func(ctx context.Context, commit string, localPath string) (clients.VulnerabilitiesResponse, error) {
if tt.vulnsError {
//nolint:goerr113
return clients.VulnerabilitiesResponse{}, errors.New("error")
}
return tt.vulnsResponse, tt.err
Expand Down
2 changes: 1 addition & 1 deletion checks/sast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
func Test_SAST(t *testing.T) {
t.Parallel()

//nolint:govet,goerr113
//nolint:govet
tests := []struct {
name string
err error
Expand Down
4 changes: 2 additions & 2 deletions checks/signed_releases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,10 @@ func TestSignedRelease(t *testing.T) {

{
name: "Error getting releases",
err: errors.New("Error getting releases"), //nolint:goerr113
err: errors.New("Error getting releases"),
expected: checker.CheckResult{
Score: -1,
Error: errors.New("Error getting releases"), //nolint:goerr113
Error: errors.New("Error getting releases"),
},
},
}
Expand Down
4 changes: 2 additions & 2 deletions clients/git/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func createTestRepo(t *testing.T) (path string) {

// Create a new file
filePath := filepath.Join(dir, "file")
err = os.WriteFile(filePath, []byte("Hello, World!"), 0o644) //nolint:gosec
err = os.WriteFile(filePath, []byte("Hello, World!"), 0o600)
if err != nil {
t.Fatalf("Failed to write a file: %v", err)
}
Expand Down Expand Up @@ -185,7 +185,7 @@ func TestSearch(t *testing.T) {
// Use the same test repo for all test cases.
repoPath := createTestRepo(t)
filePath := filepath.Join(repoPath, "test.txt")
err := os.WriteFile(filePath, []byte("Hello, World!"), 0o644) //nolint:gosec
err := os.WriteFile(filePath, []byte("Hello, World!"), 0o600)
if err != nil {
t.Fatalf("WriteFile() failed: %v", err)
}
Expand Down
10 changes: 5 additions & 5 deletions clients/githubrepo/copy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestCopyBoolPtr(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
copyBoolPtr(tt.src, tt.dest)
if (tt.want == nil && *tt.dest != nil) || (tt.want != nil && *tt.dest == nil) || (tt.want != nil && *tt.dest != nil && **tt.dest != *tt.want) { //nolint:lll
if (tt.want == nil && *tt.dest != nil) || (tt.want != nil && *tt.dest == nil) || (tt.want != nil && *tt.dest != nil && **tt.dest != *tt.want) {
t.Errorf("copyBoolPtr() got = %v, want %v", *tt.dest, tt.want)
}
})
Expand Down Expand Up @@ -103,7 +103,7 @@ func TestCopyInt32Ptr(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
copyInt32Ptr(tt.src, tt.dest)
if (tt.want == nil && *tt.dest != nil) || (tt.want != nil && *tt.dest == nil) || (tt.want != nil && *tt.dest != nil && **tt.dest != *tt.want) { //nolint:lll
if (tt.want == nil && *tt.dest != nil) || (tt.want != nil && *tt.dest == nil) || (tt.want != nil && *tt.dest != nil && **tt.dest != *tt.want) {
t.Errorf("copyInt32Ptr() got = %v, want %v", *tt.dest, tt.want)
}
})
Expand Down Expand Up @@ -153,7 +153,7 @@ func TestCopyStringPtr(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
copyStringPtr(tt.src, tt.dest)
if (tt.want == nil && *tt.dest != nil) || (tt.want != nil && *tt.dest == nil) || (tt.want != nil && *tt.dest != nil && **tt.dest != *tt.want) { //nolint:lll
if (tt.want == nil && *tt.dest != nil) || (tt.want != nil && *tt.dest == nil) || (tt.want != nil && *tt.dest != nil && **tt.dest != *tt.want) {
t.Errorf("copyStringPtr() got = %v, want %v", *tt.dest, tt.want)
}
})
Expand Down Expand Up @@ -201,7 +201,7 @@ func TestCopyTimePtr(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
copyTimePtr(tt.src, tt.dest)
if (tt.want == nil && *tt.dest != nil) || (tt.want != nil && *tt.dest == nil) || (tt.want != nil && *tt.dest != nil && !(*tt.dest).Equal(*tt.want)) { //nolint:lll
if (tt.want == nil && *tt.dest != nil) || (tt.want != nil && *tt.dest == nil) || (tt.want != nil && *tt.dest != nil && !(*tt.dest).Equal(*tt.want)) {
t.Errorf("copyTimePtr() got = %v, want %v", *tt.dest, tt.want)
}
})
Expand Down Expand Up @@ -283,7 +283,7 @@ func TestCopyRepoAssociationPtr(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
copyRepoAssociationPtr(tt.src, tt.dest)
if (tt.want == nil && *tt.dest != nil) || (tt.want != nil && *tt.dest == nil) || (tt.want != nil && *tt.dest != nil && !reflect.DeepEqual(**tt.dest, *tt.want)) { //nolint:lll
if (tt.want == nil && *tt.dest != nil) || (tt.want != nil && *tt.dest == nil) || (tt.want != nil && *tt.dest != nil && !reflect.DeepEqual(**tt.dest, *tt.want)) {
t.Errorf("copyRepoAssociationPtr() got = %v, want %v", *tt.dest, tt.want)
}
})
Expand Down
6 changes: 0 additions & 6 deletions clients/githubrepo/roundtripper/tokens/accessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,9 @@ func testServer(t *testing.T) {
serverURL := strings.TrimPrefix(server.URL, "http://")
t.Setenv("GITHUB_AUTH_SERVER", serverURL)
t.Cleanup(server.Close)
myRPCService := &MyRPCService{}
rpc.Register(myRPCService) //nolint:errcheck
rpc.HandleHTTP()
got := MakeTokenAccessor()
if got == nil {
t.Errorf("MakeTokenAccessor() = nil, want not nil")
}
}

type MyRPCService struct {
// Define your RPC service methods here
}
1 change: 0 additions & 1 deletion clients/githubrepo/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ type stubTripper struct {
func (s stubTripper) RoundTrip(_ *http.Request) (*http.Response, error) {
f, err := os.Open(s.responsePath)
if err != nil {
//nolint:wrapcheck
return nil, err
}
return &http.Response{
Expand Down
9 changes: 5 additions & 4 deletions clients/gitlabrepo/branches_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,12 @@ func TestGetBranches(t *testing.T) {

handler.once.Do(func() {})

//nolint:errcheck
br, _ := handler.getBranch(tt.branchName)
br, err := handler.getBranch(tt.branchName)
if err != nil {
t.Fatalf("unexpected err: %v", err)
}

//nolint:unconvert
if string(*br.Name) != tt.expectedBranchName {
if *br.Name != tt.expectedBranchName {
t.Errorf("Branch Name (%s) didn't match expected value (%s)", *br.Name, tt.expectedBranchName)
}

Expand Down
1 change: 0 additions & 1 deletion clients/gitlabrepo/issues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func (s suffixStubTripper) RoundTrip(r *http.Request) (*http.Response, error) {
suffix := pathParts[len(pathParts)-1]
f, err := os.Open(s.responsePaths[suffix])
if err != nil {
//nolint:wrapcheck
return nil, err
}
return &http.Response{
Expand Down
Loading
Loading