Skip to content

Commit 0830551

Browse files
author
Roman Bolkhovitin
committed
add create function to integration tests
1 parent 698bd9f commit 0830551

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

database/pgx/pgx_test.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,13 @@ func TestMultipleStatementsInMultiStatementMode(t *testing.T) {
211211
t.Error(err)
212212
}
213213
}()
214-
if err := d.Run(strings.NewReader("CREATE TABLE foo (foo text); CREATE INDEX CONCURRENTLY idx_foo ON foo (foo);")); err != nil {
214+
if err := d.Run(strings.NewReader(`CREATE TABLE foo (foo text);
215+
CREATE INDEX CONCURRENTLY idx_foo ON foo (foo);
216+
CREATE FUNCTION baz() RETURNS integer AS $$
217+
BEGIN
218+
RETURN 1;
219+
END;
220+
$$ LANGUAGE plpgsql;`)); err != nil {
215221
t.Fatalf("expected err to be nil, got %v", err)
216222
}
217223

@@ -223,6 +229,15 @@ func TestMultipleStatementsInMultiStatementMode(t *testing.T) {
223229
if !exists {
224230
t.Fatalf("expected table bar to exist")
225231
}
232+
233+
// make sure procedure exists
234+
var proc string
235+
if err := d.(*Postgres).conn.QueryRowContext(context.Background(), "SELECT 'baz'::regproc;").Scan(&proc); err != nil {
236+
t.Fatal(err)
237+
}
238+
if proc != "baz" {
239+
t.Fatalf("expected procedure baz to exists")
240+
}
226241
})
227242
}
228243

database/pgx/v5/pgx_test.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,13 @@ func TestMultipleStatementsInMultiStatementMode(t *testing.T) {
186186
t.Error(err)
187187
}
188188
}()
189-
if err := d.Run(strings.NewReader("CREATE TABLE foo (foo text); CREATE INDEX CONCURRENTLY idx_foo ON foo (foo);")); err != nil {
189+
if err := d.Run(strings.NewReader(`CREATE TABLE foo (foo text);
190+
CREATE INDEX CONCURRENTLY idx_foo ON foo (foo);
191+
CREATE FUNCTION baz() RETURNS integer AS $$
192+
BEGIN
193+
RETURN 1;
194+
END;
195+
$$ LANGUAGE plpgsql;`)); err != nil {
190196
t.Fatalf("expected err to be nil, got %v", err)
191197
}
192198

@@ -198,6 +204,15 @@ func TestMultipleStatementsInMultiStatementMode(t *testing.T) {
198204
if !exists {
199205
t.Fatalf("expected table bar to exist")
200206
}
207+
208+
// make sure procedure exists
209+
var proc string
210+
if err := d.(*Postgres).conn.QueryRowContext(context.Background(), "SELECT 'baz'::regproc;").Scan(&proc); err != nil {
211+
t.Fatal(err)
212+
}
213+
if proc != "baz" {
214+
t.Fatalf("expected procedure baz to exists")
215+
}
201216
})
202217
}
203218

database/postgres/postgres_test.go

+17-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,14 @@ func TestMultipleStatementsInMultiStatementMode(t *testing.T) {
183183
t.Error(err)
184184
}
185185
}()
186-
if err := d.Run(strings.NewReader("CREATE TABLE foo (foo text); CREATE INDEX CONCURRENTLY idx_foo ON foo (foo);")); err != nil {
186+
if err := d.Run(strings.NewReader(`CREATE TABLE foo (foo text);
187+
CREATE INDEX CONCURRENTLY idx_foo ON foo (foo);
188+
CREATE FUNCTION baz() RETURNS integer AS $$
189+
BEGIN
190+
RETURN 1;
191+
END;
192+
$$ LANGUAGE plpgsql;
193+
`)); err != nil {
187194
t.Fatalf("expected err to be nil, got %v", err)
188195
}
189196

@@ -195,6 +202,15 @@ func TestMultipleStatementsInMultiStatementMode(t *testing.T) {
195202
if !exists {
196203
t.Fatalf("expected table bar to exist")
197204
}
205+
206+
// make sure procedure exists
207+
var proc string
208+
if err := d.(*Postgres).conn.QueryRowContext(context.Background(), "SELECT 'baz'::regproc;").Scan(&proc); err != nil {
209+
t.Fatal(err)
210+
}
211+
if proc != "baz" {
212+
t.Fatalf("expected procedure baz to exists")
213+
}
198214
})
199215
}
200216

0 commit comments

Comments
 (0)