(t *testing.T)
| 808 | } |
| 809 | |
| 810 | func Test_ValidateImageError(t *testing.T) { |
| 811 | cases := []struct { |
| 812 | name string |
| 813 | args []string |
| 814 | expected string |
| 815 | }{ |
| 816 | { |
| 817 | name: "image validation failure: incorrect syntax for extraRuleData", |
| 818 | args: []string{ |
| 819 | "--image", |
| 820 | "registry/image:tag", |
| 821 | "--public-key", |
| 822 | utils.TestPublicKey, |
| 823 | "--policy", |
| 824 | "/policy.yaml", |
| 825 | "--extra-rule-data", |
| 826 | "key-without-value-1,key-without-value-2", |
| 827 | }, |
| 828 | expected: "incorrect syntax for --extra-rule-data 0\nincorrect syntax for --extra-rule-data 1", |
| 829 | }, |
| 830 | { |
| 831 | name: "image validation failure: unable to load extraRuleData", |
| 832 | args: []string{ |
| 833 | "--image", |
| 834 | "registry/image:tag", |
| 835 | "--public-key", |
| 836 | utils.TestPublicKey, |
| 837 | "--policy", |
| 838 | "/policy.yaml", |
| 839 | "--extra-rule-data", |
| 840 | "key=/value.json", |
| 841 | }, |
| 842 | expected: "unable to load data from extraRuleData: file /value.json is empty", |
| 843 | }, |
| 844 | } |
| 845 | for _, c := range cases { |
| 846 | t.Run(c.name, func(t *testing.T) { |
| 847 | validateImageCmd := validateImageCmd(happyValidator()) |
| 848 | cmd := setUpCobra(validateImageCmd) |
| 849 | |
| 850 | fs := afero.NewMemMapFs() |
| 851 | |
| 852 | ctx := utils.WithFS(context.Background(), fs) |
| 853 | client := fake.FakeClient{} |
| 854 | commonMockClient(&client) |
| 855 | ctx = oci.WithClient(ctx, &client) |
| 856 | |
| 857 | mdl := MockDownloader{} |
| 858 | mdl. |
| 859 | On("Download", mock.Anything, "oci://registry/policy:latest", false). |
| 860 | Return(&ociMetadata.OCIMetadata{Digest: "sha256:da54bca5477bf4e3449bc37de1822888fa0fbb8d89c640218cb31b987374d357"}, nil) |
| 861 | mdl. |
| 862 | On("Download", mock.Anything, "oci://registry/policy-data:latest", false). |
| 863 | Return(&ociMetadata.OCIMetadata{Digest: "sha256:da54bca5477bf4e3449bc37de1822888fa0fbb8d89c640218cb31b987374d357"}, nil) |
| 864 | ctx = context.WithValue(ctx, source.DownloaderFuncKey, &mdl) |
| 865 | |
| 866 | cmd.SetContext(ctx) |
| 867 |
nothing calls this directly
no test coverage detected