TestMain sets up and tears down the test environment
(m *testing.M)
| 255 | |
| 256 | // TestMain sets up and tears down the test environment |
| 257 | func TestMain(m *testing.M) { |
| 258 | cfg := DefaultConfig() |
| 259 | |
| 260 | // Check if PostgreSQL (for comparison) is running |
| 261 | pgPort := cfg.PostgresPort |
| 262 | if !IsPostgresRunning(pgPort) { |
| 263 | fmt.Println("PostgreSQL container not running. Starting it...") |
| 264 | if err := StartPostgresContainer(); err != nil { |
| 265 | fmt.Printf("Failed to start PostgreSQL: %v\n", err) |
| 266 | fmt.Println("Running tests without PostgreSQL comparison (Duckgres-only mode)") |
| 267 | skipPostgresCompare = true |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | // Check and wait for DuckLake infrastructure if DuckLake mode is enabled |
| 272 | if cfg.UseDuckLake { |
| 273 | if !IsDuckLakeInfraRunning(cfg.DuckLakeMetadataPort, cfg.MinIOPort) { |
| 274 | fmt.Println("DuckLake infrastructure not running. Starting it...") |
| 275 | if err := StartDuckLakeInfraContainers(); err != nil { |
| 276 | fmt.Printf("Failed to start DuckLake infrastructure: %v\n", err) |
| 277 | fmt.Println("Falling back to vanilla DuckDB mode (set DUCKGRES_TEST_NO_DUCKLAKE=1 to suppress this)") |
| 278 | cfg.UseDuckLake = false |
| 279 | } |
| 280 | } |
| 281 | if cfg.UseDuckLake && !IsDuckLakeInfraRunning(cfg.DuckLakeMetadataPort, cfg.MinIOPort) { |
| 282 | fmt.Println("DuckLake infrastructure not ready yet. Waiting for it...") |
| 283 | if err := WaitForDuckLakeInfra(cfg.DuckLakeMetadataPort, cfg.MinIOPort, 30*time.Second); err != nil { |
| 284 | fmt.Printf("DuckLake infrastructure not available: %v\n", err) |
| 285 | fmt.Println("Falling back to vanilla DuckDB mode (set DUCKGRES_TEST_NO_DUCKLAKE=1 to suppress this)") |
| 286 | cfg.UseDuckLake = false |
| 287 | } else { |
| 288 | fmt.Println("DuckLake infrastructure is ready") |
| 289 | } |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | cfg.SkipPostgres = skipPostgresCompare |
| 294 | |
| 295 | var err error |
| 296 | testHarness, err = NewTestHarness(cfg) |
| 297 | if err != nil { |
| 298 | fmt.Printf("Failed to create test harness: %v\n", err) |
| 299 | os.Exit(1) |
| 300 | } |
| 301 | |
| 302 | // Run tests |
| 303 | code := m.Run() |
| 304 | |
| 305 | // Cleanup |
| 306 | if testHarness != nil { |
| 307 | _ = testHarness.Close() |
| 308 | } |
| 309 | |
| 310 | os.Exit(code) |
| 311 | } |
| 312 | |
| 313 | // runQueryTest runs a single query test |
| 314 | func runQueryTest(t *testing.T, test QueryTest) { |
nothing calls this directly
no test coverage detected