ossf/scorecard

cleanup branch protection tests

spencerschrock opened this issue · 0 comments

From #3759 (comment):

can we just create a pre-defined var (for the probes that don't have other values, like the number of reviewers) so we can cut down on the lines and increase readability?

mainBranchValues := map[string]int{
	"main": 1,
},

And then the tests can just reference:

Probe:   "blocksForcePushOnBranches",
Outcome: finding.OutcomePositive,
Values: mainBranchValues

Or even just a helper func to make a finding based on name + outcome?

func testFinding(probe string, outcome finding.Outcome) finding.Outcome {
	return finding.Finding{
		Probe: probe,
		Outcome: outcome,
		Values: map[string]int{
			"main": 1,
		},
	}
}

And then we cut down on the toil/lines?

findings: []finding.Finding{
	testFinding("blocksDeleteOnBranches", finding.OutcomePositive),
	testFinding("blocksForcePushOnBranches", finding.OutcomePositive),
	// and so on