1
0
mirror of https://github.com/xorcare/testing-go-code-with-postgres.git synced 2025-06-30 23:23:40 +02:00

Migrate to sql.DB driver

This is to reduce dependency on a particular driver. In the future this
will be used to implement different ways of cleaning the database.
This commit is contained in:
Vasiliy Vasilyuk
2024-02-17 16:38:16 +03:00
parent 883c9e0805
commit 912e9c9ab0
5 changed files with 30 additions and 32 deletions

View File

@ -1,4 +1,4 @@
// Copyright (c) 2023 Vasiliy Vasilyuk. All rights reserved.
// Copyright (c) 2023-2024 Vasiliy Vasilyuk. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
@ -50,7 +50,7 @@ func TestNewPostgres(t *testing.T) {
// Act
var version string
err := postgres.PgxPool().QueryRow(ctx, "SELECT version();").Scan(&version)
err := postgres.DB().QueryRowContext(ctx, "SELECT version();").Scan(&version)
// Assert
require.NoError(t, err)
@ -70,8 +70,8 @@ func TestNewPostgres(t *testing.T) {
// Act
const sql = `CREATE TABLE "no_conflict" (id integer PRIMARY KEY)`
_, err1 := postgres1.PgxPool().Exec(ctx, sql)
_, err2 := postgres2.PgxPool().Exec(ctx, sql)
_, err1 := postgres1.DB().ExecContext(ctx, sql)
_, err2 := postgres2.DB().ExecContext(ctx, sql)
// Assert
require.NoError(t, err1)