Skip to content

Commit

Permalink
fix tests like in ossf#3409
Browse files Browse the repository at this point in the history
Signed-off-by: AdamKorcz <[email protected]>
  • Loading branch information
AdamKorcz committed Sep 28, 2023
1 parent b6aa192 commit b44d2d0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 49 deletions.
2 changes: 1 addition & 1 deletion checks/contributors.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ func Contributors(c *checker.CheckRequest) checker.CheckResult {
}

// Return the score evaluation.
return evaluation.Contributors(CheckContributors, findings)
return evaluation.Contributors(CheckContributors, findings, c.Dlogger)
}
2 changes: 2 additions & 0 deletions checks/evaluation/contributors.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const (

func Contributors(name string,
findings []finding.Finding,
dl checker.DetailLogger,
) checker.CheckResult {
expectedProbes := []string{
contributorsFromOrgOrCompany.Probe,
Expand All @@ -46,6 +47,7 @@ func Contributors(name string,
// are added for other contributors metrics. Right now, it the
// scoring is designed for a single probe that returns true
// or false.
// checker.LogFindings(nonNegativeFindings(findings), dl) TODO: Uncomment this line
return checker.CreateMaxScoreResult(name, reason)
}

Expand Down
81 changes: 33 additions & 48 deletions checks/evaluation/contributors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,79 +16,64 @@ package evaluation
import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"

"github.com/ossf/scorecard/v4/checker"
"github.com/ossf/scorecard/v4/finding"
scut "github.com/ossf/scorecard/v4/utests"
)

func TestContributors(t *testing.T) {
t.Parallel()
type args struct { //nolint
tests := []struct {
name string
findings []finding.Finding
}
tests := []struct {
name string
args args
want checker.CheckResult
result scut.TestReturn
}{
{
name: "Only has two positive outcomes",
args: args{
name: "Contributors",
findings: []finding.Finding{
{
Probe: "contributorsFromOrgOrCompany",
Outcome: finding.OutcomePositive,
},
{
Probe: "contributorsFromOrgOrCompany",
Outcome: finding.OutcomePositive,
},
findings: []finding.Finding{
{
Probe: "contributorsFromOrgOrCompany",
Outcome: finding.OutcomePositive,
},
{
Probe: "contributorsFromOrgOrCompany",
Outcome: finding.OutcomePositive,
},
},
want: checker.CheckResult{
Score: 0,
Version: 2,
Name: "contributorsFromOrgOrCompany",
Reason: "project has 2 contributing companies or organizations",
result: scut.TestReturn{
Score: checker.MinResultScore,
NumberOfInfo: 0,
},
}, {
name: "Has two positive outcomes",
args: args{
name: "Contributors",
findings: []finding.Finding{
{
Probe: "contributorsFromOrgOrCompany",
Outcome: finding.OutcomePositive,
},
{
Probe: "contributorsFromOrgOrCompany",
Outcome: finding.OutcomePositive,
},
{
Probe: "contributorsFromOrgOrCompany",
Outcome: finding.OutcomePositive,
},
findings: []finding.Finding{
{
Probe: "contributorsFromOrgOrCompany",
Outcome: finding.OutcomePositive,
},
{
Probe: "contributorsFromOrgOrCompany",
Outcome: finding.OutcomePositive,
},
{
Probe: "contributorsFromOrgOrCompany",
Outcome: finding.OutcomePositive,
},
},
want: checker.CheckResult{
Score: 10,
Version: 2,
Name: "contributorsFromOrgOrCompany",
Reason: "project has 3 contributing companies or organizations",
result: scut.TestReturn{
Score: checker.MaxResultScore,
NumberOfInfo: 0,
},
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
result := Contributors("contributorsFromOrgOrCompany", tt.args.findings)
if !cmp.Equal(result, tt.want, cmpopts.IgnoreFields(checker.CheckResult{}, "Error")) { //nolint:govet
t.Errorf("expected %v, got %v", tt.want, cmp.Diff(tt.want, result, cmpopts.IgnoreFields(checker.CheckResult{}, "Error"))) //nolint:lll
dl := scut.TestDetailLogger{}
got := Contributors(tt.name, tt.findings, &dl)
if !scut.ValidateTestReturn(t, tt.name, &tt.result, &got, &dl) {
t.Fatalf(tt.name)
}
})
}
Expand Down

0 comments on commit b44d2d0

Please sign in to comment.