Skip to content

Commit

Permalink
add test coverage
Browse files Browse the repository at this point in the history
Signed-off-by: AdamKorcz <[email protected]>
  • Loading branch information
AdamKorcz committed Nov 22, 2023
1 parent 7408b45 commit f9a3568
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions pkg/scorecard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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,
},
Expand All @@ -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)

Expand All @@ -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)

Check failure on line 286 in pkg/scorecard_test.go

View workflow job for this annotation

GitHub Actions / check-linter

line is 153 characters (lll)
if (err != nil) != tt.wantErr {
Expand Down

0 comments on commit f9a3568

Please sign in to comment.