Skip to content

Commit

Permalink
Merge branch 'main' into update_contributor_ladder
Browse files Browse the repository at this point in the history
  • Loading branch information
justaugustus committed Feb 27, 2024
2 parents 4f26ffb + 299948e commit a1d60aa
Show file tree
Hide file tree
Showing 13 changed files with 1,371 additions and 1,077 deletions.
89 changes: 32 additions & 57 deletions checks/code_review_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,52 +24,31 @@ import (
"github.com/ossf/scorecard/v4/checker"
"github.com/ossf/scorecard/v4/clients"
mockrepo "github.com/ossf/scorecard/v4/clients/mockclients"
sce "github.com/ossf/scorecard/v4/errors"
scut "github.com/ossf/scorecard/v4/utests"
)

var errNew = errors.New("error")

// TestCodeReview tests the code review checker.
func TestCodereview(t *testing.T) {
t.Parallel()
// fieldalignment lint issue. Ignoring it as it is not important for this test.
//nolint:gci
//nolint:gofmt
//nolint:gofumpt
//nolint:goimports
tests := []struct {
err error
name string
commiterr error
commitErr error
commits []clients.Commit
expected checker.CheckResult
expected scut.TestReturn
}{
{
name: "no commits",
expected: checker.CheckResult{
Score: -1,
},
},
{
name: "no commits with error",
commiterr: errNew,
expected: checker.CheckResult{
Score: -1,
},
},
{
name: "no PR's with error",
err: errNew,
expected: checker.CheckResult{
expected: scut.TestReturn{
Score: -1,
},
},
{
name: "no PR's with error as well as commits",
err: errNew,
commiterr: errNew,
expected: checker.CheckResult{
name: "no commits due to error",
commitErr: errors.New("error fetching commits"),
expected: scut.TestReturn{
Score: -1,
Error: sce.ErrScorecardInternal,
},
},
{
Expand All @@ -92,7 +71,7 @@ func TestCodereview(t *testing.T) {
},
},
},
expected: checker.CheckResult{
expected: scut.TestReturn{
Score: 10,
},
},
Expand All @@ -115,7 +94,7 @@ func TestCodereview(t *testing.T) {
},
},
},
expected: checker.CheckResult{
expected: scut.TestReturn{
Score: 10,
},
},
Expand All @@ -138,7 +117,7 @@ func TestCodereview(t *testing.T) {
},
},
},
expected: checker.CheckResult{
expected: scut.TestReturn{
Score: 10,
},
},
Expand All @@ -160,8 +139,9 @@ func TestCodereview(t *testing.T) {
},
},
},
expected: checker.CheckResult{
Score: 0,
expected: scut.TestReturn{
Score: 0,
NumberOfDebug: 1, // one per un-reviewed change
},
},
{
Expand Down Expand Up @@ -190,8 +170,9 @@ func TestCodereview(t *testing.T) {
},
},
},
expected: checker.CheckResult{
Score: 5,
expected: scut.TestReturn{
Score: 5,
NumberOfDebug: 1, // one per un-reviewed change
},
},
{
Expand All @@ -215,8 +196,9 @@ func TestCodereview(t *testing.T) {
},
},
},
expected: checker.CheckResult{
Score: 5,
expected: scut.TestReturn{
Score: 5,
NumberOfDebug: 1, // one per un-reviewed change
},
},
{
Expand All @@ -230,7 +212,7 @@ func TestCodereview(t *testing.T) {
Message: "Title\nReviewed By: alice\nDifferential Revision: PHAB234",
},
},
expected: checker.CheckResult{
expected: scut.TestReturn{
Score: 10,
},
},
Expand All @@ -245,8 +227,9 @@ func TestCodereview(t *testing.T) {
Message: "Title\nReviewed By: alice",
},
},
expected: checker.CheckResult{
Score: 0,
expected: scut.TestReturn{
Score: 0,
NumberOfDebug: 1, // one per un-reviewed change
},
},
{
Expand All @@ -260,7 +243,7 @@ func TestCodereview(t *testing.T) {
Message: "Title\nDifferential Revision: PHAB234",
},
},
expected: checker.CheckResult{
expected: scut.TestReturn{
Score: checker.MaxResultScore,
},
},
Expand All @@ -275,7 +258,7 @@ func TestCodereview(t *testing.T) {
Message: "Title\nPiperOrigin-RevId: 444529962",
},
},
expected: checker.CheckResult{
expected: scut.TestReturn{
Score: 10,
},
},
Expand All @@ -287,26 +270,18 @@ func TestCodereview(t *testing.T) {
t.Parallel()
ctrl := gomock.NewController(t)
mockRepo := mockrepo.NewMockRepoClient(ctrl)
mockRepo.EXPECT().ListCommits().Return(tt.commits, tt.err).AnyTimes()
mockRepo.EXPECT().ListCommits().Return(tt.commits, tt.commitErr).AnyTimes()

var dl scut.TestDetailLogger
req := checker.CheckRequest{
RepoClient: mockRepo,
Dlogger: &dl,
}
req.Dlogger = &scut.TestDetailLogger{}
res := CodeReview(&req)

if tt.err != nil {
if res.Error == nil {
t.Errorf("Expected error %v, got nil", tt.err)
}
// return as we don't need to check the rest of the fields.
return
}

if res.Score != tt.expected.Score {
t.Errorf("Expected score %d, got %d for %v", tt.expected.Score, res.Score, tt.name)
if tt.commitErr != nil && res.Error == nil {
t.Fatalf("Expected error %v, got nil", tt.commitErr)
}
ctrl.Finish()
scut.ValidateTestReturn(t, tt.name, &tt.expected, &res, &dl)
})
}
}
Loading

0 comments on commit a1d60aa

Please sign in to comment.