diff --git a/etcdserver/etcdhttp/client.go b/etcdserver/etcdhttp/client.go index 1c676c031..ce67ac929 100644 --- a/etcdserver/etcdhttp/client.go +++ b/etcdserver/etcdhttp/client.go @@ -541,8 +541,8 @@ func newMemberCollection(ms []*etcdserver.Member) httptypes.MemberCollection { ClientURLs: make([]string, len(m.ClientURLs)), } - copy(m.PeerURLs, tm.PeerURLs) - copy(m.ClientURLs, tm.ClientURLs) + copy(tm.PeerURLs, m.PeerURLs) + copy(tm.ClientURLs, m.ClientURLs) c[i] = tm } diff --git a/etcdserver/etcdhttp/client_test.go b/etcdserver/etcdhttp/client_test.go index 04506a1df..4a5100019 100644 --- a/etcdserver/etcdhttp/client_test.go +++ b/etcdserver/etcdhttp/client_test.go @@ -36,6 +36,7 @@ import ( "github.com/coreos/etcd/Godeps/_workspace/src/github.com/jonboulle/clockwork" etcdErr "github.com/coreos/etcd/error" "github.com/coreos/etcd/etcdserver" + "github.com/coreos/etcd/etcdserver/etcdhttp/httptypes" "github.com/coreos/etcd/etcdserver/etcdserverpb" "github.com/coreos/etcd/raft/raftpb" "github.com/coreos/etcd/store" @@ -561,7 +562,7 @@ func TestServeAdminMembers(t *testing.T) { clusterInfo: cluster, } - wmc := string(`[{"id":"c","name":"","peerURLs":[],"clientURLs":[""]},{"id":"d","name":"","peerURLs":[],"clientURLs":[""]}]`) + wmc := string(`[{"id":"c","name":"","peerURLs":[],"clientURLs":["http://localhost:8080"]},{"id":"d","name":"","peerURLs":[],"clientURLs":["http://localhost:8081"]}]`) tests := []struct { path string @@ -1564,3 +1565,36 @@ func TestTrimPrefix(t *testing.T) { } } } + +func TestNewMemberCollection(t *testing.T) { + fixture := []*etcdserver.Member{ + &etcdserver.Member{ + ID: 12, + Attributes: etcdserver.Attributes{ClientURLs: []string{"http://localhost:8080", "http://localhost:8081"}}, + RaftAttributes: etcdserver.RaftAttributes{PeerURLs: []string{"http://localhost:8082", "http://localhost:8083"}}, + }, + &etcdserver.Member{ + ID: 13, + Attributes: etcdserver.Attributes{ClientURLs: []string{"http://localhost:9090", "http://localhost:9091"}}, + RaftAttributes: etcdserver.RaftAttributes{PeerURLs: []string{"http://localhost:9092", "http://localhost:9093"}}, + }, + } + got := newMemberCollection(fixture) + + want := httptypes.MemberCollection([]httptypes.Member{ + httptypes.Member{ + ID: "c", + ClientURLs: []string{"http://localhost:8080", "http://localhost:8081"}, + PeerURLs: []string{"http://localhost:8082", "http://localhost:8083"}, + }, + httptypes.Member{ + ID: "d", + ClientURLs: []string{"http://localhost:9090", "http://localhost:9091"}, + PeerURLs: []string{"http://localhost:9092", "http://localhost:9093"}, + }, + }) + + if !reflect.DeepEqual(want, got) { + t.Fatalf("newMemberCollection failure: want=%#v, got=%#v", want, got) + } +}