MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / TestFormatErrorSummary

Function TestFormatErrorSummary

pkg/errors/formatter_test.go:195–238  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

193}
194
195func TestFormatErrorSummary(t *testing.T) {
196 tests := []struct {
197 name string
198 err error
199 wantCode bool
200 contains []string
201 }{
202 {
203 name: "structured error",
204 err: NewError(ErrCodeUnexpectedToken, "unexpected token", models.Location{Line: 5, Column: 10}),
205 wantCode: true,
206 contains: []string{
207 "[E2001]",
208 "unexpected token",
209 "line 5, column 10",
210 },
211 },
212 {
213 name: "simple error",
214 err: fmt.Errorf("simple error"),
215 wantCode: false,
216 contains: []string{
217 "Error:",
218 "simple error",
219 },
220 },
221 }
222
223 for _, tt := range tests {
224 t.Run(tt.name, func(t *testing.T) {
225 got := FormatErrorSummary(tt.err)
226
227 for _, substr := range tt.contains {
228 if !strings.Contains(got, substr) {
229 t.Errorf("FormatErrorSummary() missing substring %q\nGot: %s", substr, got)
230 }
231 }
232
233 if tt.wantCode && !strings.Contains(got, "[E") {
234 t.Errorf("FormatErrorSummary() should contain error code [E*]\nGot: %s", got)
235 }
236 })
237 }
238}
239
240func TestFormatErrorWithSuggestion(t *testing.T) {
241 tests := []struct {

Callers

nothing calls this directly

Calls 4

FormatErrorSummaryFunction · 0.85
RunMethod · 0.80
NewErrorFunction · 0.70
ErrorfMethod · 0.65

Tested by

no test coverage detected