|
@@ -27,6 +27,7 @@ import (
|
|
|
"net/url"
|
|
"net/url"
|
|
|
"path"
|
|
"path"
|
|
|
"reflect"
|
|
"reflect"
|
|
|
|
|
+ "strconv"
|
|
|
"strings"
|
|
"strings"
|
|
|
"testing"
|
|
"testing"
|
|
|
"time"
|
|
"time"
|
|
@@ -551,6 +552,7 @@ func TestServeAdminMembers(t *testing.T) {
|
|
|
memb1 := etcdserver.Member{ID: 1, Attributes: etcdserver.Attributes{ClientURLs: []string{"http://localhost:8080"}}}
|
|
memb1 := etcdserver.Member{ID: 1, Attributes: etcdserver.Attributes{ClientURLs: []string{"http://localhost:8080"}}}
|
|
|
memb2 := etcdserver.Member{ID: 2, Attributes: etcdserver.Attributes{ClientURLs: []string{"http://localhost:8081"}}}
|
|
memb2 := etcdserver.Member{ID: 2, Attributes: etcdserver.Attributes{ClientURLs: []string{"http://localhost:8081"}}}
|
|
|
cluster := &fakeCluster{
|
|
cluster := &fakeCluster{
|
|
|
|
|
+ id: 1,
|
|
|
members: map[uint64]*etcdserver.Member{1: &memb1, 2: &memb2},
|
|
members: map[uint64]*etcdserver.Member{1: &memb1, 2: &memb2},
|
|
|
}
|
|
}
|
|
|
h := &adminMembersHandler{
|
|
h := &adminMembersHandler{
|
|
@@ -596,6 +598,11 @@ func TestServeAdminMembers(t *testing.T) {
|
|
|
if gct := rw.Header().Get("Content-Type"); gct != tt.wct {
|
|
if gct := rw.Header().Get("Content-Type"); gct != tt.wct {
|
|
|
t.Errorf("#%d: content-type = %s, want %s", i, gct, tt.wct)
|
|
t.Errorf("#%d: content-type = %s, want %s", i, gct, tt.wct)
|
|
|
}
|
|
}
|
|
|
|
|
+ gcid := rw.Header().Get("X-Etcd-Cluster-ID")
|
|
|
|
|
+ wcid := strconv.FormatUint(cluster.ID(), 16)
|
|
|
|
|
+ if gcid != wcid {
|
|
|
|
|
+ t.Errorf("#%d: cid = %s, want %s", i, gcid, wcid)
|
|
|
|
|
+ }
|
|
|
if rw.Body.String() != tt.wbody {
|
|
if rw.Body.String() != tt.wbody {
|
|
|
t.Errorf("#%d: body = %q, want %q", i, rw.Body.String(), tt.wbody)
|
|
t.Errorf("#%d: body = %q, want %q", i, rw.Body.String(), tt.wbody)
|
|
|
}
|
|
}
|
|
@@ -617,8 +624,9 @@ func TestServeAdminMembersPut(t *testing.T) {
|
|
|
req.Header.Set("Content-Type", "application/json")
|
|
req.Header.Set("Content-Type", "application/json")
|
|
|
s := &serverRecorder{}
|
|
s := &serverRecorder{}
|
|
|
h := &adminMembersHandler{
|
|
h := &adminMembersHandler{
|
|
|
- server: s,
|
|
|
|
|
- clock: clockwork.NewFakeClock(),
|
|
|
|
|
|
|
+ server: s,
|
|
|
|
|
+ clock: clockwork.NewFakeClock(),
|
|
|
|
|
+ clusterInfo: &fakeCluster{id: 1},
|
|
|
}
|
|
}
|
|
|
rw := httptest.NewRecorder()
|
|
rw := httptest.NewRecorder()
|
|
|
|
|
|
|
@@ -641,6 +649,11 @@ func TestServeAdminMembersPut(t *testing.T) {
|
|
|
if gct := rw.Header().Get("Content-Type"); gct != wct {
|
|
if gct := rw.Header().Get("Content-Type"); gct != wct {
|
|
|
t.Errorf("content-type = %s, want %s", gct, wct)
|
|
t.Errorf("content-type = %s, want %s", gct, wct)
|
|
|
}
|
|
}
|
|
|
|
|
+ gcid := rw.Header().Get("X-Etcd-Cluster-ID")
|
|
|
|
|
+ wcid := strconv.FormatUint(h.clusterInfo.ID(), 16)
|
|
|
|
|
+ if gcid != wcid {
|
|
|
|
|
+ t.Errorf("cid = %s, want %s", gcid, wcid)
|
|
|
|
|
+ }
|
|
|
g := rw.Body.String()
|
|
g := rw.Body.String()
|
|
|
w := string(wb) + "\n"
|
|
w := string(wb) + "\n"
|
|
|
if g != w {
|
|
if g != w {
|
|
@@ -659,7 +672,8 @@ func TestServeAdminMembersDelete(t *testing.T) {
|
|
|
}
|
|
}
|
|
|
s := &serverRecorder{}
|
|
s := &serverRecorder{}
|
|
|
h := &adminMembersHandler{
|
|
h := &adminMembersHandler{
|
|
|
- server: s,
|
|
|
|
|
|
|
+ server: s,
|
|
|
|
|
+ clusterInfo: &fakeCluster{id: 1},
|
|
|
}
|
|
}
|
|
|
rw := httptest.NewRecorder()
|
|
rw := httptest.NewRecorder()
|
|
|
|
|
|
|
@@ -669,6 +683,11 @@ func TestServeAdminMembersDelete(t *testing.T) {
|
|
|
if rw.Code != wcode {
|
|
if rw.Code != wcode {
|
|
|
t.Errorf("code=%d, want %d", rw.Code, wcode)
|
|
t.Errorf("code=%d, want %d", rw.Code, wcode)
|
|
|
}
|
|
}
|
|
|
|
|
+ gcid := rw.Header().Get("X-Etcd-Cluster-ID")
|
|
|
|
|
+ wcid := strconv.FormatUint(h.clusterInfo.ID(), 16)
|
|
|
|
|
+ if gcid != wcid {
|
|
|
|
|
+ t.Errorf("cid = %s, want %s", gcid, wcid)
|
|
|
|
|
+ }
|
|
|
g := rw.Body.String()
|
|
g := rw.Body.String()
|
|
|
if g != "" {
|
|
if g != "" {
|
|
|
t.Errorf("got body=%q, want %q", g, "")
|
|
t.Errorf("got body=%q, want %q", g, "")
|
|
@@ -768,14 +787,22 @@ func TestServeAdminMembersFail(t *testing.T) {
|
|
|
}
|
|
}
|
|
|
for i, tt := range tests {
|
|
for i, tt := range tests {
|
|
|
h := &adminMembersHandler{
|
|
h := &adminMembersHandler{
|
|
|
- server: tt.server,
|
|
|
|
|
- clock: clockwork.NewFakeClock(),
|
|
|
|
|
|
|
+ server: tt.server,
|
|
|
|
|
+ clusterInfo: &fakeCluster{id: 1},
|
|
|
|
|
+ clock: clockwork.NewFakeClock(),
|
|
|
}
|
|
}
|
|
|
rw := httptest.NewRecorder()
|
|
rw := httptest.NewRecorder()
|
|
|
h.ServeHTTP(rw, tt.req)
|
|
h.ServeHTTP(rw, tt.req)
|
|
|
if rw.Code != tt.wcode {
|
|
if rw.Code != tt.wcode {
|
|
|
t.Errorf("#%d: code=%d, want %d", i, rw.Code, tt.wcode)
|
|
t.Errorf("#%d: code=%d, want %d", i, rw.Code, tt.wcode)
|
|
|
}
|
|
}
|
|
|
|
|
+ if rw.Code != http.StatusMethodNotAllowed {
|
|
|
|
|
+ gcid := rw.Header().Get("X-Etcd-Cluster-ID")
|
|
|
|
|
+ wcid := strconv.FormatUint(h.clusterInfo.ID(), 16)
|
|
|
|
|
+ if gcid != wcid {
|
|
|
|
|
+ t.Errorf("#%d: cid = %s, want %s", i, gcid, wcid)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1101,14 +1128,22 @@ func TestBadServeKeys(t *testing.T) {
|
|
|
}
|
|
}
|
|
|
for i, tt := range testBadCases {
|
|
for i, tt := range testBadCases {
|
|
|
h := &keysHandler{
|
|
h := &keysHandler{
|
|
|
- timeout: 0, // context times out immediately
|
|
|
|
|
- server: tt.server,
|
|
|
|
|
|
|
+ timeout: 0, // context times out immediately
|
|
|
|
|
+ server: tt.server,
|
|
|
|
|
+ clusterInfo: &fakeCluster{id: 1},
|
|
|
}
|
|
}
|
|
|
rw := httptest.NewRecorder()
|
|
rw := httptest.NewRecorder()
|
|
|
h.ServeHTTP(rw, tt.req)
|
|
h.ServeHTTP(rw, tt.req)
|
|
|
if rw.Code != tt.wcode {
|
|
if rw.Code != tt.wcode {
|
|
|
t.Errorf("#%d: got code=%d, want %d", i, rw.Code, tt.wcode)
|
|
t.Errorf("#%d: got code=%d, want %d", i, rw.Code, tt.wcode)
|
|
|
}
|
|
}
|
|
|
|
|
+ if rw.Code != http.StatusMethodNotAllowed {
|
|
|
|
|
+ gcid := rw.Header().Get("X-Etcd-Cluster-ID")
|
|
|
|
|
+ wcid := strconv.FormatUint(h.clusterInfo.ID(), 16)
|
|
|
|
|
+ if gcid != wcid {
|
|
|
|
|
+ t.Errorf("#%d: cid = %s, want %s", i, gcid, wcid)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
if g := strings.TrimSuffix(rw.Body.String(), "\n"); g != tt.wbody {
|
|
if g := strings.TrimSuffix(rw.Body.String(), "\n"); g != tt.wbody {
|
|
|
t.Errorf("#%d: body = %s, want %s", i, g, tt.wbody)
|
|
t.Errorf("#%d: body = %s, want %s", i, g, tt.wbody)
|
|
|
}
|
|
}
|
|
@@ -1126,9 +1161,10 @@ func TestServeKeysEvent(t *testing.T) {
|
|
|
},
|
|
},
|
|
|
}
|
|
}
|
|
|
h := &keysHandler{
|
|
h := &keysHandler{
|
|
|
- timeout: time.Hour,
|
|
|
|
|
- server: server,
|
|
|
|
|
- timer: &dummyRaftTimer{},
|
|
|
|
|
|
|
+ timeout: time.Hour,
|
|
|
|
|
+ server: server,
|
|
|
|
|
+ clusterInfo: &fakeCluster{id: 1},
|
|
|
|
|
+ timer: &dummyRaftTimer{},
|
|
|
}
|
|
}
|
|
|
rw := httptest.NewRecorder()
|
|
rw := httptest.NewRecorder()
|
|
|
|
|
|
|
@@ -1146,6 +1182,11 @@ func TestServeKeysEvent(t *testing.T) {
|
|
|
if rw.Code != wcode {
|
|
if rw.Code != wcode {
|
|
|
t.Errorf("got code=%d, want %d", rw.Code, wcode)
|
|
t.Errorf("got code=%d, want %d", rw.Code, wcode)
|
|
|
}
|
|
}
|
|
|
|
|
+ gcid := rw.Header().Get("X-Etcd-Cluster-ID")
|
|
|
|
|
+ wcid := strconv.FormatUint(h.clusterInfo.ID(), 16)
|
|
|
|
|
+ if gcid != wcid {
|
|
|
|
|
+ t.Errorf("cid = %s, want %s", gcid, wcid)
|
|
|
|
|
+ }
|
|
|
g := rw.Body.String()
|
|
g := rw.Body.String()
|
|
|
if g != wbody {
|
|
if g != wbody {
|
|
|
t.Errorf("got body=%#v, want %#v", g, wbody)
|
|
t.Errorf("got body=%#v, want %#v", g, wbody)
|
|
@@ -1164,9 +1205,10 @@ func TestServeKeysWatch(t *testing.T) {
|
|
|
},
|
|
},
|
|
|
}
|
|
}
|
|
|
h := &keysHandler{
|
|
h := &keysHandler{
|
|
|
- timeout: time.Hour,
|
|
|
|
|
- server: server,
|
|
|
|
|
- timer: &dummyRaftTimer{},
|
|
|
|
|
|
|
+ timeout: time.Hour,
|
|
|
|
|
+ server: server,
|
|
|
|
|
+ clusterInfo: &fakeCluster{id: 1},
|
|
|
|
|
+ timer: &dummyRaftTimer{},
|
|
|
}
|
|
}
|
|
|
go func() {
|
|
go func() {
|
|
|
ec <- &store.Event{
|
|
ec <- &store.Event{
|
|
@@ -1190,6 +1232,11 @@ func TestServeKeysWatch(t *testing.T) {
|
|
|
if rw.Code != wcode {
|
|
if rw.Code != wcode {
|
|
|
t.Errorf("got code=%d, want %d", rw.Code, wcode)
|
|
t.Errorf("got code=%d, want %d", rw.Code, wcode)
|
|
|
}
|
|
}
|
|
|
|
|
+ gcid := rw.Header().Get("X-Etcd-Cluster-ID")
|
|
|
|
|
+ wcid := strconv.FormatUint(h.clusterInfo.ID(), 16)
|
|
|
|
|
+ if gcid != wcid {
|
|
|
|
|
+ t.Errorf("cid = %s, want %s", gcid, wcid)
|
|
|
|
|
+ }
|
|
|
g := rw.Body.String()
|
|
g := rw.Body.String()
|
|
|
if g != wbody {
|
|
if g != wbody {
|
|
|
t.Errorf("got body=%#v, want %#v", g, wbody)
|
|
t.Errorf("got body=%#v, want %#v", g, wbody)
|