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

Function Test_ValidateImageCommandEmptyPolicyFile

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

Source from the content-addressed store, hash-verified

768}
769
770func Test_ValidateImageCommandEmptyPolicyFile(t *testing.T) {
771 validateImageCmd := validateImageCmd(happyValidator())
772 cmd := setUpCobra(validateImageCmd)
773
774 client := fake.FakeClient{}
775 commonMockClient(&client)
776 fs := afero.NewMemMapFs()
777 ctx := utils.WithFS(context.Background(), fs)
778 ctx = oci.WithClient(ctx, &client)
779
780 mdl := MockDownloader{}
781 mdl.On("Download", mock.Anything, "registry/policy:latest", false).Return(&ociMetadata.OCIMetadata{Digest: "sha256:da54bca5477bf4e3449bc37de1822888fa0fbb8d89c640218cb31b987374d357"}, nil)
782 mdl.On("Download", mock.Anything, "registry/policy-data:latest", false).Return(&ociMetadata.OCIMetadata{Digest: "sha256:da54bca5477bf4e3449bc37de1822888fa0fbb8d89c640218cb31b987374d357"}, nil)
783 ctx = context.WithValue(ctx, source.DownloaderFuncKey, &mdl)
784
785 cmd.SetContext(ctx)
786
787 err := afero.WriteFile(fs, "/policy.yaml", []byte(nil), 0o644)
788 if err != nil {
789 panic(err)
790 }
791 args := append(rootArgs, []string{
792 "--image",
793 "registry/image:tag",
794 "--public-key",
795 utils.TestPublicKey,
796 "--policy",
797 "/policy.yaml",
798 }...)
799 cmd.SetArgs(args)
800
801 var out bytes.Buffer
802 cmd.SetOut(&out)
803
804 utils.SetTestRekorPublicKey(t)
805
806 err = cmd.Execute()
807 assert.EqualError(t, err, "file /policy.yaml is empty")
808}
809
810func Test_ValidateImageError(t *testing.T) {
811 cases := []struct {

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