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

Function Test_ValidateImageCommandJSONPolicyFile

cmd/validate/image_test.go:617–665  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

615}
616
617func Test_ValidateImageCommandJSONPolicyFile(t *testing.T) {
618 validateImageCmd := validateImageCmd(happyValidator())
619 cmd := setUpCobra(validateImageCmd)
620
621 client := fake.FakeClient{}
622 commonMockClient(&client)
623 fs := afero.NewMemMapFs()
624 ctx := utils.WithFS(context.Background(), fs)
625 ctx = oci.WithClient(ctx, &client)
626
627 mdl := MockDownloader{}
628 mdl.On("Download", mock.Anything, "registry/policy:latest", false).Return(&ociMetadata.OCIMetadata{Digest: "sha256:da54bca5477bf4e3449bc37de1822888fa0fbb8d89c640218cb31b987374d357"}, nil)
629 mdl.On("Download", mock.Anything, "registry/policy-data:latest", false).Return(&ociMetadata.OCIMetadata{Digest: "sha256:da54bca5477bf4e3449bc37de1822888fa0fbb8d89c640218cb31b987374d357"}, nil)
630 ctx = context.WithValue(ctx, source.DownloaderFuncKey, &mdl)
631
632 cmd.SetContext(ctx)
633
634 testPolicyJSON := `sources:
635 - policy:
636 - "registry/policy:latest"
637 data:
638 - "registry/policy-data:latest"
639 config:
640 include:
641 - '@minimal'
642 exclude: []
643`
644 err := afero.WriteFile(fs, "/policy.json", []byte(testPolicyJSON), 0o644)
645 if err != nil {
646 panic(err)
647 }
648 args := append(rootArgs, []string{
649 "--image",
650 "registry/image:tag",
651 "--public-key",
652 utils.TestPublicKey,
653 "--policy",
654 "/policy.json",
655 }...)
656 cmd.SetArgs(args)
657
658 var out bytes.Buffer
659 cmd.SetOut(&out)
660
661 utils.SetTestRekorPublicKey(t)
662
663 err = cmd.Execute()
664 assert.NoError(t, err)
665}
666
667func Test_ValidateImageCommandExtraData(t *testing.T) {
668 validateImageCmd := validateImageCmd(happyValidator())

Callers

nothing calls this directly

Calls 7

WithFSFunction · 0.92
WithClientFunction · 0.92
SetTestRekorPublicKeyFunction · 0.92
validateImageCmdFunction · 0.85
happyValidatorFunction · 0.85
commonMockClientFunction · 0.85
setUpCobraFunction · 0.70

Tested by

no test coverage detected