(t *testing.T)
| 230 | } |
| 231 | |
| 232 | func 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 { |
nothing calls this directly
no test coverage detected