Skip to content

Commit

Permalink
refactor(storage): move from lib/pq to pgx (#2996)
Browse files Browse the repository at this point in the history
* refactor(storage): move from lib/pq to pgx

Signed-off-by: Roman Dmytrenko <[email protected]>

* ignore golang mock files by codecov

Signed-off-by: Roman Dmytrenko <[email protected]>

* address PR feedback

Signed-off-by: Roman Dmytrenko <[email protected]>

---------

Signed-off-by: Roman Dmytrenko <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
erka and kodiakhq[bot] authored Apr 23, 2024
1 parent 722e0bf commit a2d18fc
Show file tree
Hide file tree
Showing 13 changed files with 356 additions and 53 deletions.
1 change: 1 addition & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ ignore:
- "rpc/flipt/flipt.pb.*"
- "rpc/flipt/meta"
- "ui"
- "**/mock_*.go"
7 changes: 6 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ require (
github.com/hashicorp/cap v0.6.0
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/golang-lru/v2 v2.0.7
github.com/lib/pq v1.10.9
github.com/jackc/pgx/v5 v5.5.5
github.com/libsql/libsql-client-go v0.0.0-20230917132930-48c310b27e7b
github.com/magefile/mage v1.15.0
github.com/mattn/go-sqlite3 v1.14.22
Expand Down Expand Up @@ -175,6 +175,10 @@ require (
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
Expand All @@ -183,6 +187,7 @@ require (
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/libsql/sqlite-antlr4-parser v0.0.0-20230802215326-5cb5bb604475 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
Expand Down
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,11 @@ github.com/jackc/pgconn v1.4.0/go.mod h1:Y2O3ZDF0q4mMacyWV3AstPJpeHXWGEetiFttmq5
github.com/jackc/pgconn v1.5.0/go.mod h1:QeD3lBfpTFe8WUnPZWN5KY/mB8FGMIYRdd8P8Jr0fAI=
github.com/jackc/pgconn v1.5.1-0.20200601181101-fa742c524853/go.mod h1:QeD3lBfpTFe8WUnPZWN5KY/mB8FGMIYRdd8P8Jr0fAI=
github.com/jackc/pgconn v1.8.0/go.mod h1:1C2Pb36bGIP9QHGBYCjnyhqu7Rv3sGshaQUvmfGIB/o=
github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa h1:s+4MhCQ6YrzisK6hFJUX53drDT4UsSW3DEhKn0ifuHw=
github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa/go.mod h1:a/s9Lp5W7n/DD0VrVoyJ00FbP2ytTPDVOivvn2bMlds=
github.com/jackc/pgio v1.0.0/go.mod h1:oP+2QK2wFfUWgr+gxjoBH9KGBb31Eio69xUb0w5bYf8=
github.com/jackc/pgmock v0.0.0-20190831213851-13a1b77aafa2/go.mod h1:fGZlG77KXmcq05nJLRkk0+p82V8B8Dw8KN2/V9c/OAE=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgproto3 v1.1.0/go.mod h1:eR5FA3leWg7p9aeAqi37XOTgTIbkABlvcPB3E5rlc78=
github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190420180111-c116219b62db/go.mod h1:bhq50y+xrl9n5mRYyCBFKkpRVTLYJVWeCc+mEAI3yXA=
Expand All @@ -407,6 +410,8 @@ github.com/jackc/pgproto3/v2 v2.0.1/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwX
github.com/jackc/pgproto3/v2 v2.0.6/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
github.com/jackc/pgservicefile v0.0.0-20200307190119-3430c5407db8/go.mod h1:vsD4gTJCa9TptPL8sPkXrLZ+hDuNrZCnj29CQpr4X1E=
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b/go.mod h1:vsD4gTJCa9TptPL8sPkXrLZ+hDuNrZCnj29CQpr4X1E=
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
github.com/jackc/pgtype v0.0.0-20190421001408-4ed0de4755e0/go.mod h1:hdSHsc1V01CGwFsrv11mJRHWJ6aifDLfdV3aVjFF0zg=
github.com/jackc/pgtype v0.0.0-20190824184912-ab885b375b90/go.mod h1:KcahbBH1nCMSo2DXpzsoWOAfFkdEtEJpPbVLq8eE+mc=
github.com/jackc/pgtype v0.0.0-20190828014616-a8802b16cc59/go.mod h1:MWlu30kVJrUS8lot6TQqcg7mtthZ9T0EoIBFiJcmcyw=
Expand All @@ -421,11 +426,15 @@ github.com/jackc/pgx/v4 v4.5.0/go.mod h1:EpAKPLdnTorwmPUUsqrPxy5fphV18j9q3wrfRXg
github.com/jackc/pgx/v4 v4.6.1-0.20200510190926-94ba730bb1e9/go.mod h1:t3/cdRQl6fOLDxqtlyhe9UWgfIi9R8+8v8GKV5TRA/o=
github.com/jackc/pgx/v4 v4.6.1-0.20200606145419-4e5062306904/go.mod h1:ZDaNWkt9sW1JMiNn0kdYBaLelIhw7Pg4qd+Vk6tw7Hg=
github.com/jackc/pgx/v4 v4.10.1/go.mod h1:QlrWebbs3kqEZPHCTGyxecvzG6tvIsYu+A5b1raylkA=
github.com/jackc/pgx/v5 v5.5.5 h1:amBjrZVmksIdNjxGW/IiIMzxMKZFelXbUoPNb+8sjQw=
github.com/jackc/pgx/v5 v5.5.5/go.mod h1:ez9gk+OAat140fv9ErkZDYFWmXLfV+++K0uAOiwgm1A=
github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle v1.1.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle v1.1.1/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk=
github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
Expand Down
16 changes: 11 additions & 5 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -657,14 +657,21 @@ github.com/intel/goresctrl v0.2.0/go.mod h1:+CZdzouYFn5EsxgqAQTEzMfwKwuc0fVdMrT9
github.com/intel/goresctrl v0.3.0/go.mod h1:fdz3mD85cmP9sHD8JUlrNWAxvwM86CrbmVXltEKd7zk=
github.com/j-keck/arping v0.0.0-20160618110441-2cf9dc699c56/go.mod h1:ymszkNOg6tORTn+6F6j+Jc8TOr5osrynvN6ivFWZ2GA=
github.com/j-keck/arping v1.0.2/go.mod h1:aJbELhR92bSk7tp79AWM/ftfc90EfEi2bQJrbBFOsPw=
github.com/jackc/chunkreader v1.0.0 h1:4s39bBR8ByfqH+DKm8rQA3E1LHZWB9XWcrz8fqaZbe0=
github.com/jackc/chunkreader/v2 v2.0.1 h1:i+RDz65UE+mmpjTfyz0MoVTnzeYxroil2G82ki7MGG8=
github.com/jackc/pgconn v1.14.0 h1:vrbA9Ud87g6JdFWkHTJXppVce58qPIdP7N8y0Ml/A7Q=
github.com/jackc/pgconn v1.14.0/go.mod h1:9mBNlny0UvkgJdCDvdVHYSjI+8tD2rnKK69Wz8ti++E=
github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa/go.mod h1:a/s9Lp5W7n/DD0VrVoyJ00FbP2ytTPDVOivvn2bMlds=
github.com/jackc/pgio v1.0.0 h1:g12B9UwVnzGhueNavwioyEEpAmqMe1E/BN9ES+8ovkE=
github.com/jackc/pgmock v0.0.0-20190831213851-13a1b77aafa2 h1:JVX6jT/XfzNqIjye4717ITLaNwV9mWbJx0dLCpcRzdA=
github.com/jackc/pgproto3 v1.1.0 h1:FYYE4yRw+AgI8wXIinMlNjBbp/UitDJwfj5LqqewP1A=
github.com/jackc/pgproto3/v2 v2.3.2 h1:7eY55bdBeCz1F2fTzSz69QC+pG46jYq9/jtSPiJ5nn0=
github.com/jackc/pgproto3/v2 v2.3.2/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
github.com/jackc/pgtype v1.14.0 h1:y+xUdabmyMkJLyApYuPj38mW+aAIqCe5uuBB51rH3Vw=
github.com/jackc/pgtype v1.14.0/go.mod h1:LUMuVrfsFfdKGLw+AFFVv6KtHOFMwRgDDzBt76IqCA4=
github.com/jackc/pgx/v4 v4.18.1 h1:YP7G1KABtKpB5IHrO9vYwSrCOhs7p3uqhvhhQBptya0=
github.com/jackc/pgx/v4 v4.18.1/go.mod h1:FydWkUyadDmdNH/mHnGob881GawxeEm7TcMCzkb+qQE=
github.com/jackc/pgx/v5 v5.3.1/go.mod h1:t3JDKnCBlYIc0ewLF0Q7B8MXmoIaBOZj/ic7iHozM/8=
github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/jackc/puddle v1.1.3 h1:JnPg/5Q9xVJGfjsO5CPUOjnJps1JaRUm8I9FXVCFK94=
github.com/jackc/puddle v1.3.0 h1:eHK/5clGOatcjX3oWGBO/MpxpbHzSwud5EWTSCI+MX0=
github.com/jcmturner/aescts/v2 v2.0.0/go.mod h1:AiaICIRyfYg35RUkr8yESTqvSy7csK90qZ5xfvvsoNs=
github.com/jcmturner/dnsutils/v2 v2.0.0/go.mod h1:b0TnjGOvI/n42bZa+hmXL+kFJZsFT7G4t3HTlQ184QM=
github.com/jcmturner/gofork v1.7.6/go.mod h1:1622LH6i/EZqLloHfE7IeZ0uEJwMSUyQ/nDd82IeqRo=
Expand Down Expand Up @@ -1179,7 +1186,6 @@ golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
Expand Down
64 changes: 64 additions & 0 deletions internal/storage/sql/adapted_driver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package sql

import (
"context"
"database/sql/driver"
"time"

pgx "github.com/jackc/pgx/v5/stdlib"
)

const adaptedDriverOpenTimeout = 60 * time.Second

// This is the wrapper around sql driver. By default, pgx driver returns connection
// error with the host, username and password. `adaptedDriver` and `postgresConnector`
// allow to customize errors and preventing leakage of the credentials to outside.
func newAdaptedPostgresDriver(d Driver) driver.Driver {
return &adaptedDriver{origin: &pgx.Driver{}, adapter: d}
}

var _ driver.Driver = (*adaptedDriver)(nil)
var _ driver.DriverContext = (*adaptedDriver)(nil)

type adaptedDriver struct {
adapter Driver
origin driver.DriverContext
}

func (d *adaptedDriver) Open(name string) (driver.Conn, error) {
connector, err := d.OpenConnector(name)
if err != nil {
return nil, d.adapter.AdaptError(err)
}
ctx, cancel := context.WithTimeout(context.Background(), adaptedDriverOpenTimeout)
defer cancel()
return connector.Connect(ctx)
}

func (d *adaptedDriver) OpenConnector(name string) (driver.Connector, error) {
connector, err := d.origin.OpenConnector(name)
if err != nil {
return nil, d.adapter.AdaptError(err)
}
return &adaptedConnector{origin: connector, driver: d, adapter: d.adapter}, nil
}

var _ driver.Connector = (*adaptedConnector)(nil)

type adaptedConnector struct {
origin driver.Connector
driver driver.Driver
adapter Driver
}

func (c *adaptedConnector) Driver() driver.Driver {
return c.driver
}

func (c *adaptedConnector) Connect(ctx context.Context) (driver.Conn, error) {
conn, err := c.origin.Connect(ctx)
if err != nil {
return nil, c.adapter.AdaptError(err)
}
return conn, nil
}
61 changes: 61 additions & 0 deletions internal/storage/sql/adapted_driver_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package sql

import (
"context"

"testing"

"github.com/jackc/pgx/v5/pgconn"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)

func TestAdaptedDriver(t *testing.T) {
mockDriver := NewMockDriverContext(t)
t.Run("failure", func(t *testing.T) {
name := "pgx://failure"
mockDriver.On("OpenConnector", name).Return(nil, &pgconn.PgError{})
d := &adaptedDriver{origin: mockDriver, adapter: Postgres}
_, err := d.Open(name)
require.Error(t, err)
})
t.Run("success", func(t *testing.T) {
o := newMockConnector(t)
var mockConn = &mockDriverConn{}
o.On("Connect", mock.Anything).Once().Return(mockConn, nil)
name := "pgx://success"
mockDriver.On("OpenConnector", name).Return(o, nil)
d := &adaptedDriver{origin: mockDriver, adapter: Postgres}
conn, err := d.Open(name)
require.NoError(t, err)
require.Equal(t, mockConn, conn)
})
}

func TestAdaptedConnectorConnect(t *testing.T) {
o := newMockConnector(t)
d := &adaptedDriver{}
c := &adaptedConnector{
origin: o,
adapter: Postgres,
driver: d,
}
require.Equal(t, d, c.Driver())
t.Run("failure", func(t *testing.T) {
var mockConn *mockDriverConn
ctx := context.Background()
o.On("Connect", ctx).Once().Return(mockConn, &pgconn.ConnectError{})
_, err := c.Connect(ctx)
require.Error(t, err)
require.Equal(t, err, errConnectionFailed)
})

t.Run("success", func(t *testing.T) {
var mockConn = &mockDriverConn{}
ctx := context.Background()
o.On("Connect", ctx).Once().Return(mockConn, nil)
conn, err := c.Connect(ctx)
require.NoError(t, err)
require.Equal(t, mockConn, conn)
})
}
11 changes: 7 additions & 4 deletions internal/storage/sql/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
sq "github.com/Masterminds/squirrel"
"github.com/XSAM/otelsql"
"github.com/go-sql-driver/mysql"
"github.com/lib/pq"

"github.com/libsql/libsql-client-go/libsql"
"github.com/mattn/go-sqlite3"
"github.com/xo/dburl"
Expand Down Expand Up @@ -49,6 +49,9 @@ func init() {
Aliases: []string{"libsql", "http", "https"},
Override: "file",
})
// drop references to lib/pq and relay on pgx
dburl.Unregister("postgres")
dburl.RegisterAlias("pgx", "postgres")
}

// Open opens a connection to the db
Expand Down Expand Up @@ -123,10 +126,10 @@ func open(cfg config.Config, opts Options) (*sql.DB, Driver, error) {
dr = &libsql.Driver{}
attrs = []attribute.KeyValue{semconv.DBSystemSqlite}
case Postgres:
dr = &pq.Driver{}
dr = newAdaptedPostgresDriver(d)
attrs = []attribute.KeyValue{semconv.DBSystemPostgreSQL}
case CockroachDB:
dr = &pq.Driver{}
dr = newAdaptedPostgresDriver(d)
attrs = []attribute.KeyValue{semconv.DBSystemCockroachdb}
case MySQL:
dr = &mysql.MySQLDriver{}
Expand Down Expand Up @@ -203,7 +206,7 @@ var (
stringToDriver = map[string]Driver{
"sqlite3": SQLite,
"libsql": LibSQL,
"postgres": Postgres,
"pgx": Postgres,
"mysql": MySQL,
"cockroachdb": CockroachDB,
"clickhouse": Clickhouse,
Expand Down
23 changes: 16 additions & 7 deletions internal/storage/sql/db_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,23 @@ func TestParse(t *testing.T) {
PreparedStatementsEnabled: true,
},
driver: Postgres,
dsn: "dbname=flipt host=localhost port=5432 sslmode=disable user=postgres",
dsn: "postgres://postgres@localhost:5432/flipt?sslmode=disable",
},
{
name: "postgres url",
cfg: config.DatabaseConfig{
URL: "postgres://postgres@localhost:5432/flipt?sslmode=disable",
},
driver: Postgres,
dsn: "binary_parameters=yes dbname=flipt host=localhost port=5432 sslmode=disable user=postgres",
dsn: "postgres://postgres@localhost:5432/flipt?binary_parameters=yes&sslmode=disable",
},
{
name: "postgres no disable sslmode",
cfg: config.DatabaseConfig{
URL: "postgres://postgres@localhost:5432/flipt",
},
driver: Postgres,
dsn: "binary_parameters=yes dbname=flipt host=localhost port=5432 user=postgres",
dsn: "postgres://postgres@localhost:5432/flipt?binary_parameters=yes",
},
{
name: "postgres disable sslmode via opts",
Expand All @@ -70,7 +70,7 @@ func TestParse(t *testing.T) {
},
options: []Option{WithSSLDisabled},
driver: Postgres,
dsn: "binary_parameters=yes dbname=flipt host=localhost port=5432 sslmode=disable user=postgres",
dsn: "postgres://postgres@localhost:5432/flipt?binary_parameters=yes&sslmode=disable",
},
{
name: "postgres no port",
Expand All @@ -81,7 +81,7 @@ func TestParse(t *testing.T) {
User: "postgres",
},
driver: Postgres,
dsn: "binary_parameters=yes dbname=flipt host=localhost user=postgres",
dsn: "postgres://postgres@localhost:5432/flipt?binary_parameters=yes",
},
{
name: "postgres no password",
Expand All @@ -93,7 +93,7 @@ func TestParse(t *testing.T) {
User: "postgres",
},
driver: Postgres,
dsn: "binary_parameters=yes dbname=flipt host=localhost port=5432 user=postgres",
dsn: "postgres://postgres@localhost:5432/flipt?binary_parameters=yes",
},
{
name: "postgres with password",
Expand All @@ -106,7 +106,7 @@ func TestParse(t *testing.T) {
Password: "foo",
},
driver: Postgres,
dsn: "binary_parameters=yes dbname=flipt host=localhost password=foo port=5432 user=postgres",
dsn: "postgres://postgres:foo@localhost:5432/flipt?binary_parameters=yes",
},
{
name: "mysql url",
Expand Down Expand Up @@ -276,6 +276,15 @@ func TestParse(t *testing.T) {
},
wantErr: true,
},
{
name: "postgres multi hosts url",
cfg: config.DatabaseConfig{
URL: "postgres://user:pass@host1:5432,host2:2345/flipt?application_name=flipt&target_session_attrs=primary",
PreparedStatementsEnabled: false,
},
driver: Postgres,
dsn: "postgres://user:pass@host1:5432,host2:2345/flipt?application_name=flipt&binary_parameters=yes&target_session_attrs=primary",
},
}

for _, tt := range tests {
Expand Down
Loading

0 comments on commit a2d18fc

Please sign in to comment.