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
|
package util
import (
"github.com/mongodb/mongo-tools/common/testutil"
. "github.com/smartystreets/goconvey/convey"
"testing"
)
func TestCreateConnectionAddrs(t *testing.T) {
testutil.VerifyTestType(t, "unit")
Convey("When creating the slice of connection addresses", t, func() {
Convey("if no port is specified, the addresses should all appear"+
" unmodified in the result", func() {
addrs := CreateConnectionAddrs("host1,host2", "")
So(addrs, ShouldResemble, []string{"host1", "host2"})
})
Convey("if a port is specified, it should be appended to each host"+
" from the host connection string", func() {
addrs := CreateConnectionAddrs("host1,host2", "20000")
So(addrs, ShouldResemble, []string{"host1:20000", "host2:20000"})
})
})
}
func TestParseHost(t *testing.T) {
testutil.VerifyTestType(t, "unit")
Convey("When parsing a host string into the contained"+
" addresses", t, func() {
Convey("a string with a single hostname should return a slice of just"+
" the hostname", func() {
addrs := parseHost("localhost")
So(addrs, ShouldResemble, []string{"localhost"})
})
Convey("a string with multiple hostnames should return a slice of"+
" all of them", func() {
addrs := parseHost("host1,host2,host3")
So(addrs, ShouldResemble, []string{"host1", "host2", "host3"})
})
Convey("a string with multiple hostnames and a replica set should"+
" return a slice of all the host names", func() {
addrs := parseHost("foo/host1,host2,host3")
So(addrs, ShouldResemble, []string{"host1", "host2", "host3"})
})
})
}
|