MCPcopy Create free account
hub / github.com/conforma/cli / Test_ValidateInputCmd_NonStrictMode

Function Test_ValidateInputCmd_NonStrictMode

cmd/validate/input_test.go:214–254  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

212}
213
214func Test_ValidateInputCmd_NonStrictMode(t *testing.T) {
215 fs := afero.NewMemMapFs()
216 require.NoError(t, afero.WriteFile(fs, "/file.yaml", []byte("some: data"), 0o644))
217
218 // Mock validator: returns no error but a violation (should not cause non-zero exit in non-strict mode).
219 outMock := &output.Output{
220 PolicyCheck: []evaluator.Outcome{
221 {
222 Failures: []evaluator.Result{
223 {Message: "Some violation"},
224 },
225 },
226 },
227 }
228
229 cmd, _ := setUpValidateInputCmd(mockValidate(outMock, nil), fs)
230 cmd.SetArgs([]string{
231 "input",
232 "--file", "/file.yaml",
233 "--policy", `{"publicKey": "testkey"}`,
234 "--strict", "false",
235 })
236
237 utils.SetTestRekorPublicKey(t)
238
239 // Capture output for assertions
240 outputBuffer := &bytes.Buffer{}
241 cmd.SetOut(outputBuffer)
242 cmd.SetErr(outputBuffer)
243
244 // Execute the command
245 err := cmd.Execute()
246
247 // Ensure no error is returned in non-strict mode
248 assert.Error(t, err)
249
250 // Check that the output mentions violations, but the command succeeds
251 output := outputBuffer.String()
252 assert.Contains(t, output, "Some violation")
253 assert.Contains(t, output, "success criteria not met")
254}
255
256func Test_ValidateInputCmd_NoPolicyProvided(t *testing.T) {
257 fs := afero.NewMemMapFs()

Callers

nothing calls this directly

Calls 5

SetTestRekorPublicKeyFunction · 0.92
setUpValidateInputCmdFunction · 0.85
mockValidateFunction · 0.85
ErrorMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected