Some checks failed
CI / Run lints and checks (push) Failing after 47s
CI / Run tests (push) Failing after 1s
CI / Run race tests (push) Failing after 5s
CI / Build CLI docs (push) Has been skipped
CI / Run buf actions (push) Failing after 5s
CodeQL / Analyze (go) (push) Failing after 3s
CodeQL / Analyze (javascript) (push) Failing after 2s
Docker Image Scanners / scanners (push) Failing after 3s
Format / format (push) Failing after 3s
Synchronize Issue Labels / Synchronize Issue Labels (push) Has been skipped
CI / Generate release (push) Has been skipped
CI / Draft newsletter (push) Has been skipped
CI / Pending approval Slack notification (push) Has been skipped
CI / Send newsletter (push) Has been skipped
65 lines
1.6 KiB
Go
65 lines
1.6 KiB
Go
// Copyright © 2023 Ory Corp
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package dbx
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/ory/pop/v6"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
//nolint:gosec // Test DSNs with dummy credentials, not real secrets.
|
|
func Test_withDbName(t *testing.T) {
|
|
type args struct {
|
|
dsn string
|
|
db string
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want string
|
|
}{{
|
|
name: "postgres",
|
|
args: args{
|
|
dsn: "postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable",
|
|
db: "mydb",
|
|
},
|
|
want: "postgres://postgres:postgres@localhost:5432/mydb?sslmode=disable",
|
|
}, {
|
|
name: "cockroach",
|
|
args: args{
|
|
dsn: "cockroach://root@localhost:49364/defaultdb?sslmode=disable",
|
|
db: "foo",
|
|
},
|
|
want: "cockroach://root@localhost:49364/foo?sslmode=disable",
|
|
}, {
|
|
name: "mysql",
|
|
args: args{
|
|
dsn: "mysql://root:secret@(localhost:49394)/mysql?parseTime=true&multiStatements=true",
|
|
db: "testdb",
|
|
},
|
|
want: "mysql://root:secret@tcp(localhost:49394)/testdb?multiStatements=true&parseTime=true",
|
|
}}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
assert.Equal(t, tt.want, withDbName(tt.args.dsn, tt.args.db))
|
|
})
|
|
}
|
|
}
|
|
|
|
func Test_GetDSNs_can_connect_to_each_db(t *testing.T) {
|
|
for _, db := range GetDSNs(t) {
|
|
t.Run("dsn="+db.Name, func(t *testing.T) {
|
|
t.Parallel()
|
|
conn, err := pop.NewConnection(&pop.ConnectionDetails{URL: db.Conn})
|
|
require.NoError(t, err)
|
|
assert.NoError(t, conn.Open())
|
|
assert.NoError(t, Ping(conn))
|
|
assert.NoError(t, conn.Close())
|
|
})
|
|
}
|
|
}
|