-
Notifications
You must be signed in to change notification settings - Fork 11
/
dsn_test.go
43 lines (39 loc) · 902 Bytes
/
dsn_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package otsql
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestGetInstanceFromDSN(t *testing.T) {
fixtures := []struct {
dsn string
instance string
database string
}{
{
// go-sql-driver/mysql
"username:password@protocol(address)/dbname?param=value",
"protocol(address)",
"dbname",
},
{
// jackc/pgx
"postgres://username:password@localhost:5432/database_name",
"localhost:5432",
"database_name",
},
{
// postgresql: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING
"host=localhost port=5432 dbname=mydb connect_timeout=10",
"localhost:5432",
"mydb",
},
}
for _, f := range fixtures {
fixture := f
t.Run(f.dsn, func(t *testing.T) {
instance, database := parseDSN(fixture.dsn)
require.Equal(t, fixture.instance, instance)
require.Equal(t, fixture.database, database)
})
}
}