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

Function TestPgDatabaseViewContent

server/catalog_test.go:57–118  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

55}
56
57func TestPgDatabaseViewContent(t *testing.T) {
58 db, err := sql.Open("duckdb", ":memory:")
59 if err != nil {
60 t.Fatalf("Failed to open database: %v", err)
61 }
62 defer func() { _ = db.Close() }()
63
64 if err := initPgCatalog(db, processStartTime, processStartTime, "dev", "dev"); err != nil {
65 t.Fatalf("Failed to init pg_catalog: %v", err)
66 }
67
68 // Test that we have the expected databases
69 rows, err := db.Query("SELECT datname, datlocprovider, datistemplate, datallowconn FROM pg_database ORDER BY oid")
70 if err != nil {
71 t.Fatalf("Failed to query pg_database: %v", err)
72 }
73 defer func() { _ = rows.Close() }()
74
75 expected := []struct {
76 datname string
77 datlocprovider string
78 datistemplate bool
79 datallowconn bool
80 }{
81 {"postgres", "c", false, true},
82 {"template0", "c", true, false},
83 {"template1", "c", true, true},
84 {"testdb", "c", false, true}, // Hardcoded to match integration test PostgreSQL container
85 }
86
87 i := 0
88 for rows.Next() {
89 var datname, datlocprovider string
90 var datistemplate, datallowconn bool
91 if err := rows.Scan(&datname, &datlocprovider, &datistemplate, &datallowconn); err != nil {
92 t.Fatalf("Failed to scan row: %v", err)
93 }
94
95 if i >= len(expected) {
96 t.Errorf("Unexpected extra row: %s", datname)
97 continue
98 }
99
100 if datname != expected[i].datname {
101 t.Errorf("Row %d datname: expected %q, got %q", i, expected[i].datname, datname)
102 }
103 if datlocprovider != expected[i].datlocprovider {
104 t.Errorf("Row %d datlocprovider: expected %q, got %q", i, expected[i].datlocprovider, datlocprovider)
105 }
106 if datistemplate != expected[i].datistemplate {
107 t.Errorf("Row %d datistemplate: expected %v, got %v", i, expected[i].datistemplate, datistemplate)
108 }
109 if datallowconn != expected[i].datallowconn {
110 t.Errorf("Row %d datallowconn: expected %v, got %v", i, expected[i].datallowconn, datallowconn)
111 }
112 i++
113 }
114

Callers

nothing calls this directly

Calls 6

initPgCatalogFunction · 0.85
CloseMethod · 0.65
QueryMethod · 0.65
NextMethod · 0.65
ScanMethod · 0.65
OpenMethod · 0.45

Tested by

no test coverage detected