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

Function TestFormatErrorWithContext

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

Source from the content-addressed store, hash-verified

23)
24
25func TestFormatErrorWithContext(t *testing.T) {
26 tests := []struct {
27 name string
28 err error
29 sql string
30 contains []string
31 }{
32 {
33 name: "structured error",
34 err: NewError(ErrCodeUnexpectedToken, "unexpected token: IDENT", models.Location{Line: 1, Column: 10}).
35 WithContext("SELECT * FORM users", 4),
36 sql: "SELECT * FORM users",
37 contains: []string{
38 "Error E2001",
39 "line 1, column 10",
40 "unexpected token",
41 "SELECT * FORM users",
42 "^",
43 },
44 },
45 {
46 name: "non-structured error",
47 err: fmt.Errorf("simple error"),
48 sql: "SELECT * FROM users",
49 contains: []string{
50 "Error:",
51 "simple error",
52 },
53 },
54 }
55
56 for _, tt := range tests {
57 t.Run(tt.name, func(t *testing.T) {
58 got := FormatErrorWithContext(tt.err, tt.sql)
59 for _, substr := range tt.contains {
60 if !strings.Contains(got, substr) {
61 t.Errorf("FormatErrorWithContext() missing substring %q\nGot:\n%s", substr, got)
62 }
63 }
64 })
65 }
66}
67
68func TestFormatErrorWithContextAt(t *testing.T) {
69 tests := []struct {

Callers

nothing calls this directly

Calls 5

FormatErrorWithContextFunction · 0.85
RunMethod · 0.80
NewErrorFunction · 0.70
ErrorfMethod · 0.65
WithContextMethod · 0.45

Tested by

no test coverage detected