mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
etcdserver: add Peers.Addrs
This commit is contained in:
parent
b94d0281d4
commit
99e9f561ee
@ -85,6 +85,19 @@ func (ps Peers) Endpoints() []string {
|
||||
return endpoints
|
||||
}
|
||||
|
||||
// Addrs returns a list of all peer addresses. The returned list is sorted
|
||||
// in ascending lexicographical order.
|
||||
func (ps Peers) Addrs() []string {
|
||||
addrs := make([]string, 0)
|
||||
for _, paddrs := range ps {
|
||||
for _, paddr := range paddrs {
|
||||
addrs = append(addrs, paddr)
|
||||
}
|
||||
}
|
||||
sort.Strings(addrs)
|
||||
return addrs
|
||||
}
|
||||
|
||||
func Sender(t *http.Transport, p Peers) func(msgs []raftpb.Message) {
|
||||
c := &http.Client{Transport: t}
|
||||
|
||||
|
@ -16,24 +16,28 @@ func TestPeers(t *testing.T) {
|
||||
in string
|
||||
wids []int64
|
||||
wep []string
|
||||
waddrs []string
|
||||
wstring string
|
||||
}{
|
||||
{
|
||||
"1=1.1.1.1",
|
||||
[]int64{1},
|
||||
[]string{"http://1.1.1.1"},
|
||||
[]string{"1.1.1.1"},
|
||||
"1=1.1.1.1",
|
||||
},
|
||||
{
|
||||
"2=2.2.2.2",
|
||||
[]int64{2},
|
||||
[]string{"http://2.2.2.2"},
|
||||
[]string{"2.2.2.2"},
|
||||
"2=2.2.2.2",
|
||||
},
|
||||
{
|
||||
"1=1.1.1.1&1=1.1.1.2&2=2.2.2.2",
|
||||
[]int64{1, 2},
|
||||
[]string{"http://1.1.1.1", "http://1.1.1.2", "http://2.2.2.2"},
|
||||
[]string{"1.1.1.1", "1.1.1.2", "2.2.2.2"},
|
||||
"1=1.1.1.1&1=1.1.1.2&2=2.2.2.2",
|
||||
},
|
||||
{
|
||||
@ -41,6 +45,7 @@ func TestPeers(t *testing.T) {
|
||||
[]int64{1, 2, 3, 4},
|
||||
[]string{"http://1.1.1.1", "http://1.1.1.2", "http://2.2.2.2",
|
||||
"http://3.3.3.3", "http://4.4.4.4"},
|
||||
[]string{"1.1.1.1", "1.1.1.2", "2.2.2.2", "3.3.3.3", "4.4.4.4"},
|
||||
"1=1.1.1.1&1=1.1.1.2&2=2.2.2.2&3=3.3.3.3&4=4.4.4.4",
|
||||
},
|
||||
}
|
||||
@ -59,6 +64,10 @@ func TestPeers(t *testing.T) {
|
||||
if !reflect.DeepEqual(ep, tt.wep) {
|
||||
t.Errorf("#%d: Endpoints=%#v, want %#v", i, ep, tt.wep)
|
||||
}
|
||||
addrs := p.Addrs()
|
||||
if !reflect.DeepEqual(addrs, tt.waddrs) {
|
||||
t.Errorf("#%d: addrs=%#v, want %#v", i, ep, tt.waddrs)
|
||||
}
|
||||
s := p.String()
|
||||
if s != tt.wstring {
|
||||
t.Errorf("#%d: string=%q, want %q", i, s, tt.wstring)
|
||||
|
Loading…
x
Reference in New Issue
Block a user