From f082ae9a138edd1ee1bcdfc40276013064fbec7e Mon Sep 17 00:00:00 2001 From: Stefan Majewsky Date: Tue, 10 Nov 2026 00:32:16 +0100 Subject: replace execQuery() with new gsql.Exec() helper --- testing/pgruntime/connect_test.go | 3 ++- testing/pgruntime/helpers_test.go | 23 ----------------------- testing/pgruntime/migration_test.go | 5 +++-- 3 files changed, 5 insertions(+), 26 deletions(-) delete mode 100644 testing/pgruntime/helpers_test.go (limited to 'testing') diff --git a/testing/pgruntime/connect_test.go b/testing/pgruntime/connect_test.go index f43c6f8..d821fb0 100644 --- a/testing/pgruntime/connect_test.go +++ b/testing/pgruntime/connect_test.go @@ -7,6 +7,7 @@ import ( "testing" "go.xyrillian.de/gg/assert" + "go.xyrillian.de/gg/gsql" "go.xyrillian.de/gg/oblast" ) @@ -21,7 +22,7 @@ func TestMultipleConnectionsToSameDB(t *testing.T) { `INSERT INTO objects (name) VALUES ('foo')`, // -> id = 1 `INSERT INTO objects (name) VALUES ('bar')`, // -> id = 2 } { - _, err := execQuery(ctx, db1, query, nil) + _, err := gsql.Exec(ctx, db1, query) if err != nil { t.Fatalf("in query %q: %s", query, err.Error()) } diff --git a/testing/pgruntime/helpers_test.go b/testing/pgruntime/helpers_test.go deleted file mode 100644 index d8c3cc9..0000000 --- a/testing/pgruntime/helpers_test.go +++ /dev/null @@ -1,23 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Stefan Majewsky -// SPDX-License-Identifier: Apache-2.0 - -package pgruntime_test - -import ( - "context" - "database/sql" - - "go.xyrillian.de/gg/errext" - "go.xyrillian.de/gg/gsql" -) - -// Convenience function for executing a one-off SQL query returning no rows. -// TODO: move to gsql -func execQuery(ctx context.Context, db gsql.Handle, query string, args []any) (sql.Result, error) { - stmt, err := db.GSQLPrepare(ctx, query, false) - if err != nil { - return nil, err - } - result, err := stmt.Exec(ctx, args) - return result, errext.WithCleanup(err, "stmt.Close", stmt.Close()) -} diff --git a/testing/pgruntime/migration_test.go b/testing/pgruntime/migration_test.go index 6113c36..d65741a 100644 --- a/testing/pgruntime/migration_test.go +++ b/testing/pgruntime/migration_test.go @@ -7,6 +7,7 @@ import ( "testing" "go.xyrillian.de/gg/assert" + "go.xyrillian.de/gg/gsql" "go.xyrillian.de/gg/oblast" "go.xyrillian.de/gg/pgruntime" ) @@ -17,7 +18,7 @@ func TestMigrations(t *testing.T) { // reset the test DB to empty if it exists db, _ := connector.ConnectForTest(t, defaultBehavior) for _, tableName := range []string{"comments", "posts", "schema_migrations"} { - _, err := execQuery(ctx, db, `DROP TABLE IF EXISTS `+tableName, nil) + _, err := gsql.Exec(ctx, db, `DROP TABLE IF EXISTS `+tableName) if err != nil { t.Fatal(err.Error()) } @@ -50,7 +51,7 @@ func TestMigrations(t *testing.T) { if err != nil { t.Fatal(err.Error()) } - _, err = execQuery(ctx, db, `INSERT INTO comments (post_id, message) VALUES ($1, $2)`, []any{postID, "Hi there."}) + _, err = gsql.Exec(ctx, db, `INSERT INTO comments (post_id, message) VALUES ($1, $2)`, postID, "Hi there.") if err != nil { t.Fatal(err.Error()) } -- cgit v1.3.1