sqldb: merge SQLite and Postgres configs with the kvdb counterparts

This commit is part of a refactor that unifies configuration of the
sqldb and kvdb packages for SQL backends.
In order to unify the SQLite and Postgres configuration under sqldb we
first need to ensure that the final config types are compatible with
the alreay deployed versions.
This commit is contained in:
Andras Banki-Horvath
2023-12-06 16:31:25 +01:00
parent aee1f7f563
commit aba45018a8
3 changed files with 86 additions and 70 deletions

View File

@@ -1,7 +1,6 @@
package sqldb
import (
"context"
"database/sql"
"fmt"
"strconv"
@@ -75,7 +74,7 @@ func NewTestPgFixture(t *testing.T, expiry time.Duration) *TestPgFixture {
host: host,
port: int(port),
}
databaseURL := fixture.GetDSN()
databaseURL := fixture.GetConfig(testPgDBName).Dsn
log.Infof("Connecting to Postgres fixture: %v\n", databaseURL)
// Tell docker to hard kill the container in "expiry" seconds.
@@ -104,20 +103,13 @@ func NewTestPgFixture(t *testing.T, expiry time.Duration) *TestPgFixture {
return fixture
}
// GetDSN returns the DSN (Data Source Name) for the started Postgres node.
func (f *TestPgFixture) GetDSN() string {
return f.GetConfig().DSN(false)
}
// GetConfig returns the full config of the Postgres node.
func (f *TestPgFixture) GetConfig() *PostgresConfig {
func (f *TestPgFixture) GetConfig(dbName string) *PostgresConfig {
return &PostgresConfig{
Host: f.host,
Port: f.port,
User: testPgUser,
Password: testPgPass,
DBName: testPgDBName,
RequireSSL: false,
Dsn: fmt.Sprintf(
"postgres://%v:%v@%v:%v/%v?sslmode=disable",
testPgUser, testPgPass, f.host, f.port, dbName,
),
}
}
@@ -126,16 +118,3 @@ func (f *TestPgFixture) TearDown(t *testing.T) {
err := f.pool.Purge(f.resource)
require.NoError(t, err, "Could not purge resource")
}
// ClearDB clears the database.
func (f *TestPgFixture) ClearDB(t *testing.T) {
dbConn, err := sql.Open("postgres", f.GetDSN())
require.NoError(t, err)
_, err = dbConn.ExecContext(
context.Background(),
`DROP SCHEMA IF EXISTS public CASCADE;
CREATE SCHEMA public;`,
)
require.NoError(t, err)
}