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

Function TestPgDatabaseView

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

Source from the content-addressed store, hash-verified

10)
11
12func TestPgDatabaseView(t *testing.T) {
13 db, err := sql.Open("duckdb", ":memory:")
14 if err != nil {
15 t.Fatalf("Failed to open database: %v", err)
16 }
17 defer func() { _ = db.Close() }()
18
19 if err := initPgCatalog(db, processStartTime, processStartTime, "dev", "dev"); err != nil {
20 t.Fatalf("Failed to init pg_catalog: %v", err)
21 }
22
23 // Test that pg_database view has all expected columns (PostgreSQL 16 compatible)
24 expectedColumns := []string{
25 "oid", "datname", "datdba", "encoding", "datlocprovider",
26 "datistemplate", "datallowconn", "datconnlimit", "datfrozenxid",
27 "datminmxid", "dattablespace", "datcollate", "datctype",
28 "daticulocale", "daticurules", "datcollversion", "datacl",
29 }
30
31 rows, err := db.Query("SELECT * FROM pg_database LIMIT 1")
32 if err != nil {
33 t.Fatalf("Failed to query pg_database: %v", err)
34 }
35 defer func() { _ = rows.Close() }()
36
37 columns, err := rows.Columns()
38 if err != nil {
39 t.Fatalf("Failed to get columns: %v", err)
40 }
41
42 if len(columns) != len(expectedColumns) {
43 t.Errorf("Expected %d columns, got %d", len(expectedColumns), len(columns))
44 }
45
46 for i, expected := range expectedColumns {
47 if i >= len(columns) {
48 t.Errorf("Missing column %d: %s", i, expected)
49 continue
50 }
51 if columns[i] != expected {
52 t.Errorf("Column %d: expected %q, got %q", i, expected, columns[i])
53 }
54 }
55}
56
57func TestPgDatabaseViewContent(t *testing.T) {
58 db, err := sql.Open("duckdb", ":memory:")

Callers

nothing calls this directly

Calls 5

initPgCatalogFunction · 0.85
CloseMethod · 0.65
QueryMethod · 0.65
ColumnsMethod · 0.65
OpenMethod · 0.45

Tested by

no test coverage detected