MCPcopy Create free account
hub / github.com/PostHog/duckgres / TestMain

Function TestMain

tests/integration/setup_test.go:257–311  ·  view source on GitHub ↗

TestMain sets up and tears down the test environment

(m *testing.M)

Source from the content-addressed store, hash-verified

255
256// TestMain sets up and tears down the test environment
257func 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
314func runQueryTest(t *testing.T, test QueryTest) {

Callers

nothing calls this directly

Calls 9

IsPostgresRunningFunction · 0.85
StartPostgresContainerFunction · 0.85
IsDuckLakeInfraRunningFunction · 0.85
WaitForDuckLakeInfraFunction · 0.85
NewTestHarnessFunction · 0.85
DefaultConfigFunction · 0.70
RunMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected