Browse Source

etcdhttp: copy Member URLs properly

Brian Waldon 11 years ago
parent
commit
8d052dd374
2 changed files with 37 additions and 3 deletions
  1. 2 2
      etcdserver/etcdhttp/client.go
  2. 35 1
      etcdserver/etcdhttp/client_test.go

+ 2 - 2
etcdserver/etcdhttp/client.go

@@ -540,8 +540,8 @@ func newMemberCollection(ms []*etcdserver.Member) httptypes.MemberCollection {
 			ClientURLs: make([]string, len(m.ClientURLs)),
 			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
 		c[i] = tm
 	}
 	}

+ 35 - 1
etcdserver/etcdhttp/client_test.go

@@ -36,6 +36,7 @@ import (
 	"github.com/coreos/etcd/Godeps/_workspace/src/github.com/jonboulle/clockwork"
 	"github.com/coreos/etcd/Godeps/_workspace/src/github.com/jonboulle/clockwork"
 	etcdErr "github.com/coreos/etcd/error"
 	etcdErr "github.com/coreos/etcd/error"
 	"github.com/coreos/etcd/etcdserver"
 	"github.com/coreos/etcd/etcdserver"
+	"github.com/coreos/etcd/etcdserver/etcdhttp/httptypes"
 	"github.com/coreos/etcd/etcdserver/etcdserverpb"
 	"github.com/coreos/etcd/etcdserver/etcdserverpb"
 	"github.com/coreos/etcd/raft/raftpb"
 	"github.com/coreos/etcd/raft/raftpb"
 	"github.com/coreos/etcd/store"
 	"github.com/coreos/etcd/store"
@@ -561,7 +562,7 @@ func TestServeAdminMembers(t *testing.T) {
 		clusterInfo: cluster,
 		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 {
 	tests := []struct {
 		path  string
 		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)
+	}
+}