🌱 Disable more style linters for test files (#3707)

* disable lll linter for test files
* disable goerr113 linter for tests
* disable wrapcheck linter for tests
* fix easy linter issues in tests

---------

Signed-off-by: Spencer Schrock <sschrock@google.com>
This commit is contained in:
Spencer Schrock 2023-12-03 18:14:01 -08:00 committed by GitHub
parent 4d1621b92e
commit 1625b0c578
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
41 changed files with 76 additions and 115 deletions

View File

@ -18,6 +18,9 @@ issues:
- funlen
- goconst
- gocyclo
- goerr113
- lll
- wrapcheck
skip-files:
- cron/data/request.pb.go # autogenerated
linters:

View File

@ -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))
}
})
@ -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"),
},
},
}

View File

@ -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)
}

View File

@ -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{

View File

@ -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

View File

@ -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{

View File

@ -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)
}

View File

@ -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 {

View File

@ -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
@ -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

View File

@ -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

View File

@ -28,7 +28,6 @@ import (
scut "github.com/ossf/scorecard/v4/utests"
)
//nolint:lll
func TestGithubTokenPermissions(t *testing.T) {
t.Parallel()

View File

@ -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
@ -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
@ -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

View File

@ -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 {
@ -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 {

View File

@ -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 {
@ -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 {
@ -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 {
@ -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 {

View File

@ -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,
},
@ -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
@ -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

View File

@ -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{},
},
@ -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

View File

@ -34,7 +34,7 @@ import (
func Test_SAST(t *testing.T) {
t.Parallel()
//nolint:govet,goerr113
//nolint:govet
tests := []struct {
name string
err error

View File

@ -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"),
},
},
}

View File

@ -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)
}
@ -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)
}

View File

@ -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)
}
})
@ -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)
}
})
@ -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)
}
})
@ -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)
}
})
@ -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)
}
})

View File

@ -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
}

View File

@ -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{

View File

@ -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)
}

View File

@ -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{

View File

@ -32,7 +32,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{

View File

@ -390,7 +390,6 @@ func Test_fetchGitRepositoryFromNuget(t *testing.T) {
resultPackageRegistrationPages: []resultPackagePage{},
resultPackageSpec: "",
},
//nolint:lll
want: "internal error: failed to parse nuget package registration index json: invalid character 'e' in literal true (expecting 'r')",
wantErr: true,
},
@ -443,7 +442,6 @@ func Test_fetchGitRepositoryFromNuget(t *testing.T) {
},
resultPackageSpec: "",
},
//nolint:lll
want: "internal error: failed to parse nuget package registration page: invalid character 'e' in literal true (expecting 'r')",
wantErr: true,
},
@ -514,7 +512,6 @@ func Test_fetchGitRepositoryFromNuget(t *testing.T) {
resultPackageSpec: "",
version: "",
},
//nolint:lll
want: "internal error: failed to parse nuget package registration index json: failed to unmarshal json: json: cannot unmarshal number into Go struct field Alias.listed of type bool",
wantErr: true,
},
@ -580,7 +577,6 @@ func nugetIndexOrPageTestResults(url string, test *nugetTest) (*http.Response, e
urlResponseIndex := slices.IndexFunc(test.args.resultPackageRegistrationPages,
func(page resultPackagePage) bool { return page.url == url })
if urlResponseIndex == -1 {
//nolint:goerr113
return nil, errors.New("error")
}
page := test.args.resultPackageRegistrationPages[urlResponseIndex]
@ -597,13 +593,11 @@ func nugetPackageIndexAndSpecResponse(t *testing.T, url string, test *nugetTest)
}
t.Errorf("fetchGitRepositoryFromNuget() version = %v, expected version = %v", url, test.args.version)
}
//nolint:goerr113
return nil, errors.New("error")
}
func testResult(wantErr bool, responseFileName string) (*http.Response, error) {
if wantErr && responseFileName == "" {
//nolint:goerr113
return nil, errors.New("error")
}
if wantErr && responseFileName == "text" {

View File

@ -21,7 +21,6 @@ import (
"testing"
)
//nolint:lll // results are long
func Test_compare(t *testing.T) {
t.Parallel()
//nolint:govet // struct alignment
@ -97,7 +96,6 @@ func (a alwaysErrorReader) Read(b []byte) (n int, err error) {
return 0, io.ErrClosedPipe
}
//nolint:lll // results are long
func Test_compare_reader_err(t *testing.T) {
t.Parallel()
//nolint:govet // struct alignment

View File

@ -31,7 +31,6 @@ type resultCounter struct {
lines int
}
//nolint:wrapcheck
func (rc *resultCounter) Write(p []byte) (n int, err error) {
rc.lines += bytes.Count(p, []byte("\n"))
return rc.b.Write(p)

View File

@ -141,7 +141,6 @@ func Test_fetchGitRepositoryFromNPM(t *testing.T) {
p.EXPECT().Get(gomock.Any(), tt.args.packageName).
DoAndReturn(func(url, packageName string) (*http.Response, error) {
if tt.wantErr && tt.args.result == "" {
//nolint:goerr113
return nil, errors.New("error")
}
@ -316,7 +315,6 @@ func Test_fetchGitRepositoryFromPYPI(t *testing.T) {
name: "fetchGitRepositoryFromPYPI",
args: args{
packageName: "some-package",
//nolint:lll
result: `
{
"info": {
@ -450,7 +448,6 @@ func Test_fetchGitRepositoryFromPYPI(t *testing.T) {
p.EXPECT().Get(gomock.Any(), tt.args.packageName).
DoAndReturn(func(url, packageName string) (*http.Response, error) {
if tt.wantErr && tt.args.result == "" {
//nolint:goerr113
return nil, errors.New("error")
}
@ -487,7 +484,6 @@ func Test_fetchGitRepositoryFromRubyGems(t *testing.T) {
name: "fetchGitRepositoryFromPYPI",
args: args{
packageName: "npm-package",
//nolint:lll
result: `
{
"name": "color",
@ -609,7 +605,6 @@ func Test_fetchGitRepositoryFromRubyGems(t *testing.T) {
name: "empty project url",
args: args{
packageName: "npm-package",
//nolint:lll
result: `
{
"name": "color",
@ -717,7 +712,6 @@ func Test_fetchGitRepositoryFromRubyGems(t *testing.T) {
p.EXPECT().Get(gomock.Any(), tt.args.packageName).
DoAndReturn(func(url, packageName string) (*http.Response, error) {
if tt.wantErr && tt.args.result == "" {
//nolint:goerr113
return nil, errors.New("error")
}
@ -778,7 +772,6 @@ func Test_fetchGitRepositoryFromNuget(t *testing.T) {
n.EXPECT().GitRepositoryByPackageName(tt.args.packageName).
DoAndReturn(func(packageName string) (string, error) {
if tt.wantErr && tt.args.result == "" {
//nolint:goerr113
return "", errors.New("error")
}

View File

@ -70,7 +70,6 @@ func getByteValueFromFile(filename string) ([]byte, error) {
if filename == "" {
return nil, nil
}
//nolint:wrapcheck
return os.ReadFile(filename)
}

View File

@ -33,7 +33,6 @@ func (topic *mockSucceedTopic) Send(ctx context.Context, msg *pubsub.Message) er
type mockFailTopic struct{}
func (topic *mockFailTopic) Send(ctx context.Context, msg *pubsub.Message) error {
//nolint:goerr113
return fmt.Errorf("mockFailTopic failed to send")
}

View File

@ -65,8 +65,7 @@ func TestSubscriber(t *testing.T) {
{
name: "ReceiveFails",
hasErrOnReceive: true,
//nolint:goerr113
errOnReceive: errors.New("mock Receive failure"),
errOnReceive: errors.New("mock Receive failure"),
},
{
name: "ShutdownFails",
@ -78,8 +77,7 @@ func TestSubscriber(t *testing.T) {
},
},
hasErrOnShutdown: true,
//nolint:goerr113
errOnShutdown: errors.New("mock Shutdown close"),
errOnShutdown: errors.New("mock Shutdown close"),
},
}
for _, testcase := range testcases {

View File

@ -247,6 +247,6 @@ func getScorecardResult(repoURL string) (pkg.ScorecardResult, error) {
if err != nil {
return pkg.ScorecardResult{}, fmt.Errorf("couldn't set up clients: %w", err)
}
//nolint:wrapcheck,lll
return pkg.RunScorecard(ctx, repo, clients.HeadSHA, 0, enabledChecks, repoClient, ossFuzzRepoClient, ciiClient, vulnsClient)
}

View File

@ -32,10 +32,10 @@ func TestCreateInternal(t *testing.T) {
}{
name: "non-nil error and non-empty message",
args: args{
e: errors.New("test error"), //nolint:goerr113
e: errors.New("test error"),
msg: "test message",
},
want: fmt.Errorf("test error: test message"), //nolint:goerr113
want: fmt.Errorf("test error: test message"),
}
t.Run(test.name, func(t *testing.T) {

View File

@ -92,7 +92,7 @@ func TestGetName(t *testing.T) {
{
name: "unknown error",
args: args{
err: errors.New("unknown error"), //nolint:goerr113
err: errors.New("unknown error"),
},
want: "ErrUnknown",
},

View File

@ -175,7 +175,7 @@ func TestOptions_AddFlags_Format(t *testing.T) {
cmd := &cobra.Command{}
tt.opts.AddFlags(cmd)
if !cmp.Equal(cmd.Flag(FlagFormat).Value.String(), strings.Join(tt.expected, ", ")) {
t.Errorf("expected FlagFormat to be %q, but got %q", strings.Join(tt.expected, ", "), cmd.Flag(FlagFormat).Value.String()) //nolint:lll
t.Errorf("expected FlagFormat to be %q, but got %q", strings.Join(tt.expected, ", "), cmd.Flag(FlagFormat).Value.String())
}
})
}

View File

@ -583,7 +583,7 @@ func TestJsonScorecardRawResult_AddOssfBestPracticesRawResults(t *testing.T) {
t.Errorf("addOssfBestPracticesRawResults() error = %v, wantError %v", err, test.wantError)
}
if r.Results.OssfBestPractices.Badge != test.input.Badge.String() {
t.Errorf("addOssfBestPracticesRawResults() badge = %v, want %v", r.Results.OssfBestPractices.Badge, test.input.Badge.String()) //nolint:lll
t.Errorf("addOssfBestPracticesRawResults() badge = %v, want %v", r.Results.OssfBestPractices.Badge, test.input.Badge.String())
}
})
}
@ -650,7 +650,7 @@ func TestJsonScorecardRawResult_AddCodeReviewRawResults(t *testing.T) {
t.Errorf("addCodeReviewRawResults() error = %v, wantError %v", err, test.wantError)
}
if len(r.Results.DefaultBranchChangesets) != len(test.input.DefaultBranchChangesets) {
t.Errorf("addCodeReviewRawResults() changesets length = %v, want %v", len(r.Results.DefaultBranchChangesets), len(test.input.DefaultBranchChangesets)) //nolint:lll
t.Errorf("addCodeReviewRawResults() changesets length = %v, want %v", len(r.Results.DefaultBranchChangesets), len(test.input.DefaultBranchChangesets))
}
})
}
@ -724,7 +724,7 @@ func TestAddCodeReviewRawResults(t *testing.T) {
}
if !reflect.DeepEqual(r.Results.DefaultBranchChangesets, expected) {
t.Errorf("addCodeReviewRawResults did not produce the expected output. Got: %v, Expected: %v", r.Results.DefaultBranchChangesets, expected) //nolint:lll
t.Errorf("addCodeReviewRawResults did not produce the expected output. Got: %v, Expected: %v", r.Results.DefaultBranchChangesets, expected)
}
}
@ -820,12 +820,12 @@ func TestAddBinaryArtifactRawResults(t *testing.T) {
}
if len(r.Results.Binaries) != len(expected) {
t.Errorf("addBinaryArtifactRawResults did not add the correct number of files. Expected %d, got %d", len(expected), len(r.Results.Binaries)) //nolint:lll
t.Errorf("addBinaryArtifactRawResults did not add the correct number of files. Expected %d, got %d", len(expected), len(r.Results.Binaries))
}
for i, file := range r.Results.Binaries {
if file.Path != expected[i].Path {
t.Errorf("addBinaryArtifactRawResults did not add the correct file. Expected %s, got %s", expected[i].Path, file.Path) //nolint:lll
t.Errorf("addBinaryArtifactRawResults did not add the correct file. Expected %s, got %s", expected[i].Path, file.Path)
}
}
}
@ -892,25 +892,25 @@ func TestAddSecurityPolicyRawResults(t *testing.T) {
}
if len(r.Results.SecurityPolicies) != len(expected) {
t.Errorf("addSecurityPolicyRawResults did not add the correct number of policies. Expected %d, got %d", len(expected), len(r.Results.SecurityPolicies)) //nolint:lll
t.Errorf("addSecurityPolicyRawResults did not add the correct number of policies. Expected %d, got %d", len(expected), len(r.Results.SecurityPolicies))
}
for i, policy := range r.Results.SecurityPolicies {
if policy.Path != expected[i].Path {
t.Errorf("addSecurityPolicyRawResults did not add the correct policy. Expected %s, got %s", expected[i].Path, policy.Path) //nolint:lll
t.Errorf("addSecurityPolicyRawResults did not add the correct policy. Expected %s, got %s", expected[i].Path, policy.Path)
}
if policy.ContentLength != expected[i].ContentLength {
t.Errorf("addSecurityPolicyRawResults did not add the correct content length. Expected %d, got %d", expected[i].ContentLength, policy.ContentLength) //nolint:lll
t.Errorf("addSecurityPolicyRawResults did not add the correct content length. Expected %d, got %d", expected[i].ContentLength, policy.ContentLength)
}
if len(policy.Hits) != len(expected[i].Hits) {
t.Errorf("addSecurityPolicyRawResults did not add the correct number of hits. Expected %d, got %d", len(expected[i].Hits), len(policy.Hits)) //nolint:lll
t.Errorf("addSecurityPolicyRawResults did not add the correct number of hits. Expected %d, got %d", len(expected[i].Hits), len(policy.Hits))
}
for j, hit := range policy.Hits {
if hit.Type != expected[i].Hits[j].Type {
t.Errorf("addSecurityPolicyRawResults did not add the correct hit type. Expected %s, got %s", expected[i].Hits[j].Type, hit.Type) //nolint:lll
t.Errorf("addSecurityPolicyRawResults did not add the correct hit type. Expected %s, got %s", expected[i].Hits[j].Type, hit.Type)
}
}
}
@ -944,12 +944,12 @@ func TestAddVulnerabilitiesRawResults(t *testing.T) {
}
if len(r.Results.DatabaseVulnerabilities) != len(expected) {
t.Errorf("addVulnerbilitiesRawResults did not add the correct number of vulnerabilities. Expected %d, got %d", len(expected), len(r.Results.DatabaseVulnerabilities)) //nolint:lll
t.Errorf("addVulnerbilitiesRawResults did not add the correct number of vulnerabilities. Expected %d, got %d", len(expected), len(r.Results.DatabaseVulnerabilities))
}
for i, vuln := range r.Results.DatabaseVulnerabilities {
if vuln.ID != expected[i].ID {
t.Errorf("addVulnerbilitiesRawResults did not add the correct vulnerability. Expected %s, got %s", expected[i].ID, vuln.ID) //nolint:lll
t.Errorf("addVulnerbilitiesRawResults did not add the correct vulnerability. Expected %s, got %s", expected[i].ID, vuln.ID)
}
}
}
@ -1016,24 +1016,24 @@ func TestAddFuzzingRawResults(t *testing.T) {
}
if len(r.Results.Fuzzers) != len(expectedFuzzers) {
t.Errorf("addFuzzingRawResults did not add the correct number of fuzzers. Expected %d, got %d", len(expectedFuzzers), len(r.Results.Fuzzers)) //nolint:lll
t.Errorf("addFuzzingRawResults did not add the correct number of fuzzers. Expected %d, got %d", len(expectedFuzzers), len(r.Results.Fuzzers))
}
for i, fuzzer := range r.Results.Fuzzers {
if fuzzer.Name != expectedFuzzers[i].Name {
t.Errorf("addFuzzingRawResults did not add the correct fuzzer name. Expected %s, got %s", expectedFuzzers[i].Name, fuzzer.Name) //nolint:lll
t.Errorf("addFuzzingRawResults did not add the correct fuzzer name. Expected %s, got %s", expectedFuzzers[i].Name, fuzzer.Name)
}
if *fuzzer.URL != *expectedFuzzers[i].URL {
t.Errorf("addFuzzingRawResults did not add the correct fuzzer URL. Expected %s, got %s", *expectedFuzzers[i].URL, *fuzzer.URL) //nolint:lll
t.Errorf("addFuzzingRawResults did not add the correct fuzzer URL. Expected %s, got %s", *expectedFuzzers[i].URL, *fuzzer.URL)
}
if *fuzzer.Desc != *expectedFuzzers[i].Desc {
t.Errorf("addFuzzingRawResults did not add the correct fuzzer description. Expected %s, got %s", *expectedFuzzers[i].Desc, *fuzzer.Desc) //nolint:lll
t.Errorf("addFuzzingRawResults did not add the correct fuzzer description. Expected %s, got %s", *expectedFuzzers[i].Desc, *fuzzer.Desc)
}
if len(fuzzer.Files) != len(expectedFuzzers[i].Files) {
t.Errorf("addFuzzingRawResults did not add the correct number of files for fuzzer %s. Expected %d, got %d", fuzzer.Name, len(expectedFuzzers[i].Files), len(fuzzer.Files)) //nolint:lll
t.Errorf("addFuzzingRawResults did not add the correct number of files for fuzzer %s. Expected %d, got %d", fuzzer.Name, len(expectedFuzzers[i].Files), len(fuzzer.Files))
}
for j, file := range fuzzer.Files {
if file.Path != expectedFuzzers[i].Files[j].Path {
t.Errorf("addFuzzingRawResults did not add the correct file path for fuzzer %s. Expected %s, got %s", fuzzer.Name, expectedFuzzers[i].Files[j].Path, file.Path) //nolint:lll
t.Errorf("addFuzzingRawResults did not add the correct file path for fuzzer %s. Expected %s, got %s", fuzzer.Name, expectedFuzzers[i].Files[j].Path, file.Path)
}
}
}
@ -1137,7 +1137,7 @@ func TestJsonScorecardRawResult(t *testing.T) {
{ID: "CVE-2021-5678"},
}
if cmp.Diff(r.Results.DatabaseVulnerabilities, expectedVulnerabilities) != "" {
t.Errorf("addVulnerbilitiesRawResults did not produce the expected results %v", cmp.Diff(r.Results.DatabaseVulnerabilities, expectedVulnerabilities)) //nolint:lll
t.Errorf("addVulnerbilitiesRawResults did not produce the expected results %v", cmp.Diff(r.Results.DatabaseVulnerabilities, expectedVulnerabilities))
}
// test addBinaryArtifactRawResults
@ -1173,7 +1173,7 @@ func TestJsonScorecardRawResult(t *testing.T) {
},
}
if cmp.Diff(expectedSecurityPolicies, r.Results.SecurityPolicies) != "" {
t.Errorf("addSecurityPolicyRawResults did not produce the expected results %v", cmp.Diff(expectedSecurityPolicies, r.Results.SecurityPolicies)) //nolint:lll
t.Errorf("addSecurityPolicyRawResults did not produce the expected results %v", cmp.Diff(expectedSecurityPolicies, r.Results.SecurityPolicies))
}
// test addFuzzingRawResults
@ -1202,7 +1202,7 @@ func TestJsonScorecardRawResult(t *testing.T) {
},
}
if cmp.Diff(expectedFuzzers, r.Results.Fuzzers, cmpopts.IgnoreFields(jsonTool{}, "URL", "Desc")) != "" {
t.Errorf("addFuzzingRawResults did not produce the expected results %v", cmp.Diff(expectedFuzzers, r.Results.Fuzzers)) //nolint:lll
t.Errorf("addFuzzingRawResults did not produce the expected results %v", cmp.Diff(expectedFuzzers, r.Results.Fuzzers))
}
// test addBranchProtectionRawResults
@ -1224,7 +1224,6 @@ func intPtr(i int32) *int32 {
return &i
}
//nolint:lll
func TestScorecardResult_AsRawJSON(t *testing.T) {
type fields struct {
Repo RepoInfo
@ -1249,7 +1248,7 @@ func TestScorecardResult_AsRawJSON(t *testing.T) {
},
},
wantWriter: `{"date":"0001-01-01","repo":{"name":"bar","commit":"1234567890123456789012345678901234567890"},"scorecard":{"version":"","commit":""},"metadata":null,"results":{"workflows":[],"permissions":{},"licenses":[],"issues":null,"openssfBestPracticesBadge":{"badge":"Unknown"},"databaseVulnerabilities":[],"binaries":[],"securityPolicies":[],"dependencyUpdateTools":[],"branchProtections":{"branches":[],"codeownersFiles":null},"Contributors":{"users":null},"defaultBranchChangesets":[],"archived":{"status":false},"createdAt":{"timestamp":"0001-01-01T00:00:00Z"},"fuzzers":[],"releases":[],"packages":[],"dependencyPinning":{"dependencies":null}}}
`, //nolint:lll
`,
},
}
for _, tt := range tests {

View File

@ -495,7 +495,7 @@ func TestJSONOutput(t *testing.T) {
func TestExperimentalFromJSON2_time(t *testing.T) {
t.Parallel()
//nolint:lll,govet // result strings are long
//nolint:govet
tests := []struct {
name string
result string

View File

@ -52,7 +52,7 @@ func countDetails(c []checker.CheckDetail) (debug, info, warn int) {
return debug, info, warn
}
//nolint:lll,gocritic // comparison was failing with pointer types
//nolint:gocritic // comparison was failing with pointer types
func compareScorecardResults(a, b ScorecardResult) bool {
if a.Repo != b.Repo {
fmt.Fprintf(GinkgoWriter, "Unequal repo details in results: %v vs %v\n", a.Repo, b.Repo)

View File

@ -88,11 +88,9 @@ func Test_Run(t *testing.T) {
Probe: "hasOSVVulnerabilities",
Message: "Project is vulnerable to: foo",
Remediation: &probe.Remediation{
//nolint:lll
Text: `Fix the foo by following information from https://osv.dev/foo.
If the vulnerability is in a dependency, update the dependency to a non-vulnerable version. If no update is available, consider whether to remove the dependency.
If you believe the vulnerability does not affect your project, the vulnerability can be ignored. To ignore, create an osv-scanner.toml file next to the dependency manifest (e.g. package-lock.json) and specify the ID to ignore and reason. Details on the structure of osv-scanner.toml can be found on OSV-Scanner repository.`,
//nolint:lll
Markdown: `Fix the foo by following information from [OSV](https://osv.dev/foo).
If the vulnerability is in a dependency, update the dependency to a non-vulnerable version. If no update is available, consider whether to remove the dependency.
If you believe the vulnerability does not affect your project, the vulnerability can be ignored. To ignore, create an osv-scanner.toml ([example](https://github.com/google/osv.dev/blob/eb99b02ec8895fe5b87d1e76675ddad79a15f817/vulnfeeds/osv-scanner.toml)) file next to the dependency manifest (e.g. package-lock.json) and specify the ID to ignore and reason. Details on the structure of osv-scanner.toml can be found on [OSV-Scanner repository](https://github.com/google/osv-scanner#ignore-vulnerabilities-by-id).`,

View File

@ -66,7 +66,6 @@ func (s stubDigester) Digest(name string) (string, error) {
}
hash, ok := m[name]
if !ok {
//nolint:goerr113
return "", fmt.Errorf("no hash for image: %q", name)
}
return fmt.Sprintf("sha256:%s", hash), nil
@ -75,7 +74,7 @@ func (s stubDigester) Digest(name string) (string, error) {
func TestCreateDockerfilePinningRemediation(t *testing.T) {
t.Parallel()
//nolint:govet,lll
//nolint:govet
tests := []struct {
name string
dep checker.Dependency