-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagent_option_test.go
84 lines (78 loc) · 2.46 KB
/
agent_option_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
84
package zongzi
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestWithApiAddress(t *testing.T) {
t.Run(`withBind`, func(t *testing.T) {
a, err := NewAgent(`test001`, nil)
require.Nil(t, err)
o := WithApiAddress(`127.0.0.1:80000`)
o(a)
assert.Equal(t, `127.0.0.1:80000`, a.advertiseAddress)
assert.Equal(t, `0.0.0.0:80000`, a.bindAddress)
})
t.Run(`withoutBind`, func(t *testing.T) {
a, err := NewAgent(`test001`, nil)
require.Nil(t, err)
o := WithApiAddress(`127.0.0.1:80001`, `127.0.0.1:80002`)
o(a)
assert.Equal(t, `127.0.0.1:80001`, a.advertiseAddress)
assert.Equal(t, `127.0.0.1:80002`, a.bindAddress)
})
}
func TestWithGossipAddress(t *testing.T) {
t.Run(`with-bind`, func(t *testing.T) {
a, err := NewAgent(`test001`, nil)
require.Nil(t, err)
o := WithGossipAddress(`127.0.0.1:80000`)
o(a)
assert.Equal(t, `127.0.0.1:80000`, a.hostConfig.Gossip.AdvertiseAddress)
assert.Equal(t, `0.0.0.0:80000`, a.hostConfig.Gossip.BindAddress)
})
t.Run(`without-bind`, func(t *testing.T) {
a, err := NewAgent(`test001`, nil)
require.Nil(t, err)
o := WithGossipAddress(`127.0.0.1:80001`, `127.0.0.1:80002`)
o(a)
assert.Equal(t, `127.0.0.1:80001`, a.hostConfig.Gossip.AdvertiseAddress)
assert.Equal(t, `127.0.0.1:80002`, a.hostConfig.Gossip.BindAddress)
})
}
func TestWithHostConfig(t *testing.T) {
t.Run(`gossip`, func(t *testing.T) {
a, err := NewAgent(`test001`, nil)
require.Nil(t, err)
a.hostConfig.Gossip.Meta = []byte(`test1`)
o := WithHostConfig(HostConfig{
Gossip: GossipConfig{
AdvertiseAddress: `127.0.0.1:80001`,
BindAddress: `127.0.0.1:80002`,
},
})
o(a)
assert.Equal(t, `127.0.0.1:80001`, string(a.hostConfig.Gossip.AdvertiseAddress))
assert.Equal(t, `127.0.0.1:80002`, string(a.hostConfig.Gossip.BindAddress))
})
t.Run(`no-gossip`, func(t *testing.T) {
a, err := NewAgent(`test001`, nil)
require.Nil(t, err)
aa := a.hostConfig.Gossip.AdvertiseAddress
ba := a.hostConfig.Gossip.BindAddress
o := WithHostConfig(HostConfig{})
o(a)
assert.Equal(t, aa, string(a.hostConfig.Gossip.AdvertiseAddress))
assert.Equal(t, ba, string(a.hostConfig.Gossip.BindAddress))
})
}
func TestWithHostTags(t *testing.T) {
t.Run(`success`, func(t *testing.T) {
a, err := NewAgent(`test001`, nil)
require.Nil(t, err)
a.hostConfig.Gossip.Meta = []byte(`test1`)
o := WithHostTags(`test:tag=2`)
o(a)
assert.Equal(t, []string{`test:tag=2`}, a.hostTags)
})
}