MCPcopy Create free account
hub / github.com/cockroachdb/errors / TestFormat

Function TestFormat

domains/domains_test.go:179–242  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

177}
178
179func TestFormat(t *testing.T) {
180 tt := testutils.T{t}
181
182 baseErr := goErr.New("woo")
183 const woo = `woo`
184 const waawoo = `waa: woo`
185 testCases := []struct {
186 name string
187 err error
188 expFmtSimple string
189 expFmtVerbose string
190 }{
191 {"keys",
192 domains.WithDomain(baseErr, domains.NoDomain),
193 woo, `
194woo
195(1) error domain: <none>
196Wraps: (2) woo
197Error types: (1) *domains.withDomain (2) *errors.errorString`},
198
199 {"keys + wrapper",
200 domains.WithDomain(&werrFmt{baseErr, "waa"}, domains.NoDomain),
201 waawoo, `
202waa: woo
203(1) error domain: <none>
204Wraps: (2) waa
205 | -- this is waa's
206 | multi-line payload
207Wraps: (3) woo
208Error types: (1) *domains.withDomain (2) *domains_test.werrFmt (3) *errors.errorString`},
209
210 {"wrapper + keys",
211 &werrFmt{domains.WithDomain(baseErr, domains.NoDomain), "waa"},
212 waawoo, `
213waa: woo
214(1) waa
215 | -- this is waa's
216 | multi-line payload
217Wraps: (2) error domain: <none>
218Wraps: (3) woo
219Error types: (1) *domains_test.werrFmt (2) *domains.withDomain (3) *errors.errorString`},
220 }
221
222 for _, test := range testCases {
223 tt.Run(test.name, func(tt testutils.T) {
224 err := test.err
225
226 // %s is simple formatting
227 tt.CheckStringEqual(fmt.Sprintf("%s", err), test.expFmtSimple)
228
229 // %v is simple formatting too, for compatibility with the past.
230 tt.CheckStringEqual(fmt.Sprintf("%v", err), test.expFmtSimple)
231
232 // %q is always like %s but quotes the result.
233 ref := fmt.Sprintf("%q", test.expFmtSimple)
234 tt.CheckStringEqual(fmt.Sprintf("%q", err), ref)
235
236 // %+v is the verbose mode.

Callers

nothing calls this directly

Calls 3

RunMethod · 0.95
CheckStringEqualMethod · 0.95
WithDomainFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…