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

Function TestPlugin_OnParseError

integrations/gorm/plugin_test.go:120–146  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

118}
119
120func TestPlugin_OnParseError(t *testing.T) {
121 var called bool
122 var errSQL string
123
124 plugin := gosqlxgorm.NewPluginWithOptions(gosqlxgorm.PluginOptions{
125 OnParseError: func(sql string, err error) {
126 called = true
127 errSQL = sql
128 },
129 })
130
131 db := openTestDB(t)
132 _ = db.Use(plugin)
133
134 // Execute a raw query that is very likely to trigger a parse error.
135 db.Exec("PRAGMA table_info('users')")
136
137 // If no parse error was triggered, the test is inconclusive but should not fail.
138 // We check that the callback was wired correctly by verifying the stats.
139 stats := plugin.Stats()
140 if stats.ParseErrors > 0 && !called {
141 t.Error("OnParseError callback was not called despite parse errors")
142 }
143 if called && errSQL == "" {
144 t.Error("OnParseError was called but sql was empty")
145 }
146}
147
148func TestPlugin_DefaultMaxHistory(t *testing.T) {
149 // NewPlugin without options should use the default (1000).

Callers

nothing calls this directly

Calls 3

openTestDBFunction · 0.85
StatsMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected