-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions_test.go
52 lines (38 loc) · 852 Bytes
/
options_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
package clickhouse
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestOptionBaseOptionString(t *testing.T) {
o := WithDatabase("database")
assert.Equal(t, "WithDatabase", o.String())
}
func TestOptionWithCredentials(t *testing.T) {
exp := Credentials{
Database: "db",
User: "user",
Password: "pass",
}
opt := WithCredentials(exp)
opts := []ClientOption{opt}
var res Credentials
for _, o := range opts {
if o, ok := o.(CredentialsOption); ok {
err := o.F(&res)
assert.NoError(t, err)
}
}
assert.Equal(t, exp, res)
}
func TestOptionGetDatabase(t *testing.T) {
opt := WithCredentials(Credentials{
Database: "db0",
User: "user",
Password: "pass",
})
db := GetDatabase(opt)
assert.Equal(t, "db0", db)
opt = WithDatabase("db1")
db = GetDatabase(opt)
assert.Equal(t, "db1", db)
}