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

Function Test_ValidateInputCmd_ShowWarningsFlag

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

Source from the content-addressed store, hash-verified

314}
315
316func Test_ValidateInputCmd_ShowWarningsFlag(t *testing.T) {
317 // Create a validator that returns warnings
318 warningValidator := func(_ context.Context, fpath string, _ policy.Policy, _ bool) (*output.Output, error) {
319 return &output.Output{
320 PolicyCheck: []evaluator.Outcome{
321 {
322 Warnings: []evaluator.Result{
323 {
324 Message: "This is a warning message",
325 Metadata: map[string]interface{}{
326 "code": "warning.test",
327 "title": "Test Warning",
328 },
329 },
330 },
331 },
332 },
333 }, nil
334 }
335
336 cases := []struct {
337 name string
338 args []string
339 expectedWarnings bool
340 }{
341 {
342 name: "default behavior (show-warnings=true)",
343 args: []string{"input", "--file", "/file.yaml", "--policy", `{"publicKey": "testkey"}`},
344 expectedWarnings: true,
345 },
346 {
347 name: "explicit show-warnings=true",
348 args: []string{"input", "--file", "/file.yaml", "--policy", `{"publicKey": "testkey"}`, "--show-warnings=true"},
349 expectedWarnings: true,
350 },
351 {
352 name: "show-warnings=false",
353 args: []string{"input", "--file", "/file.yaml", "--policy", `{"publicKey": "testkey"}`, "--show-warnings=false"},
354 expectedWarnings: false,
355 },
356 }
357
358 for _, c := range cases {
359 t.Run(c.name, func(t *testing.T) {
360 fs := afero.NewMemMapFs()
361 require.NoError(t, afero.WriteFile(fs, "/file.yaml", []byte("some: data"), 0o644))
362
363 cmd, buf := setUpValidateInputCmd(warningValidator, fs)
364 args := append(c.args, "--output", "json") // Explicitly request JSON output
365 cmd.SetArgs(args)
366
367 utils.SetTestRekorPublicKey(t)
368 err := cmd.Execute()
369 assert.NoError(t, err)
370
371 // Parse the JSON output
372 var outJSON map[string]interface{}
373 err = json.Unmarshal(buf.Bytes(), &outJSON)

Callers

nothing calls this directly

Calls 3

SetTestRekorPublicKeyFunction · 0.92
setUpValidateInputCmdFunction · 0.85
RunMethod · 0.65

Tested by

no test coverage detected