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

Function AssertValidSQL

pkg/gosqlx/testing/testing.go:45–55  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

43//
44// testing.AssertValidSQL(t, "SELECT * FROM users WHERE active = true")
45func 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.

Callers 2

TestAssertValidSQL_ValidFunction · 0.85

Calls 4

ValidateFunction · 0.92
truncateSQLFunction · 0.85
HelperMethod · 0.65
ErrorfMethod · 0.65

Tested by 2

TestAssertValidSQL_ValidFunction · 0.68