ErrorContains asserts err != nil and err.Error() contains sub. The match will be case insensitive.
(t testing.TB, name string, err error, sub string)
| 70 | // |
| 71 | // The match will be case insensitive. |
| 72 | func ErrorContains(t testing.TB, name string, err error, sub string) { |
| 73 | slog.Helper() |
| 74 | |
| 75 | Error(t, name, err) |
| 76 | |
| 77 | errs := err.Error() |
| 78 | if !stringContainsFold(errs, sub) { |
| 79 | slogtest.Fatal(t, "unexpected error string", |
| 80 | slog.F("name", name), |
| 81 | slog.F("error_string", errs), |
| 82 | slog.F("expected_contains", sub), |
| 83 | ) |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | func stringContainsFold(errs, sub string) bool { |
| 88 | errs = strings.ToLower(errs) |