mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #1363 from coreos/return_json
etcdserver: admin PUT returns the json representation of the newly creat...
This commit is contained in:
commit
051ad7585f
@ -47,7 +47,7 @@ func TestClusterStoreAdd(t *testing.T) {
|
|||||||
params: []interface{}{
|
params: []interface{}{
|
||||||
path.Join(storeMembersPrefix, "1", "attributes"),
|
path.Join(storeMembersPrefix, "1", "attributes"),
|
||||||
false,
|
false,
|
||||||
`{"Name":"node1","ClientURLs":null}`,
|
`{"Name":"node1"}`,
|
||||||
false,
|
false,
|
||||||
store.Permanent,
|
store.Permanent,
|
||||||
},
|
},
|
||||||
|
@ -185,7 +185,11 @@ func (h serverHandler) serveAdminMembers(w http.ResponseWriter, r *http.Request)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Printf("etcdhttp: added node %x with peer urls %v", m.ID, raftAttr.PeerURLs)
|
log.Printf("etcdhttp: added node %x with peer urls %v", m.ID, raftAttr.PeerURLs)
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.WriteHeader(http.StatusCreated)
|
w.WriteHeader(http.StatusCreated)
|
||||||
|
if err := json.NewEncoder(w).Encode(m); err != nil {
|
||||||
|
log.Printf("etcdhttp: %v", err)
|
||||||
|
}
|
||||||
case "DELETE":
|
case "DELETE":
|
||||||
idStr := strings.TrimPrefix(r.URL.Path, adminMembersPrefix)
|
idStr := strings.TrimPrefix(r.URL.Path, adminMembersPrefix)
|
||||||
id, err := strconv.ParseUint(idStr, 16, 64)
|
id, err := strconv.ParseUint(idStr, 16, 64)
|
||||||
|
@ -1553,14 +1553,24 @@ func TestServeAdminMembersPut(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)
|
||||||
}
|
}
|
||||||
g := rw.Body.String()
|
|
||||||
if g != "" {
|
|
||||||
t.Errorf("got body=%q, want %q", g, "")
|
|
||||||
}
|
|
||||||
wm := etcdserver.Member{
|
wm := etcdserver.Member{
|
||||||
ID: 3064321551348478165,
|
ID: 3064321551348478165,
|
||||||
RaftAttributes: raftAttr,
|
RaftAttributes: raftAttr,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wb, err := json.Marshal(wm)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
wct := "application/json"
|
||||||
|
if gct := rw.Header().Get("Content-Type"); gct != wct {
|
||||||
|
t.Errorf("content-type = %s, want %s", gct, wct)
|
||||||
|
}
|
||||||
|
g := rw.Body.String()
|
||||||
|
w := string(wb) + "\n"
|
||||||
|
if g != w {
|
||||||
|
t.Errorf("got body=%q, want %q", g, w)
|
||||||
|
}
|
||||||
wactions := []action{{name: "AddMember", params: []interface{}{wm}}}
|
wactions := []action{{name: "AddMember", params: []interface{}{wm}}}
|
||||||
if !reflect.DeepEqual(s.actions, wactions) {
|
if !reflect.DeepEqual(s.actions, wactions) {
|
||||||
t.Errorf("actions = %+v, want %+v", s.actions, wactions)
|
t.Errorf("actions = %+v, want %+v", s.actions, wactions)
|
||||||
|
@ -37,8 +37,8 @@ type RaftAttributes struct {
|
|||||||
|
|
||||||
// Attributes represents all the non-raft related attributes of an etcd member.
|
// Attributes represents all the non-raft related attributes of an etcd member.
|
||||||
type Attributes struct {
|
type Attributes struct {
|
||||||
Name string
|
Name string `json:",omitempty"`
|
||||||
ClientURLs []string
|
ClientURLs []string `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Member struct {
|
type Member struct {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user