| 9 | ) |
| 10 | |
| 11 | func TestRootExprValidate(t *testing.T) { |
| 12 | cases := map[string]struct { |
| 13 | api *APIExpr |
| 14 | expected *eval.ValidationErrors |
| 15 | }{ |
| 16 | "no error": { |
| 17 | api: &APIExpr{ |
| 18 | Name: "foo", |
| 19 | }, |
| 20 | expected: &eval.ValidationErrors{ |
| 21 | Errors: []error{}, |
| 22 | }, |
| 23 | }, |
| 24 | "missing api declaration": { |
| 25 | api: nil, |
| 26 | expected: &eval.ValidationErrors{ |
| 27 | Errors: []error{fmt.Errorf("Missing API declaration")}, |
| 28 | }, |
| 29 | }, |
| 30 | } |
| 31 | |
| 32 | for k, tc := range cases { |
| 33 | e := RootExpr{ |
| 34 | API: tc.api, |
| 35 | } |
| 36 | var actual *eval.ValidationErrors |
| 37 | if errors.As(e.Validate(), &actual); len(tc.expected.Errors) != len(actual.Errors) { |
| 38 | t.Errorf("%s: expected the number of error values to match %d got %d ", k, len(tc.expected.Errors), len(actual.Errors)) |
| 39 | } else { |
| 40 | for i, err := range actual.Errors { |
| 41 | if err.Error() != tc.expected.Errors[i].Error() { |
| 42 | t.Errorf("%s: got %#v, expected %#v at index %d", k, err, tc.expected.Errors[i], i) |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | func TestMetaExpr_Last(t *testing.T) { |
| 50 | tt := map[string]struct { |