AssertValidSQL asserts that the given SQL is syntactically valid. If the SQL is invalid, the test continues but is marked as failed. Example: testing.AssertValidSQL(t, "SELECT * FROM users WHERE active = true")
(t TestingT, sql string)
| 43 | // |
| 44 | // testing.AssertValidSQL(t, "SELECT * FROM users WHERE active = true") |
| 45 | func AssertValidSQL(t TestingT, sql string) bool { |
| 46 | t.Helper() |
| 47 | |
| 48 | err := gosqlx.Validate(sql) |
| 49 | if err != nil { |
| 50 | t.Errorf("Expected valid SQL, but got error:\n SQL: %s\n Error: %v", |
| 51 | truncateSQL(sql), err) |
| 52 | return false |
| 53 | } |
| 54 | return true |
| 55 | } |
| 56 | |
| 57 | // AssertInvalidSQL asserts that the given SQL is syntactically invalid. |
| 58 | // If the SQL is valid, the test continues but is marked as failed. |