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

Function TestFallbackUtilityWithComments

tests/integration/fallback_test.go:458–534  ·  view source on GitHub ↗

TestFallbackUtilityWithComments tests utility commands with leading comments

(t *testing.T)

Source from the content-addressed store, hash-verified

456
457// TestFallbackUtilityWithComments tests utility commands with leading comments
458func TestFallbackUtilityWithComments(t *testing.T) {
459 if testHarness == nil || testHarness.DuckgresDB == nil {
460 t.Skip("Test harness not available")
461 }
462
463 db := testHarness.DuckgresDB
464
465 t.Run("attach_with_comment", func(t *testing.T) {
466 skipIfKnown(t)
467
468 // Save current database so we can restore it (may be "memory" or "ducklake")
469 var originalDb string
470 if err := db.QueryRow("SELECT current_database()").Scan(&originalDb); err != nil {
471 t.Fatalf("Get current database failed: %v", err)
472 }
473
474 // ATTACH with block comment
475 _, err := db.Exec("/* attach test db */ ATTACH ':memory:' AS comment_attach_test")
476 if err != nil {
477 t.Fatalf("ATTACH with comment failed: %v", err)
478 }
479 defer func() {
480 // Always restore original database and detach, even on failure
481 _, _ = db.Exec("USE " + originalDb)
482 _, _ = db.Exec("DETACH comment_attach_test")
483 }()
484
485 // USE with line comment
486 _, err = db.Exec("-- switch db\nUSE comment_attach_test")
487 if err != nil {
488 t.Fatalf("USE with comment failed: %v", err)
489 }
490
491 if _, err := db.Exec("CREATE TABLE comment_attach_test.comment_probe (id INT)"); err != nil {
492 t.Fatalf("create table in attached database failed: %v", err)
493 }
494
495 var count int
496 if err := db.QueryRow("SELECT COUNT(*) FROM comment_attach_test.comment_probe").Scan(&count); err != nil {
497 t.Fatalf("query table in attached database failed: %v", err)
498 }
499 if count != 0 {
500 t.Errorf("Expected empty attached table, got %d rows", count)
501 }
502
503 // Switch back and detach (defer handles cleanup on failure too)
504 _, err = db.Exec("/* back to original */ USE " + originalDb)
505 if err != nil {
506 t.Fatalf("USE %s failed: %v", originalDb, err)
507 }
508
509 if _, err := db.Exec("SELECT * FROM users LIMIT 1"); err != nil {
510 t.Fatalf("expected users lookup to succeed after restoring original database: %v", err)
511 }
512
513 _, err = db.Exec("/* cleanup */ DETACH comment_attach_test")
514 if err != nil {
515 t.Fatalf("DETACH with comment failed: %v", err)

Callers

nothing calls this directly

Calls 4

skipIfKnownFunction · 0.85
RunMethod · 0.65
ScanMethod · 0.65
ExecMethod · 0.65

Tested by

no test coverage detected