(t *testing.T)
| 23 | ) |
| 24 | |
| 25 | func 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 | |
| 68 | func TestFormatErrorWithContextAt(t *testing.T) { |
| 69 | tests := []struct { |
nothing calls this directly
no test coverage detected