mirror of
https://github.com/ossf/scorecard.git
synced 2024-09-11 08:55:27 +03:00
🌱 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:
parent
4d1621b92e
commit
1625b0c578
@ -18,6 +18,9 @@ issues:
|
|||||||
- funlen
|
- funlen
|
||||||
- goconst
|
- goconst
|
||||||
- gocyclo
|
- gocyclo
|
||||||
|
- goerr113
|
||||||
|
- lll
|
||||||
|
- wrapcheck
|
||||||
skip-files:
|
skip-files:
|
||||||
- cron/data/request.pb.go # autogenerated
|
- cron/data/request.pb.go # autogenerated
|
||||||
linters:
|
linters:
|
||||||
|
@ -545,7 +545,7 @@ func TestCreateProportionalScoreResult(t *testing.T) {
|
|||||||
tt := tt
|
tt := tt
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
t.Parallel()
|
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))
|
t.Errorf("CreateProportionalScoreResult() = %v, want %v", got, cmp.Diff(got, tt.want))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -714,14 +714,14 @@ func TestCreateRuntimeErrorResult(t *testing.T) {
|
|||||||
name: "empty",
|
name: "empty",
|
||||||
args: args{
|
args: args{
|
||||||
name: "",
|
name: "",
|
||||||
e: errors.New("runtime error"), //nolint:goerr113
|
e: errors.New("runtime error"),
|
||||||
},
|
},
|
||||||
want: CheckResult{
|
want: CheckResult{
|
||||||
Name: "",
|
Name: "",
|
||||||
Reason: "runtime error",
|
Reason: "runtime error",
|
||||||
Score: -1,
|
Score: -1,
|
||||||
Version: 2,
|
Version: 2,
|
||||||
Error: errors.New("runtime error"), //nolint:goerr113
|
Error: errors.New("runtime error"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,7 @@ func TestGetClients(t *testing.T) {
|
|||||||
t.Setenv("GH_HOST", "github.corp.com")
|
t.Setenv("GH_HOST", "github.corp.com")
|
||||||
t.Setenv("GH_TOKEN", "PAT")
|
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 {
|
if (err != nil) != tt.wantErr {
|
||||||
t.Fatalf("GetClients() error = %v, wantErr %v", err, tt.wantErr)
|
t.Fatalf("GetClients() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,6 @@ func TestCITestsRuntimeError(t *testing.T) {
|
|||||||
|
|
||||||
ctrl := gomock.NewController(t)
|
ctrl := gomock.NewController(t)
|
||||||
mockRepoClient := mockrepo.NewMockRepoClient(ctrl)
|
mockRepoClient := mockrepo.NewMockRepoClient(ctrl)
|
||||||
//nolint:goerr113
|
|
||||||
mockRepoClient.EXPECT().ListCommits().Return(nil, fmt.Errorf("some runtime error")).AnyTimes()
|
mockRepoClient.EXPECT().ListCommits().Return(nil, fmt.Errorf("some runtime error")).AnyTimes()
|
||||||
|
|
||||||
req := checker.CheckRequest{
|
req := checker.CheckRequest{
|
||||||
|
@ -30,7 +30,6 @@ import (
|
|||||||
// TestCodeReview tests the code review checker.
|
// TestCodeReview tests the code review checker.
|
||||||
func TestCodereview(t *testing.T) {
|
func TestCodereview(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
//nolint:goerr113
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
err error
|
err error
|
||||||
name string
|
name string
|
||||||
|
@ -143,7 +143,7 @@ func TestContributors(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
err: errors.New("error"), //nolint:goerr113
|
err: errors.New("error"),
|
||||||
name: "Error getting contributors",
|
name: "Error getting contributors",
|
||||||
contrib: []clients.User{},
|
contrib: []clients.User{},
|
||||||
expected: checker.CheckResult{
|
expected: checker.CheckResult{
|
||||||
|
@ -192,8 +192,10 @@ func Test_prHasSuccessfulCheck(t *testing.T) {
|
|||||||
tt := tt
|
tt := tt
|
||||||
dl := &scut.TestDetailLogger{}
|
dl := &scut.TestDetailLogger{}
|
||||||
|
|
||||||
//nolint:errcheck
|
got, err := prHasSuccessfulCheck(tt.args, dl)
|
||||||
got, _ := prHasSuccessfulCheck(tt.args, dl)
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected err: %v", err)
|
||||||
|
}
|
||||||
if got != tt.want {
|
if got != tt.want {
|
||||||
t.Errorf("prHasSuccessfulCheck() = %v, want %v", got, tt.want)
|
t.Errorf("prHasSuccessfulCheck() = %v, want %v", got, tt.want)
|
||||||
}
|
}
|
||||||
|
@ -515,7 +515,6 @@ func TestOnMatchingFileContent(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
x := func(path string, content []byte, args ...interface{}) (bool, error) {
|
x := func(path string, content []byte, args ...interface{}) (bool, error) {
|
||||||
if tt.shouldFuncFail {
|
if tt.shouldFuncFail {
|
||||||
//nolint:goerr113
|
|
||||||
return false, errors.New("test error")
|
return false, errors.New("test error")
|
||||||
}
|
}
|
||||||
if tt.shouldGetPredicateFail {
|
if tt.shouldGetPredicateFail {
|
||||||
|
@ -139,7 +139,6 @@ func TestFuzzing(t *testing.T) {
|
|||||||
mockFuzz.EXPECT().Search(gomock.Any()).
|
mockFuzz.EXPECT().Search(gomock.Any()).
|
||||||
DoAndReturn(func(q clients.SearchRequest) (clients.SearchResponse, error) {
|
DoAndReturn(func(q clients.SearchRequest) (clients.SearchResponse, error) {
|
||||||
if tt.wantErr {
|
if tt.wantErr {
|
||||||
//nolint:goerr113
|
|
||||||
return clients.SearchResponse{}, errors.New("error")
|
return clients.SearchResponse{}, errors.New("error")
|
||||||
}
|
}
|
||||||
return tt.response, nil
|
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().ListFiles(gomock.Any()).Return(tt.fileName, nil).AnyTimes()
|
||||||
mockFuzz.EXPECT().GetFileContent(gomock.Any()).DoAndReturn(func(f string) (string, error) {
|
mockFuzz.EXPECT().GetFileContent(gomock.Any()).DoAndReturn(func(f string) (string, error) {
|
||||||
if tt.wantErr {
|
if tt.wantErr {
|
||||||
//nolint:goerr113
|
|
||||||
return "", errors.New("error")
|
return "", errors.New("error")
|
||||||
}
|
}
|
||||||
return tt.fileContent, nil
|
return tt.fileContent, nil
|
||||||
|
@ -44,7 +44,7 @@ func Test_Maintained(t *testing.T) {
|
|||||||
otheruser := clients.User{
|
otheruser := clients.User{
|
||||||
Login: "someone-else",
|
Login: "someone-else",
|
||||||
}
|
}
|
||||||
//nolint:govet,goerr113
|
//nolint:govet
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
err error
|
err error
|
||||||
name string
|
name string
|
||||||
|
@ -28,7 +28,6 @@ import (
|
|||||||
scut "github.com/ossf/scorecard/v4/utests"
|
scut "github.com/ossf/scorecard/v4/utests"
|
||||||
)
|
)
|
||||||
|
|
||||||
//nolint:lll
|
|
||||||
func TestGithubTokenPermissions(t *testing.T) {
|
func TestGithubTokenPermissions(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
@ -76,7 +76,6 @@ func Test_checkOSSFuzz(t *testing.T) {
|
|||||||
mockFuzz.EXPECT().Search(gomock.Any()).
|
mockFuzz.EXPECT().Search(gomock.Any()).
|
||||||
DoAndReturn(func(q clients.SearchRequest) (clients.SearchResponse, error) {
|
DoAndReturn(func(q clients.SearchRequest) (clients.SearchResponse, error) {
|
||||||
if tt.wantErr {
|
if tt.wantErr {
|
||||||
//nolint:goerr113
|
|
||||||
return clients.SearchResponse{}, errors.New("error")
|
return clients.SearchResponse{}, errors.New("error")
|
||||||
}
|
}
|
||||||
return tt.response, nil
|
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().ListFiles(gomock.Any()).Return(tt.fileName, nil).AnyTimes()
|
||||||
mockFuzz.EXPECT().GetFileContent(gomock.Any()).DoAndReturn(func(f string) (string, error) {
|
mockFuzz.EXPECT().GetFileContent(gomock.Any()).DoAndReturn(func(f string) (string, error) {
|
||||||
if tt.wantErr {
|
if tt.wantErr {
|
||||||
//nolint:goerr113
|
|
||||||
return "", errors.New("error")
|
return "", errors.New("error")
|
||||||
}
|
}
|
||||||
return tt.fileContent, nil
|
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().ListFiles(gomock.Any()).Return(tt.fileName, nil).AnyTimes()
|
||||||
mockClient.EXPECT().GetFileContent(gomock.Any()).DoAndReturn(func(f string) ([]byte, error) {
|
mockClient.EXPECT().GetFileContent(gomock.Any()).DoAndReturn(func(f string) ([]byte, error) {
|
||||||
if tt.wantErr {
|
if tt.wantErr {
|
||||||
//nolint:goerr113
|
|
||||||
return nil, errors.New("error")
|
return nil, errors.New("error")
|
||||||
}
|
}
|
||||||
return []byte(tt.fileContent), nil
|
return []byte(tt.fileContent), nil
|
||||||
|
@ -136,9 +136,8 @@ func TestGitlabPackagingPackager(t *testing.T) {
|
|||||||
|
|
||||||
moqRepoClient.EXPECT().GetFileContent(tt.filename).
|
moqRepoClient.EXPECT().GetFileContent(tt.filename).
|
||||||
DoAndReturn(func(b string) ([]byte, error) {
|
DoAndReturn(func(b string) ([]byte, error) {
|
||||||
//nolint:errcheck
|
content, err := os.ReadFile(b)
|
||||||
content, _ := os.ReadFile(b)
|
return content, err
|
||||||
return content, nil
|
|
||||||
}).AnyTimes()
|
}).AnyTimes()
|
||||||
|
|
||||||
if tt.exists {
|
if tt.exists {
|
||||||
@ -150,8 +149,10 @@ func TestGitlabPackagingPackager(t *testing.T) {
|
|||||||
Repo: moqRepo,
|
Repo: moqRepo,
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint:errcheck
|
packagingData, err := Packaging(&req)
|
||||||
packagingData, _ := Packaging(&req)
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected err: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
if !tt.exists {
|
if !tt.exists {
|
||||||
if len(packagingData.Packages) != 0 {
|
if len(packagingData.Packages) != 0 {
|
||||||
|
@ -78,7 +78,7 @@ func TestMaintained(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("returns error if IsArchived fails", func(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)
|
_, err := Maintained(req)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -88,7 +88,7 @@ func TestMaintained(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("returns error if ListCommits fails", func(t *testing.T) {
|
t.Run("returns error if ListCommits fails", func(t *testing.T) {
|
||||||
mockRepoClient.EXPECT().IsArchived().Return(false, nil)
|
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)
|
_, err := Maintained(req)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -99,7 +99,7 @@ func TestMaintained(t *testing.T) {
|
|||||||
t.Run("returns error if ListIssues fails", func(t *testing.T) {
|
t.Run("returns error if ListIssues fails", func(t *testing.T) {
|
||||||
mockRepoClient.EXPECT().IsArchived().Return(false, nil)
|
mockRepoClient.EXPECT().IsArchived().Return(false, nil)
|
||||||
mockRepoClient.EXPECT().ListCommits().Return([]clients.Commit{}, 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)
|
_, err := Maintained(req)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -111,7 +111,7 @@ func TestMaintained(t *testing.T) {
|
|||||||
mockRepoClient.EXPECT().IsArchived().Return(false, nil)
|
mockRepoClient.EXPECT().IsArchived().Return(false, nil)
|
||||||
mockRepoClient.EXPECT().ListCommits().Return([]clients.Commit{}, nil)
|
mockRepoClient.EXPECT().ListCommits().Return([]clients.Commit{}, nil)
|
||||||
mockRepoClient.EXPECT().ListIssues().Return([]clients.Issue{}, 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)
|
_, err := Maintained(req)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -159,14 +159,12 @@ func TestGithubWorkflowPinningPattern(t *testing.T) {
|
|||||||
ispinned: true,
|
ispinned: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "non-github docker image pinned by digest",
|
desc: "non-github docker image pinned by digest",
|
||||||
//nolint:lll
|
|
||||||
uses: "docker://gcr.io/distroless/static-debian11@sha256:9e6f8952f12974d088f648ed6252ea1887cdd8641719c8acd36bf6d2537e71c0",
|
uses: "docker://gcr.io/distroless/static-debian11@sha256:9e6f8952f12974d088f648ed6252ea1887cdd8641719c8acd36bf6d2537e71c0",
|
||||||
ispinned: true,
|
ispinned: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "non-github docker image pinned to mutable tag",
|
desc: "non-github docker image pinned to mutable tag",
|
||||||
//nolint:lll
|
|
||||||
uses: "docker://gcr.io/distroless/static-debian11:sha256-3876708467ad6f38f263774aa107d331e8de6558a2874aa223b96fc0d9dfc820.sig",
|
uses: "docker://gcr.io/distroless/static-debian11:sha256-3876708467ad6f38f263774aa107d331e8de6558a2874aa223b96fc0d9dfc820.sig",
|
||||||
ispinned: false,
|
ispinned: false,
|
||||||
},
|
},
|
||||||
@ -635,7 +633,7 @@ func TestDockerfileInvalidFiles(t *testing.T) {
|
|||||||
|
|
||||||
func TestDockerfileInsecureDownloadsLineNumber(t *testing.T) {
|
func TestDockerfileInsecureDownloadsLineNumber(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
//nolint:govet,lll
|
//nolint:govet
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
filename string
|
filename string
|
||||||
@ -847,7 +845,7 @@ func TestDockerfileInsecureDownloadsLineNumber(t *testing.T) {
|
|||||||
|
|
||||||
func TestShellscriptInsecureDownloadsLineNumber(t *testing.T) {
|
func TestShellscriptInsecureDownloadsLineNumber(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
//nolint:govet,lll
|
//nolint:govet
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
filename string
|
filename string
|
||||||
|
@ -47,9 +47,8 @@ func TestVulnerabilities(t *testing.T) {
|
|||||||
numberofCommits: 1,
|
numberofCommits: 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "err response",
|
name: "err response",
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
//nolint:goerr113
|
|
||||||
err: errors.New("error"),
|
err: errors.New("error"),
|
||||||
vulnsResponse: clients.VulnerabilitiesResponse{},
|
vulnsResponse: clients.VulnerabilitiesResponse{},
|
||||||
},
|
},
|
||||||
@ -93,7 +92,6 @@ func TestVulnerabilities(t *testing.T) {
|
|||||||
mockVulnClient.EXPECT().ListUnfixedVulnerabilities(context.TODO(), gomock.Any(), gomock.Any()).DoAndReturn(
|
mockVulnClient.EXPECT().ListUnfixedVulnerabilities(context.TODO(), gomock.Any(), gomock.Any()).DoAndReturn(
|
||||||
func(ctx context.Context, commit string, localPath string) (clients.VulnerabilitiesResponse, error) {
|
func(ctx context.Context, commit string, localPath string) (clients.VulnerabilitiesResponse, error) {
|
||||||
if tt.vulnsError {
|
if tt.vulnsError {
|
||||||
//nolint:goerr113
|
|
||||||
return clients.VulnerabilitiesResponse{}, errors.New("error")
|
return clients.VulnerabilitiesResponse{}, errors.New("error")
|
||||||
}
|
}
|
||||||
return tt.vulnsResponse, tt.err
|
return tt.vulnsResponse, tt.err
|
||||||
|
@ -34,7 +34,7 @@ import (
|
|||||||
func Test_SAST(t *testing.T) {
|
func Test_SAST(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
//nolint:govet,goerr113
|
//nolint:govet
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
err error
|
err error
|
||||||
|
@ -364,10 +364,10 @@ func TestSignedRelease(t *testing.T) {
|
|||||||
|
|
||||||
{
|
{
|
||||||
name: "Error getting releases",
|
name: "Error getting releases",
|
||||||
err: errors.New("Error getting releases"), //nolint:goerr113
|
err: errors.New("Error getting releases"),
|
||||||
expected: checker.CheckResult{
|
expected: checker.CheckResult{
|
||||||
Score: -1,
|
Score: -1,
|
||||||
Error: errors.New("Error getting releases"), //nolint:goerr113
|
Error: errors.New("Error getting releases"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ func createTestRepo(t *testing.T) (path string) {
|
|||||||
|
|
||||||
// Create a new file
|
// Create a new file
|
||||||
filePath := filepath.Join(dir, "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 {
|
if err != nil {
|
||||||
t.Fatalf("Failed to write a file: %v", err)
|
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.
|
// Use the same test repo for all test cases.
|
||||||
repoPath := createTestRepo(t)
|
repoPath := createTestRepo(t)
|
||||||
filePath := filepath.Join(repoPath, "test.txt")
|
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 {
|
if err != nil {
|
||||||
t.Fatalf("WriteFile() failed: %v", err)
|
t.Fatalf("WriteFile() failed: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ func TestCopyBoolPtr(t *testing.T) {
|
|||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
copyBoolPtr(tt.src, tt.dest)
|
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)
|
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.Run(tt.name, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
copyInt32Ptr(tt.src, tt.dest)
|
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)
|
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.Run(tt.name, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
copyStringPtr(tt.src, tt.dest)
|
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)
|
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.Run(tt.name, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
copyTimePtr(tt.src, tt.dest)
|
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)
|
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.Run(tt.name, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
copyRepoAssociationPtr(tt.src, tt.dest)
|
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)
|
t.Errorf("copyRepoAssociationPtr() got = %v, want %v", *tt.dest, tt.want)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -85,15 +85,9 @@ func testServer(t *testing.T) {
|
|||||||
serverURL := strings.TrimPrefix(server.URL, "http://")
|
serverURL := strings.TrimPrefix(server.URL, "http://")
|
||||||
t.Setenv("GITHUB_AUTH_SERVER", serverURL)
|
t.Setenv("GITHUB_AUTH_SERVER", serverURL)
|
||||||
t.Cleanup(server.Close)
|
t.Cleanup(server.Close)
|
||||||
myRPCService := &MyRPCService{}
|
|
||||||
rpc.Register(myRPCService) //nolint:errcheck
|
|
||||||
rpc.HandleHTTP()
|
rpc.HandleHTTP()
|
||||||
got := MakeTokenAccessor()
|
got := MakeTokenAccessor()
|
||||||
if got == nil {
|
if got == nil {
|
||||||
t.Errorf("MakeTokenAccessor() = nil, want not nil")
|
t.Errorf("MakeTokenAccessor() = nil, want not nil")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type MyRPCService struct {
|
|
||||||
// Define your RPC service methods here
|
|
||||||
}
|
|
||||||
|
@ -33,7 +33,6 @@ type stubTripper struct {
|
|||||||
func (s stubTripper) RoundTrip(_ *http.Request) (*http.Response, error) {
|
func (s stubTripper) RoundTrip(_ *http.Request) (*http.Response, error) {
|
||||||
f, err := os.Open(s.responsePath)
|
f, err := os.Open(s.responsePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
//nolint:wrapcheck
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &http.Response{
|
return &http.Response{
|
||||||
|
@ -110,11 +110,12 @@ func TestGetBranches(t *testing.T) {
|
|||||||
|
|
||||||
handler.once.Do(func() {})
|
handler.once.Do(func() {})
|
||||||
|
|
||||||
//nolint:errcheck
|
br, err := handler.getBranch(tt.branchName)
|
||||||
br, _ := handler.getBranch(tt.branchName)
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected err: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
//nolint:unconvert
|
if *br.Name != tt.expectedBranchName {
|
||||||
if string(*br.Name) != tt.expectedBranchName {
|
|
||||||
t.Errorf("Branch Name (%s) didn't match expected value (%s)", *br.Name, tt.expectedBranchName)
|
t.Errorf("Branch Name (%s) didn't match expected value (%s)", *br.Name, tt.expectedBranchName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,6 @@ func (s suffixStubTripper) RoundTrip(r *http.Request) (*http.Response, error) {
|
|||||||
suffix := pathParts[len(pathParts)-1]
|
suffix := pathParts[len(pathParts)-1]
|
||||||
f, err := os.Open(s.responsePaths[suffix])
|
f, err := os.Open(s.responsePaths[suffix])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
//nolint:wrapcheck
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &http.Response{
|
return &http.Response{
|
||||||
|
@ -32,7 +32,6 @@ type stubTripper struct {
|
|||||||
func (s stubTripper) RoundTrip(_ *http.Request) (*http.Response, error) {
|
func (s stubTripper) RoundTrip(_ *http.Request) (*http.Response, error) {
|
||||||
f, err := os.Open(s.responsePath)
|
f, err := os.Open(s.responsePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
//nolint:wrapcheck
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &http.Response{
|
return &http.Response{
|
||||||
|
@ -390,7 +390,6 @@ func Test_fetchGitRepositoryFromNuget(t *testing.T) {
|
|||||||
resultPackageRegistrationPages: []resultPackagePage{},
|
resultPackageRegistrationPages: []resultPackagePage{},
|
||||||
resultPackageSpec: "",
|
resultPackageSpec: "",
|
||||||
},
|
},
|
||||||
//nolint:lll
|
|
||||||
want: "internal error: failed to parse nuget package registration index json: invalid character 'e' in literal true (expecting 'r')",
|
want: "internal error: failed to parse nuget package registration index json: invalid character 'e' in literal true (expecting 'r')",
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
@ -443,7 +442,6 @@ func Test_fetchGitRepositoryFromNuget(t *testing.T) {
|
|||||||
},
|
},
|
||||||
resultPackageSpec: "",
|
resultPackageSpec: "",
|
||||||
},
|
},
|
||||||
//nolint:lll
|
|
||||||
want: "internal error: failed to parse nuget package registration page: invalid character 'e' in literal true (expecting 'r')",
|
want: "internal error: failed to parse nuget package registration page: invalid character 'e' in literal true (expecting 'r')",
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
@ -514,7 +512,6 @@ func Test_fetchGitRepositoryFromNuget(t *testing.T) {
|
|||||||
resultPackageSpec: "",
|
resultPackageSpec: "",
|
||||||
version: "",
|
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",
|
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,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
@ -580,7 +577,6 @@ func nugetIndexOrPageTestResults(url string, test *nugetTest) (*http.Response, e
|
|||||||
urlResponseIndex := slices.IndexFunc(test.args.resultPackageRegistrationPages,
|
urlResponseIndex := slices.IndexFunc(test.args.resultPackageRegistrationPages,
|
||||||
func(page resultPackagePage) bool { return page.url == url })
|
func(page resultPackagePage) bool { return page.url == url })
|
||||||
if urlResponseIndex == -1 {
|
if urlResponseIndex == -1 {
|
||||||
//nolint:goerr113
|
|
||||||
return nil, errors.New("error")
|
return nil, errors.New("error")
|
||||||
}
|
}
|
||||||
page := test.args.resultPackageRegistrationPages[urlResponseIndex]
|
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)
|
t.Errorf("fetchGitRepositoryFromNuget() version = %v, expected version = %v", url, test.args.version)
|
||||||
}
|
}
|
||||||
//nolint:goerr113
|
|
||||||
return nil, errors.New("error")
|
return nil, errors.New("error")
|
||||||
}
|
}
|
||||||
|
|
||||||
func testResult(wantErr bool, responseFileName string) (*http.Response, error) {
|
func testResult(wantErr bool, responseFileName string) (*http.Response, error) {
|
||||||
if wantErr && responseFileName == "" {
|
if wantErr && responseFileName == "" {
|
||||||
//nolint:goerr113
|
|
||||||
return nil, errors.New("error")
|
return nil, errors.New("error")
|
||||||
}
|
}
|
||||||
if wantErr && responseFileName == "text" {
|
if wantErr && responseFileName == "text" {
|
||||||
|
@ -21,7 +21,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
//nolint:lll // results are long
|
|
||||||
func Test_compare(t *testing.T) {
|
func Test_compare(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
//nolint:govet // struct alignment
|
//nolint:govet // struct alignment
|
||||||
@ -97,7 +96,6 @@ func (a alwaysErrorReader) Read(b []byte) (n int, err error) {
|
|||||||
return 0, io.ErrClosedPipe
|
return 0, io.ErrClosedPipe
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint:lll // results are long
|
|
||||||
func Test_compare_reader_err(t *testing.T) {
|
func Test_compare_reader_err(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
//nolint:govet // struct alignment
|
//nolint:govet // struct alignment
|
||||||
|
@ -31,7 +31,6 @@ type resultCounter struct {
|
|||||||
lines int
|
lines int
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint:wrapcheck
|
|
||||||
func (rc *resultCounter) Write(p []byte) (n int, err error) {
|
func (rc *resultCounter) Write(p []byte) (n int, err error) {
|
||||||
rc.lines += bytes.Count(p, []byte("\n"))
|
rc.lines += bytes.Count(p, []byte("\n"))
|
||||||
return rc.b.Write(p)
|
return rc.b.Write(p)
|
||||||
|
@ -141,7 +141,6 @@ func Test_fetchGitRepositoryFromNPM(t *testing.T) {
|
|||||||
p.EXPECT().Get(gomock.Any(), tt.args.packageName).
|
p.EXPECT().Get(gomock.Any(), tt.args.packageName).
|
||||||
DoAndReturn(func(url, packageName string) (*http.Response, error) {
|
DoAndReturn(func(url, packageName string) (*http.Response, error) {
|
||||||
if tt.wantErr && tt.args.result == "" {
|
if tt.wantErr && tt.args.result == "" {
|
||||||
//nolint:goerr113
|
|
||||||
return nil, errors.New("error")
|
return nil, errors.New("error")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -316,7 +315,6 @@ func Test_fetchGitRepositoryFromPYPI(t *testing.T) {
|
|||||||
name: "fetchGitRepositoryFromPYPI",
|
name: "fetchGitRepositoryFromPYPI",
|
||||||
args: args{
|
args: args{
|
||||||
packageName: "some-package",
|
packageName: "some-package",
|
||||||
//nolint:lll
|
|
||||||
result: `
|
result: `
|
||||||
{
|
{
|
||||||
"info": {
|
"info": {
|
||||||
@ -450,7 +448,6 @@ func Test_fetchGitRepositoryFromPYPI(t *testing.T) {
|
|||||||
p.EXPECT().Get(gomock.Any(), tt.args.packageName).
|
p.EXPECT().Get(gomock.Any(), tt.args.packageName).
|
||||||
DoAndReturn(func(url, packageName string) (*http.Response, error) {
|
DoAndReturn(func(url, packageName string) (*http.Response, error) {
|
||||||
if tt.wantErr && tt.args.result == "" {
|
if tt.wantErr && tt.args.result == "" {
|
||||||
//nolint:goerr113
|
|
||||||
return nil, errors.New("error")
|
return nil, errors.New("error")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -487,7 +484,6 @@ func Test_fetchGitRepositoryFromRubyGems(t *testing.T) {
|
|||||||
name: "fetchGitRepositoryFromPYPI",
|
name: "fetchGitRepositoryFromPYPI",
|
||||||
args: args{
|
args: args{
|
||||||
packageName: "npm-package",
|
packageName: "npm-package",
|
||||||
//nolint:lll
|
|
||||||
result: `
|
result: `
|
||||||
{
|
{
|
||||||
"name": "color",
|
"name": "color",
|
||||||
@ -609,7 +605,6 @@ func Test_fetchGitRepositoryFromRubyGems(t *testing.T) {
|
|||||||
name: "empty project url",
|
name: "empty project url",
|
||||||
args: args{
|
args: args{
|
||||||
packageName: "npm-package",
|
packageName: "npm-package",
|
||||||
//nolint:lll
|
|
||||||
result: `
|
result: `
|
||||||
{
|
{
|
||||||
"name": "color",
|
"name": "color",
|
||||||
@ -717,7 +712,6 @@ func Test_fetchGitRepositoryFromRubyGems(t *testing.T) {
|
|||||||
p.EXPECT().Get(gomock.Any(), tt.args.packageName).
|
p.EXPECT().Get(gomock.Any(), tt.args.packageName).
|
||||||
DoAndReturn(func(url, packageName string) (*http.Response, error) {
|
DoAndReturn(func(url, packageName string) (*http.Response, error) {
|
||||||
if tt.wantErr && tt.args.result == "" {
|
if tt.wantErr && tt.args.result == "" {
|
||||||
//nolint:goerr113
|
|
||||||
return nil, errors.New("error")
|
return nil, errors.New("error")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -778,7 +772,6 @@ func Test_fetchGitRepositoryFromNuget(t *testing.T) {
|
|||||||
n.EXPECT().GitRepositoryByPackageName(tt.args.packageName).
|
n.EXPECT().GitRepositoryByPackageName(tt.args.packageName).
|
||||||
DoAndReturn(func(packageName string) (string, error) {
|
DoAndReturn(func(packageName string) (string, error) {
|
||||||
if tt.wantErr && tt.args.result == "" {
|
if tt.wantErr && tt.args.result == "" {
|
||||||
//nolint:goerr113
|
|
||||||
return "", errors.New("error")
|
return "", errors.New("error")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +70,6 @@ func getByteValueFromFile(filename string) ([]byte, error) {
|
|||||||
if filename == "" {
|
if filename == "" {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
//nolint:wrapcheck
|
|
||||||
return os.ReadFile(filename)
|
return os.ReadFile(filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,6 @@ func (topic *mockSucceedTopic) Send(ctx context.Context, msg *pubsub.Message) er
|
|||||||
type mockFailTopic struct{}
|
type mockFailTopic struct{}
|
||||||
|
|
||||||
func (topic *mockFailTopic) Send(ctx context.Context, msg *pubsub.Message) error {
|
func (topic *mockFailTopic) Send(ctx context.Context, msg *pubsub.Message) error {
|
||||||
//nolint:goerr113
|
|
||||||
return fmt.Errorf("mockFailTopic failed to send")
|
return fmt.Errorf("mockFailTopic failed to send")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,8 +65,7 @@ func TestSubscriber(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "ReceiveFails",
|
name: "ReceiveFails",
|
||||||
hasErrOnReceive: true,
|
hasErrOnReceive: true,
|
||||||
//nolint:goerr113
|
errOnReceive: errors.New("mock Receive failure"),
|
||||||
errOnReceive: errors.New("mock Receive failure"),
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "ShutdownFails",
|
name: "ShutdownFails",
|
||||||
@ -78,8 +77,7 @@ func TestSubscriber(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
hasErrOnShutdown: true,
|
hasErrOnShutdown: true,
|
||||||
//nolint:goerr113
|
errOnShutdown: errors.New("mock Shutdown close"),
|
||||||
errOnShutdown: errors.New("mock Shutdown close"),
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, testcase := range testcases {
|
for _, testcase := range testcases {
|
||||||
|
@ -247,6 +247,6 @@ func getScorecardResult(repoURL string) (pkg.ScorecardResult, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return pkg.ScorecardResult{}, fmt.Errorf("couldn't set up clients: %w", err)
|
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)
|
return pkg.RunScorecard(ctx, repo, clients.HeadSHA, 0, enabledChecks, repoClient, ossFuzzRepoClient, ciiClient, vulnsClient)
|
||||||
}
|
}
|
||||||
|
@ -32,10 +32,10 @@ func TestCreateInternal(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
name: "non-nil error and non-empty message",
|
name: "non-nil error and non-empty message",
|
||||||
args: args{
|
args: args{
|
||||||
e: errors.New("test error"), //nolint:goerr113
|
e: errors.New("test error"),
|
||||||
msg: "test message",
|
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) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
@ -92,7 +92,7 @@ func TestGetName(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "unknown error",
|
name: "unknown error",
|
||||||
args: args{
|
args: args{
|
||||||
err: errors.New("unknown error"), //nolint:goerr113
|
err: errors.New("unknown error"),
|
||||||
},
|
},
|
||||||
want: "ErrUnknown",
|
want: "ErrUnknown",
|
||||||
},
|
},
|
||||||
|
@ -175,7 +175,7 @@ func TestOptions_AddFlags_Format(t *testing.T) {
|
|||||||
cmd := &cobra.Command{}
|
cmd := &cobra.Command{}
|
||||||
tt.opts.AddFlags(cmd)
|
tt.opts.AddFlags(cmd)
|
||||||
if !cmp.Equal(cmd.Flag(FlagFormat).Value.String(), strings.Join(tt.expected, ", ")) {
|
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())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -583,7 +583,7 @@ func TestJsonScorecardRawResult_AddOssfBestPracticesRawResults(t *testing.T) {
|
|||||||
t.Errorf("addOssfBestPracticesRawResults() error = %v, wantError %v", err, test.wantError)
|
t.Errorf("addOssfBestPracticesRawResults() error = %v, wantError %v", err, test.wantError)
|
||||||
}
|
}
|
||||||
if r.Results.OssfBestPractices.Badge != test.input.Badge.String() {
|
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)
|
t.Errorf("addCodeReviewRawResults() error = %v, wantError %v", err, test.wantError)
|
||||||
}
|
}
|
||||||
if len(r.Results.DefaultBranchChangesets) != len(test.input.DefaultBranchChangesets) {
|
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) {
|
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) {
|
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 {
|
for i, file := range r.Results.Binaries {
|
||||||
if file.Path != expected[i].Path {
|
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) {
|
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 {
|
for i, policy := range r.Results.SecurityPolicies {
|
||||||
if policy.Path != expected[i].Path {
|
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 {
|
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) {
|
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 {
|
for j, hit := range policy.Hits {
|
||||||
if hit.Type != expected[i].Hits[j].Type {
|
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) {
|
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 {
|
for i, vuln := range r.Results.DatabaseVulnerabilities {
|
||||||
if vuln.ID != expected[i].ID {
|
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) {
|
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 {
|
for i, fuzzer := range r.Results.Fuzzers {
|
||||||
if fuzzer.Name != expectedFuzzers[i].Name {
|
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 {
|
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 {
|
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) {
|
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 {
|
for j, file := range fuzzer.Files {
|
||||||
if file.Path != expectedFuzzers[i].Files[j].Path {
|
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"},
|
{ID: "CVE-2021-5678"},
|
||||||
}
|
}
|
||||||
if cmp.Diff(r.Results.DatabaseVulnerabilities, expectedVulnerabilities) != "" {
|
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
|
// test addBinaryArtifactRawResults
|
||||||
@ -1173,7 +1173,7 @@ func TestJsonScorecardRawResult(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
if cmp.Diff(expectedSecurityPolicies, r.Results.SecurityPolicies) != "" {
|
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
|
// test addFuzzingRawResults
|
||||||
@ -1202,7 +1202,7 @@ func TestJsonScorecardRawResult(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
if cmp.Diff(expectedFuzzers, r.Results.Fuzzers, cmpopts.IgnoreFields(jsonTool{}, "URL", "Desc")) != "" {
|
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
|
// test addBranchProtectionRawResults
|
||||||
@ -1224,7 +1224,6 @@ func intPtr(i int32) *int32 {
|
|||||||
return &i
|
return &i
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint:lll
|
|
||||||
func TestScorecardResult_AsRawJSON(t *testing.T) {
|
func TestScorecardResult_AsRawJSON(t *testing.T) {
|
||||||
type fields struct {
|
type fields struct {
|
||||||
Repo RepoInfo
|
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}}}
|
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 {
|
for _, tt := range tests {
|
||||||
|
@ -495,7 +495,7 @@ func TestJSONOutput(t *testing.T) {
|
|||||||
|
|
||||||
func TestExperimentalFromJSON2_time(t *testing.T) {
|
func TestExperimentalFromJSON2_time(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
//nolint:lll,govet // result strings are long
|
//nolint:govet
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
result string
|
result string
|
||||||
|
@ -52,7 +52,7 @@ func countDetails(c []checker.CheckDetail) (debug, info, warn int) {
|
|||||||
return debug, info, warn
|
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 {
|
func compareScorecardResults(a, b ScorecardResult) bool {
|
||||||
if a.Repo != b.Repo {
|
if a.Repo != b.Repo {
|
||||||
fmt.Fprintf(GinkgoWriter, "Unequal repo details in results: %v vs %v\n", a.Repo, b.Repo)
|
fmt.Fprintf(GinkgoWriter, "Unequal repo details in results: %v vs %v\n", a.Repo, b.Repo)
|
||||||
|
@ -88,11 +88,9 @@ func Test_Run(t *testing.T) {
|
|||||||
Probe: "hasOSVVulnerabilities",
|
Probe: "hasOSVVulnerabilities",
|
||||||
Message: "Project is vulnerable to: foo",
|
Message: "Project is vulnerable to: foo",
|
||||||
Remediation: &probe.Remediation{
|
Remediation: &probe.Remediation{
|
||||||
//nolint:lll
|
|
||||||
Text: `Fix the foo by following information from https://osv.dev/foo.
|
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 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.`,
|
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).
|
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 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).`,
|
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).`,
|
||||||
|
@ -66,7 +66,6 @@ func (s stubDigester) Digest(name string) (string, error) {
|
|||||||
}
|
}
|
||||||
hash, ok := m[name]
|
hash, ok := m[name]
|
||||||
if !ok {
|
if !ok {
|
||||||
//nolint:goerr113
|
|
||||||
return "", fmt.Errorf("no hash for image: %q", name)
|
return "", fmt.Errorf("no hash for image: %q", name)
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("sha256:%s", hash), nil
|
return fmt.Sprintf("sha256:%s", hash), nil
|
||||||
@ -75,7 +74,7 @@ func (s stubDigester) Digest(name string) (string, error) {
|
|||||||
func TestCreateDockerfilePinningRemediation(t *testing.T) {
|
func TestCreateDockerfilePinningRemediation(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
//nolint:govet,lll
|
//nolint:govet
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
dep checker.Dependency
|
dep checker.Dependency
|
||||||
|
Loading…
Reference in New Issue
Block a user