/
dsn_test.go
71 lines (68 loc) · 1.59 KB
/
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
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
package etcd
import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"
)
func Test_parseDNS(t *testing.T) {
tests := []struct {
name string
dns string
expectError bool
expectDSN *dsn
}{
{
name: "simple",
dns: "etcd://localhost:2379",
expectError: false,
expectDSN: &dsn{
endpoints: []string{"localhost:2379"},
},
},
{
name: "with user password",
dns: "etcd://username:password@localhost:2379",
expectError: false,
expectDSN: &dsn{
endpoints: []string{"localhost:2379"},
username: "username",
password: "password",
},
},
{
name: "with compression",
dns: "etcd://username:password@localhost:2379?compression=zstd&threshold=64",
expectError: false,
expectDSN: &dsn{
endpoints: []string{"localhost:2379"},
username: "username",
password: "password",
compression: "zstd",
threshold: 64,
},
},
{
name: "multiple endpoints",
dns: "etcd://username:password@localhost:2379,localhost:2380?compression=zstd&threshold=64",
expectError: false,
expectDSN: &dsn{
endpoints: []string{"localhost:2379", "localhost:2380"},
username: "username",
password: "password",
compression: "zstd",
threshold: 64,
},
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
dsn, err := newDSN(test.dns)
if test.expectError {
require.Error(t, err)
} else {
require.NoError(t, err)
assert.Equal(t, test.expectDSN, dsn)
}
})
}
}