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

Function Test_ValidateInputCmd_DefaultTextOutput

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

Source from the content-addressed store, hash-verified

399}
400
401func Test_ValidateInputCmd_DefaultTextOutput(t *testing.T) {
402 fs := afero.NewMemMapFs()
403 require.NoError(t, afero.WriteFile(fs, "/input.yaml", []byte("some: data"), 0o644))
404
405 // Mock validator: returns success with no violations, one success result.
406 outMock := &output.Output{
407 PolicyCheck: []evaluator.Outcome{
408 {
409 Successes: []evaluator.Result{
410 {
411 Message: "Everything looks great!",
412 Metadata: map[string]interface{}{
413 "code": "policy.nice",
414 },
415 },
416 },
417 },
418 },
419 }
420
421 cmd, buf := setUpValidateInputCmd(mockValidate(outMock, nil), fs)
422 cmd.SetArgs([]string{
423 "input",
424 "--file", "/input.yaml",
425 "--policy", `{"publicKey": "testkey"}`,
426 // No --output flag, should default to text
427 })
428
429 utils.SetTestRekorPublicKey(t)
430 err := cmd.Execute()
431 assert.NoError(t, err)
432
433 output := buf.String()
434 // Verify text output format
435 assert.Contains(t, output, "Success: true")
436 assert.Contains(t, output, "Result: SUCCESS")
437 assert.Contains(t, output, "Violations: 0")
438 assert.Contains(t, output, "Input File: /input.yaml")
439 // Results section should not appear when there are only successes and showSuccesses=false
440 assert.NotContains(t, output, "Results:")
441}
442
443func Test_ValidateInputCmd_TextOutputWithShowSuccesses(t *testing.T) {
444 fs := afero.NewMemMapFs()

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected