TestValidationErrors checks whether the provided rawErrors are instance of [validation.Errors] and contains the expectedErrors keys.
(t *testing.T, rawErrors error, expectedErrors []string)
| 10 | // TestValidationErrors checks whether the provided rawErrors are |
| 11 | // instance of [validation.Errors] and contains the expectedErrors keys. |
| 12 | func TestValidationErrors(t *testing.T, rawErrors error, expectedErrors []string) { |
| 13 | var errs validation.Errors |
| 14 | |
| 15 | if rawErrors != nil && !errors.As(rawErrors, &errs) { |
| 16 | t.Fatalf("Failed to parse errors, expected to find validation.Errors, got %T\n%v", rawErrors, rawErrors) |
| 17 | } |
| 18 | |
| 19 | if len(errs) != len(expectedErrors) { |
| 20 | keys := make([]string, 0, len(errs)) |
| 21 | for k := range errs { |
| 22 | keys = append(keys, k) |
| 23 | } |
| 24 | t.Fatalf("Expected error keys \n%v\ngot\n%v\n%v", expectedErrors, keys, errs) |
| 25 | } |
| 26 | |
| 27 | for _, k := range expectedErrors { |
| 28 | if _, ok := errs[k]; !ok { |
| 29 | t.Fatalf("Missing expected error key %q in %v", k, errs) |
| 30 | } |
| 31 | } |
| 32 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…