Skip to content

Commit

Permalink
debug failing integration test
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Korczynski <[email protected]>
  • Loading branch information
AdamKorcz committed Dec 5, 2023
1 parent f50e991 commit 300ab09
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
16 changes: 13 additions & 3 deletions checks/evaluation/ci_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,26 @@ func CITests(name string,
return checker.CreateRuntimeErrorResult(name, e)
}

Check warning on line 38 in checks/evaluation/ci_tests.go

View check run for this annotation

Codecov / codecov/patch

checks/evaluation/ci_tests.go#L36-L38

Added lines #L36 - L38 were not covered by tests

// check whether there are any negative findings
// Debug PRs that were merged without CI tests
for i := range findings {
f := &findings[i]
if f.Outcome == finding.OutcomeNegative {
dl.Debug(&checker.LogMessage{
Text: f.Message,
})
}
}

// check that the project has pull requests
if noPullRequestsFound(findings) {
return checker.CreateInconclusiveResult(CheckCITests, "no pull request found")
}

totalMerged := findings[0].Values["totalMerged"]
totalTested := findings[0].Values["totalTested"]

if totalMerged < totalTested || len(findings) != totalTested {
e := sce.WithMessage(sce.ErrScorecardInternal, "invalid probe results")
if totalMerged < totalTested || len(findings) < totalTested {
e := sce.WithMessage(sce.ErrScorecardInternal, "invalid finding values")
return checker.CreateRuntimeErrorResult(name, e)
}

Expand Down
30 changes: 30 additions & 0 deletions checks/evaluation/ci_tests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,36 @@ func TestCITests(t *testing.T) {
Score: -1,
},
},
{
name: "Tests debugging",
findings: []finding.Finding{
{
Outcome: finding.OutcomeNegative,
Probe: "testsRunInCI",
Message: "merged PR 1 without CI test at HEAD: 1",
Values: map[string]int{"totalMerged": 3, "totalTested": 0},
Location: &finding.Location{Type: 4},
},
{
Outcome: finding.OutcomeNegative,
Probe: "testsRunInCI",
Message: "merged PR 1 without CI test at HEAD: 1",
Values: map[string]int{"totalMerged": 3, "totalTested": 0},
Location: &finding.Location{Type: 4},
},
{
Outcome: finding.OutcomeNegative,
Probe: "testsRunInCI",
Message: "merged PR 1 without CI test at HEAD: 1",
Values: map[string]int{"totalMerged": 3, "totalTested": 0},
Location: &finding.Location{Type: 4},
},
},
result: scut.TestReturn{
NumberOfDebug: 3,
Score: 0,
},
},
}
for _, tt := range tests {
tt := tt
Expand Down
10 changes: 10 additions & 0 deletions probes/testsRunInCI/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ func Run(raw *checker.RawResults) ([]finding.Finding, string, error) {
findings = append(findings, *f)
totalTested++
}

if !prSuccessStatus && !prCheckSuccessful {
f, err := finding.NewWith(fs, Probe,
fmt.Sprintf("merged PR %d without CI test at HEAD: %s", r.PullRequestNumber, r.HeadSHA),
nil, finding.OutcomeNegative)
if err != nil {
return nil, Probe, fmt.Errorf("create finding: %w", err)
}
findings = append(findings, *f)

Check warning on line 90 in probes/testsRunInCI/impl.go

View check run for this annotation

Codecov / codecov/patch

probes/testsRunInCI/impl.go#L84-L90

Added lines #L84 - L90 were not covered by tests
}
}

for i := range findings {
Expand Down

0 comments on commit 300ab09

Please sign in to comment.