diff --git a/pkg/scorecard_test.go b/pkg/scorecard_test.go index bf4956a47f26..3d9642efe0fc 100644 --- a/pkg/scorecard_test.go +++ b/pkg/scorecard_test.go @@ -15,15 +15,19 @@ package pkg import ( "context" + "fmt" "testing" "github.com/golang/mock/gomock" "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" + "github.com/ossf/scorecard/v4/checker" "github.com/ossf/scorecard/v4/clients" "github.com/ossf/scorecard/v4/clients/localdir" mockrepo "github.com/ossf/scorecard/v4/clients/mockclients" + "github.com/ossf/scorecard/v4/finding" + "github.com/ossf/scorecard/v4/finding/probe" "github.com/ossf/scorecard/v4/log" ) @@ -204,15 +208,48 @@ func TestExperimentalRunProbes(t *testing.T) { name: "empty commits repos should return repo details but no checks", args: args{ uri: "github.com/ossf/scorecard", - commitSHA: "", + commitSHA: "1a17bb812fb2ac23e9d09e86e122f8b67563aed7", }, want: ScorecardResult{ Repo: RepoInfo{ - Name: "github.com/ossf/scorecard", + Name: "github.com/ossf/scorecard", + CommitSHA: "1a17bb812fb2ac23e9d09e86e122f8b67563aed7", + }, + RawResults: checker.RawResults{ + Metadata: checker.MetadataData{ + Metadata: map[string]string{ + "repository.defaultBranch": "main", + "repository.host": "github.com", + "repository.name": "ossf/scorecard", + "repository.sha1": "1a17bb812fb2ac23e9d09e86e122f8b67563aed7", + "repository.uri": "github.com/ossf/scorecard", + }, + }, }, Scorecard: ScorecardInfo{ CommitSHA: "unknown", }, + Findings: []finding.Finding{ + { + Probe: "fuzzedWithOSSFuzz", + Message: "no OSSFuzz integration found", + Remediation: &probe.Remediation{ + Text: fmt.Sprintf("%s%s%s\n%s%s", + "Follow the steps in ", + "https://github.com/google/oss-fuzz ", + "to integrate fuzzing for your project.", + "Over time, try to add fuzzing for more ", + "functionalities of your project."), + Markdown: fmt.Sprintf("%s%s%s\n%s%s", + "Follow the steps in [https://github.com", + "/google/oss-fuzz](https://github.com/google/oss-fuzz) ", + "to integrate fuzzing for your project.", + "Over time, try to add fuzzing for more ", + "functionalities of your project."), + Effort: 3, + }, + }, + }, }, wantErr: false, }, @@ -226,6 +263,7 @@ func TestExperimentalRunProbes(t *testing.T) { repo := mockrepo.NewMockRepo(ctrl) repo.EXPECT().URI().Return(tt.args.uri).AnyTimes() + repo.EXPECT().Host().Return("github.com").AnyTimes() mockRepoClient.EXPECT().InitRepo(repo, tt.args.commitSHA, 0).Return(nil) @@ -243,6 +281,7 @@ func TestExperimentalRunProbes(t *testing.T) { }, }, nil }) + mockRepoClient.EXPECT().GetDefaultBranchName().Return("main", nil).AnyTimes() defer ctrl.Finish() got, err := ExperimentalRunProbes(context.Background(), repo, tt.args.commitSHA, 0, nil, []string{"fuzzedWithOSSFuzz"}, mockRepoClient, nil, nil, nil) if (err != nil) != tt.wantErr {