requireJSONInputValidationError asserts err is a typed *errs.ValidationError with subtype invalid_argument, exit code 2 (legacy ErrValidation parity), and the offending flag recorded as Param.
(t *testing.T, err error, wantParam string)
| 16 | // with subtype invalid_argument, exit code 2 (legacy ErrValidation parity), |
| 17 | // and the offending flag recorded as Param. |
| 18 | func requireJSONInputValidationError(t *testing.T, err error, wantParam string) { |
| 19 | t.Helper() |
| 20 | var valErr *errs.ValidationError |
| 21 | if !errors.As(err, &valErr) { |
| 22 | t.Fatalf("expected *errs.ValidationError, got %T: %v", err, err) |
| 23 | } |
| 24 | if valErr.Subtype != errs.SubtypeInvalidArgument { |
| 25 | t.Errorf("subtype = %q, want %q", valErr.Subtype, errs.SubtypeInvalidArgument) |
| 26 | } |
| 27 | if valErr.Param != wantParam { |
| 28 | t.Errorf("param = %q, want %q", valErr.Param, wantParam) |
| 29 | } |
| 30 | if got := output.ExitCodeOf(err); got != output.ExitValidation { |
| 31 | t.Errorf("exit code = %d, want %d (ExitValidation, legacy parity)", got, output.ExitValidation) |
| 32 | } |
| 33 | if valErr.Cause == nil { |
| 34 | t.Error("expected the underlying parse/resolve error attached as Cause") |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | func TestParseOptionalBody(t *testing.T) { |
| 39 | fio := &localfileio.LocalFileIO{} |
no test coverage detected