MCPcopy Create free account
hub / github.com/coder/slog / ErrorContains

Function ErrorContains

sloggers/slogtest/assert/assert.go:72–85  ·  view source on GitHub ↗

ErrorContains asserts err != nil and err.Error() contains sub. The match will be case insensitive.

(t testing.TB, name string, err error, sub string)

Source from the content-addressed store, hash-verified

70//
71// The match will be case insensitive.
72func 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
87func stringContainsFold(errs, sub string) bool {
88 errs = strings.ToLower(errs)

Callers 1

TestErrorContainsFunction · 0.92

Calls 5

FatalFunction · 0.92
stringContainsFoldFunction · 0.85
ErrorFunction · 0.70
HelperMethod · 0.45
ErrorMethod · 0.45

Tested by 1

TestErrorContainsFunction · 0.74