MCPcopy
hub / github.com/sqlc-dev/sqlc / TestExpandPostgreSQL

Function TestExpandPostgreSQL

internal/x/expander/expander_test.go:93–230  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

91}
92
93func TestExpandPostgreSQL(t *testing.T) {
94 ctx := context.Background()
95
96 uri := os.Getenv("POSTGRESQL_SERVER_URI")
97 if uri == "" {
98 if err := docker.Installed(); err == nil {
99 u, err := docker.StartPostgreSQLServer(ctx)
100 if err != nil {
101 t.Fatal(err)
102 }
103 uri = u
104 } else if err := native.Supported(); err == nil {
105 u, err := native.StartPostgreSQLServer(ctx)
106 if err != nil {
107 t.Fatal(err)
108 }
109 uri = u
110 } else {
111 t.Skip("POSTGRESQL_SERVER_URI is empty and neither Docker nor native installation is available")
112 }
113 }
114
115 pool, err := pgxpool.New(ctx, uri)
116 if err != nil {
117 t.Skipf("could not connect to database: %v", err)
118 }
119 defer pool.Close()
120
121 // Create a test table
122 _, err = pool.Exec(ctx, `
123 DROP TABLE IF EXISTS authors;
124 CREATE TABLE authors (
125 id SERIAL PRIMARY KEY,
126 name TEXT NOT NULL,
127 bio TEXT
128 );
129 `)
130 if err != nil {
131 t.Fatalf("failed to create test table: %v", err)
132 }
133 defer pool.Exec(ctx, "DROP TABLE IF EXISTS authors")
134
135 // Create the parser which also implements format.Dialect
136 parser := postgresql.NewParser()
137
138 // Create the expander
139 colGetter := &PostgreSQLColumnGetter{pool: pool}
140 exp := New(colGetter, parser, parser)
141
142 tests := []struct {
143 name string
144 query string
145 expected string
146 }{
147 {
148 name: "simple select star",
149 query: "SELECT * FROM authors",
150 expected: "SELECT id, name, bio FROM authors;",

Callers

nothing calls this directly

Calls 9

InstalledFunction · 0.92
StartPostgreSQLServerFunction · 0.92
SupportedFunction · 0.92
StartPostgreSQLServerFunction · 0.92
NewParserFunction · 0.92
ExpandMethod · 0.80
NewFunction · 0.70
CloseMethod · 0.65
ExecMethod · 0.65

Tested by

no test coverage detected