mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
etcdserver: admin PUT returns the json representation of the newly created member
This commit is contained in:
parent
712a05be83
commit
63fa2a626a
@ -47,7 +47,7 @@ func TestClusterStoreAdd(t *testing.T) {
|
||||
params: []interface{}{
|
||||
path.Join(storeMembersPrefix, "1", "attributes"),
|
||||
false,
|
||||
`{"Name":"node1","ClientURLs":null}`,
|
||||
`{"Name":"node1"}`,
|
||||
false,
|
||||
store.Permanent,
|
||||
},
|
||||
|
@ -185,7 +185,11 @@ func (h serverHandler) serveAdminMembers(w http.ResponseWriter, r *http.Request)
|
||||
return
|
||||
}
|
||||
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)
|
||||
if err := json.NewEncoder(w).Encode(m); err != nil {
|
||||
log.Printf("etcdhttp: %v", err)
|
||||
}
|
||||
case "DELETE":
|
||||
idStr := strings.TrimPrefix(r.URL.Path, adminMembersPrefix)
|
||||
id, err := strconv.ParseUint(idStr, 16, 64)
|
||||
|
@ -1553,14 +1553,24 @@ func TestServeAdminMembersPut(t *testing.T) {
|
||||
if 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{
|
||||
ID: 3064321551348478165,
|
||||
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}}}
|
||||
if !reflect.DeepEqual(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.
|
||||
type Attributes struct {
|
||||
Name string
|
||||
ClientURLs []string
|
||||
Name string `json:",omitempty"`
|
||||
ClientURLs []string `json:",omitempty"`
|
||||
}
|
||||
|
||||
type Member struct {
|
||||
|
Loading…
x
Reference in New Issue
Block a user