Skip to content

Commit fe7a844

Browse files
🌱 Improve workflow pinning remediation tests (ossf#3021)
- Add 3 tests for workflow pinning remediation [remediation/remediations_test.go] - Add 3 tests for workflow pinning remediation Signed-off-by: naveensrinivasan <[email protected]>
1 parent 028fa93 commit fe7a844

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

remediation/remediations_test.go

+52
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,55 @@ func TestCreateDockerfilePinningRemediation(t *testing.T) {
140140
})
141141
}
142142
}
143+
144+
func TestCreateWorkflowPinningRemediation(t *testing.T) {
145+
t.Parallel()
146+
147+
tests := []struct { //nolint:govet
148+
name string
149+
branch string
150+
repo string
151+
filepath string
152+
expected *rule.Remediation
153+
}{
154+
{
155+
name: "valid input",
156+
branch: "main",
157+
repo: "ossf/scorecard",
158+
filepath: ".github/workflows/scorecard.yml",
159+
expected: &rule.Remediation{
160+
Text: fmt.Sprintf(workflowText, "ossf/scorecard", "scorecard.yml", "main", "pin"),
161+
Markdown: fmt.Sprintf(workflowMarkdown, "ossf/scorecard", "scorecard.yml", "main", "pin"),
162+
},
163+
},
164+
{
165+
name: "empty branch",
166+
branch: "",
167+
repo: "ossf/scorecard",
168+
filepath: ".github/workflows/<workflow-file>",
169+
expected: nil,
170+
},
171+
{
172+
name: "empty repo",
173+
branch: "main",
174+
repo: "",
175+
filepath: ".github/workflows/<workflow-file>",
176+
expected: nil,
177+
},
178+
}
179+
180+
for _, tt := range tests {
181+
tt := tt
182+
t.Run(tt.name, func(t *testing.T) {
183+
t.Parallel()
184+
r := RemediationMetadata{
185+
Branch: tt.branch,
186+
Repo: tt.repo,
187+
}
188+
got := r.CreateWorkflowPinningRemediation(tt.filepath)
189+
if !cmp.Equal(got, tt.expected) {
190+
t.Errorf(cmp.Diff(got, tt.expected))
191+
}
192+
})
193+
}
194+
}

0 commit comments

Comments
 (0)