-
-
Notifications
You must be signed in to change notification settings - Fork 201
/
config_test.go
83 lines (76 loc) · 2.01 KB
/
config_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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package pgdriver_test
import (
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/uptrace/bun/driver/pgdriver"
)
func TestParseDSN(t *testing.T) {
type Test struct {
dsn string
cfg *pgdriver.Config
}
tests := []Test{
{
dsn: "postgres://postgres:1@localhost:5432/testDatabase?sslmode=disable",
cfg: &pgdriver.Config{
Network: "tcp",
Addr: "localhost:5432",
User: "postgres",
Password: "1",
Database: "testDatabase",
DialTimeout: 5 * time.Second,
ReadTimeout: 10 * time.Second,
WriteTimeout: 5 * time.Second,
},
},
{
dsn: "postgres://postgres:1@localhost:5432/testDatabase?sslmode=disable&dial_timeout=1&read_timeout=2s&write_timeout=3",
cfg: &pgdriver.Config{
Network: "tcp",
Addr: "localhost:5432",
User: "postgres",
Password: "1",
Database: "testDatabase",
DialTimeout: 1 * time.Second,
ReadTimeout: 2 * time.Second,
WriteTimeout: 3 * time.Second,
},
},
{
dsn: "postgres://postgres:1@localhost:5432/testDatabase?search_path=foo",
cfg: &pgdriver.Config{
Network: "tcp",
Addr: "localhost:5432",
User: "postgres",
Password: "1",
Database: "testDatabase",
ConnParams: map[string]interface{}{
"search_path": "foo",
},
DialTimeout: 5 * time.Second,
ReadTimeout: 10 * time.Second,
WriteTimeout: 5 * time.Second,
},
},
{
dsn: "postgres://postgres:password@app.xxx.us-east-1.rds.amazonaws.com:5432/test?sslmode=disable",
cfg: &pgdriver.Config{
Network: "tcp",
Addr: "app.xxx.us-east-1.rds.amazonaws.com:5432",
User: "postgres",
Password: "password",
Database: "test",
DialTimeout: 5 * time.Second,
ReadTimeout: 10 * time.Second,
WriteTimeout: 5 * time.Second,
},
},
}
for _, test := range tests {
c := pgdriver.NewConnector(pgdriver.WithDSN(test.dsn))
cfg := c.Config()
cfg.Dialer = nil
require.Equal(t, test.cfg, cfg)
}
}