-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopts_test.go
More file actions
122 lines (102 loc) · 2.62 KB
/
opts_test.go
File metadata and controls
122 lines (102 loc) · 2.62 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package pg
import (
"testing"
// Packages
"github.com/stretchr/testify/assert"
)
func Test_Opts_001(t *testing.T) {
assert := assert.New(t)
// Empty options
o, err := apply()
if assert.NoError(err) {
assert.NotNil(o)
}
}
func Test_Opts_002(t *testing.T) {
assert := assert.New(t)
// Empty options
o, err := apply()
if assert.NoError(err) {
assert.NotNil(o)
assert.Equal("host=localhost pool_max_conns=10 port=5432", o.Encode())
}
}
func Test_Opts_003(t *testing.T) {
assert := assert.New(t)
// Host/Port
o, err := apply(
WithHostPort("host", "999"),
)
if assert.NoError(err) {
assert.NotNil(o)
assert.Equal("host=host pool_max_conns=10 port=999", o.Encode())
}
}
func Test_Opts_004(t *testing.T) {
assert := assert.New(t)
// Host/Port
o, err := apply(
WithCredentials("user", "password"),
)
if assert.NoError(err) {
assert.NotNil(o)
assert.Equal("dbname=user host=localhost password=password pool_max_conns=10 port=5432 user=user", o.Encode())
}
}
func Test_Opts_005(t *testing.T) {
assert := assert.New(t)
// Host/Port
o, err := apply(
WithCredentials("user", "password"),
WithDatabase("db"),
WithHostPort("host", "999"),
)
if assert.NoError(err) {
assert.NotNil(o)
assert.Equal("dbname=db host=host password=password pool_max_conns=10 port=999 user=user", o.Encode())
}
}
func Test_Opts_006(t *testing.T) {
assert := assert.New(t)
// Host/Port
o, err := apply(
WithSSLMode("disable"),
)
if assert.NoError(err) {
assert.NotNil(o)
assert.Equal("host=localhost pool_max_conns=10 port=5432 sslmode=disable", o.Encode())
}
}
func Test_Opts_007(t *testing.T) {
assert := assert.New(t)
// WithPassword sets password without affecting other fields
o, err := apply(
WithPassword("secret"),
)
if assert.NoError(err) {
assert.Equal("host=localhost password=secret pool_max_conns=10 port=5432", o.Encode())
}
}
func Test_Opts_008(t *testing.T) {
assert := assert.New(t)
// WithPassword overrides a password already set by WithCredentials
o, err := apply(
WithCredentials("user", "original"),
WithPassword("override"),
)
if assert.NoError(err) {
// username and dbname from WithCredentials must be preserved
assert.Equal("dbname=user host=localhost password=override pool_max_conns=10 port=5432 user=user", o.Encode())
}
}
func Test_Opts_009(t *testing.T) {
assert := assert.New(t)
// WithPassword with empty string leaves existing password unchanged
o, err := apply(
WithCredentials("user", "original"),
WithPassword(""),
)
if assert.NoError(err) {
assert.Equal("dbname=user host=localhost password=original pool_max_conns=10 port=5432 user=user", o.Encode())
}
}