(t *testing.T)
| 899 | } |
| 900 | |
| 901 | func Test_ValidateErrorCommand(t *testing.T) { |
| 902 | cases := []struct { |
| 903 | name string |
| 904 | args []string |
| 905 | expected string |
| 906 | }{ |
| 907 | { |
| 908 | name: "image validation failure", |
| 909 | args: []string{ |
| 910 | "--image", |
| 911 | "registry/image:tag", |
| 912 | "--policy", |
| 913 | fmt.Sprintf(`{"publicKey": %s}`, utils.TestPublicKeyJSON), |
| 914 | }, |
| 915 | expected: `error validating image registry/image:tag of component Unnamed: expected`, |
| 916 | }, |
| 917 | { |
| 918 | name: "invalid policy JSON", |
| 919 | args: []string{ |
| 920 | "--image", |
| 921 | "registry/image:tag", |
| 922 | "--policy", |
| 923 | `{"invalid": "json""}`, |
| 924 | }, |
| 925 | expected: `unable to parse EnterpriseContractPolicySpec: error converting YAML to JSON: yaml: found unexpected end of stream`, |
| 926 | }, |
| 927 | { |
| 928 | name: "invalid input JSON", |
| 929 | args: []string{ |
| 930 | "--json-input", |
| 931 | `{"invalid": "json""}`, |
| 932 | "--policy", |
| 933 | fmt.Sprintf(`{"publicKey": %s}`, utils.TestPublicKeyJSON), |
| 934 | }, |
| 935 | expected: `unable to parse Snapshot specification from {"invalid": "json""}: error converting YAML to JSON: yaml: found unexpected end of stream`, |
| 936 | }, |
| 937 | { |
| 938 | name: "invalid input and policy JSON", |
| 939 | args: []string{ |
| 940 | "--json-input", |
| 941 | `{"invalid": "json""}`, |
| 942 | "--policy", |
| 943 | `{"invalid": "json""}`, |
| 944 | }, |
| 945 | expected: `unable to parse Snapshot specification from {"invalid": "json""}: error converting YAML to JSON: yaml: found unexpected end of stream |
| 946 | unable to parse EnterpriseContractPolicySpec: error converting YAML to JSON: yaml: found unexpected end of stream`, |
| 947 | }, |
| 948 | } |
| 949 | for _, c := range cases { |
| 950 | t.Run(c.name, func(t *testing.T) { |
| 951 | validate := func(context.Context, app.SnapshotComponent, *app.SnapshotSpec, policy.Policy, []evaluator.Evaluator, bool) (*output.Output, error) { |
| 952 | return nil, errors.New("expected") |
| 953 | } |
| 954 | |
| 955 | validateImageCmd := validateImageCmd(validate) |
| 956 | cmd := setUpCobra(validateImageCmd) |
| 957 | |
| 958 | client := fake.FakeClient{} |
nothing calls this directly
no test coverage detected