MCPcopy
hub / github.com/sqlc-dev/sqlc / TestExpandMySQL

Function TestExpandMySQL

internal/x/expander/expander_test.go:232–347  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

230}
231
232func TestExpandMySQL(t *testing.T) {
233 ctx := context.Background()
234
235 source := os.Getenv("MYSQL_SERVER_URI")
236 if source == "" {
237 if err := docker.Installed(); err == nil {
238 u, err := docker.StartMySQLServer(ctx)
239 if err != nil {
240 t.Fatal(err)
241 }
242 source = u
243 } else if err := native.Supported(); err == nil {
244 u, err := native.StartMySQLServer(ctx)
245 if err != nil {
246 t.Fatal(err)
247 }
248 source = u
249 } else {
250 t.Skip("MYSQL_SERVER_URI is empty and neither Docker nor native installation is available")
251 }
252 }
253
254 db, err := sql.Open("mysql", source)
255 if err != nil {
256 t.Skipf("could not connect to MySQL: %v", err)
257 }
258 defer db.Close()
259
260 // Verify connection
261 if err := db.Ping(); err != nil {
262 t.Skipf("could not ping MySQL: %v", err)
263 }
264
265 // Create a test table
266 _, err = db.ExecContext(ctx, `DROP TABLE IF EXISTS authors`)
267 if err != nil {
268 t.Fatalf("failed to drop test table: %v", err)
269 }
270 _, err = db.ExecContext(ctx, `
271 CREATE TABLE authors (
272 id INT AUTO_INCREMENT PRIMARY KEY,
273 name VARCHAR(255) NOT NULL,
274 bio TEXT
275 )
276 `)
277 if err != nil {
278 t.Fatalf("failed to create test table: %v", err)
279 }
280 defer db.ExecContext(ctx, "DROP TABLE IF EXISTS authors")
281
282 // Create the parser which also implements format.Dialect
283 parser := dolphin.NewParser()
284
285 // Create the expander
286 colGetter := &MySQLColumnGetter{db: db}
287 exp := New(colGetter, parser, parser)
288
289 tests := []struct {

Callers

nothing calls this directly

Calls 10

InstalledFunction · 0.92
StartMySQLServerFunction · 0.92
SupportedFunction · 0.92
StartMySQLServerFunction · 0.92
NewParserFunction · 0.92
OpenMethod · 0.80
ExpandMethod · 0.80
NewFunction · 0.70
CloseMethod · 0.65
ExecContextMethod · 0.65

Tested by

no test coverage detected