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

Function TestFormat

telemetrykeys/telemetrykeys_test.go:70–133  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

68}
69
70func TestFormat(t *testing.T) {
71 tt := testutils.T{t}
72
73 baseErr := goErr.New("woo")
74 const woo = `woo`
75 const waawoo = `waa: woo`
76 testCases := []struct {
77 name string
78 err error
79 expFmtSimple string
80 expFmtVerbose string
81 }{
82 {"keys",
83 telemetrykeys.WithTelemetry(baseErr, "a", "b"),
84 woo, `
85woo
86(1) keys: [a b]
87Wraps: (2) woo
88Error types: (1) *telemetrykeys.withTelemetry (2) *errors.errorString`},
89
90 {"keys + wrapper",
91 telemetrykeys.WithTelemetry(&werrFmt{baseErr, "waa"}, "a", "b"),
92 waawoo, `
93waa: woo
94(1) keys: [a b]
95Wraps: (2) waa
96 | -- this is waa's
97 | multi-line payload
98Wraps: (3) woo
99Error types: (1) *telemetrykeys.withTelemetry (2) *telemetrykeys_test.werrFmt (3) *errors.errorString`},
100
101 {"wrapper + keys",
102 &werrFmt{telemetrykeys.WithTelemetry(baseErr, "a", "b"), "waa"},
103 waawoo, `
104waa: woo
105(1) waa
106 | -- this is waa's
107 | multi-line payload
108Wraps: (2) keys: [a b]
109Wraps: (3) woo
110Error types: (1) *telemetrykeys_test.werrFmt (2) *telemetrykeys.withTelemetry (3) *errors.errorString`},
111 }
112
113 for _, test := range testCases {
114 tt.Run(test.name, func(tt testutils.T) {
115 err := test.err
116
117 // %s is simple formatting
118 tt.CheckStringEqual(fmt.Sprintf("%s", err), test.expFmtSimple)
119
120 // %v is simple formatting too, for compatibility with the past.
121 tt.CheckStringEqual(fmt.Sprintf("%v", err), test.expFmtSimple)
122
123 // %q is always like %s but quotes the result.
124 ref := fmt.Sprintf("%q", test.expFmtSimple)
125 tt.CheckStringEqual(fmt.Sprintf("%q", err), ref)
126
127 // %+v is the verbose mode.

Callers

nothing calls this directly

Calls 3

RunMethod · 0.95
CheckStringEqualMethod · 0.95
WithTelemetryFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…