Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pkg/testcoverage/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ func GenerateCoverageStats(cfg Config) ([]coverage.Stats, error) {

func Analyze(cfg Config, current, base []coverage.Stats) AnalyzeResult {
thr := cfg.Threshold
overrideRules := compileOverridePathRules(cfg)
overrideRules, hasOverrides := compileOverridePathRules(cfg)

return AnalyzeResult{
Threshold: thr,
HasOverrides: hasOverrides,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compileOverridePathRules does not need to return additional value, instead we can use something like this:

HasOverrides:        len(overrideRules) > 0,

FilesBelowThreshold: checkCoverageStatsBelowThreshold(current, thr.File, overrideRules),
PackagesBelowThreshold: checkCoverageStatsBelowThreshold(
makePackageStats(current), thr.Package, overrideRules,
Expand Down
4 changes: 2 additions & 2 deletions pkg/testcoverage/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func TestCheck(t *testing.T) {
pass := Check(buf, cfg)
assert.True(t, pass)
assertGithubActionErrorsCount(t, buf.String(), 0)
assertHumanReport(t, buf.String(), 1, 0)
assertHumanReport(t, buf.String(), 2, 0)
assert.GreaterOrEqual(t, strings.Count(buf.String(), prefix), 0)
})

Expand All @@ -134,7 +134,7 @@ func TestCheck(t *testing.T) {
pass := Check(buf, cfg)
assert.False(t, pass)
assertGithubActionErrorsCount(t, buf.String(), 0)
assertHumanReport(t, buf.String(), 0, 1)
assertHumanReport(t, buf.String(), 0, 2)
assert.GreaterOrEqual(t, strings.Count(buf.String(), prefix), 0)
})

Expand Down
4 changes: 2 additions & 2 deletions pkg/testcoverage/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ func reportCoverage(w io.Writer, result AnalyzeResult) {

thr := result.Threshold

if thr.File > 0 { // File threshold report
if thr.File > 0 || result.HasOverrides { // File threshold report
fmt.Fprintf(tabber, "File coverage threshold (%d%%) satisfied:\t", thr.File)
fmt.Fprint(tabber, statusStr(len(result.FilesBelowThreshold) == 0))
reportIssuesForHuman(tabber, result.FilesBelowThreshold)
fmt.Fprint(tabber, "\n")
}

if thr.Package > 0 { // Package threshold report
if thr.Package > 0 || result.HasOverrides { // Package threshold report
fmt.Fprintf(tabber, "Package coverage threshold (%d%%) satisfied:\t", thr.Package)
fmt.Fprint(tabber, statusStr(len(result.PackagesBelowThreshold) == 0))
reportIssuesForHuman(tabber, result.PackagesBelowThreshold)
Expand Down
1 change: 1 addition & 0 deletions pkg/testcoverage/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type AnalyzeResult struct {
TotalStats coverage.Stats
HasBaseBreakdown bool
Diff []FileCoverageDiff
HasOverrides bool
}

func (r *AnalyzeResult) Pass() bool {
Expand Down
6 changes: 3 additions & 3 deletions pkg/testcoverage/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ func matches(regexps []regRule, str string) (int, bool) {
return 0, false
}

func compileOverridePathRules(cfg Config) []regRule {
func compileOverridePathRules(cfg Config) ([]regRule, bool) {
if len(cfg.Override) == 0 {
return nil
return nil, false
}

compiled := make([]regRule, len(cfg.Override))
Expand All @@ -33,5 +33,5 @@ func compileOverridePathRules(cfg Config) []regRule {
}
}

return compiled
return compiled, true
}
Loading