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

Function Test_ValidateErrorCommand

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

Source from the content-addressed store, hash-verified

899}
900
901func 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
946unable 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{}

Callers

nothing calls this directly

Calls 8

WithFSFunction · 0.92
WithClientFunction · 0.92
SetTestRekorPublicKeyFunction · 0.92
validateImageCmdFunction · 0.85
commonMockClientFunction · 0.85
setUpCobraFunction · 0.70
RunMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected