mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
client: use httptypes.MemberCreateRequest in member add
This commit is contained in:
parent
011a67c878
commit
4e759b46ce
@ -26,6 +26,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/coreos/etcd/etcdserver/etcdhttp/httptypes"
|
||||
"github.com/coreos/etcd/pkg/types"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -82,7 +83,12 @@ func (m *httpMembersAPI) List() ([]httptypes.Member, error) {
|
||||
}
|
||||
|
||||
func (m *httpMembersAPI) Add(peerURL string) (*httptypes.Member, error) {
|
||||
req := &membersAPIActionAdd{peerURL: peerURL}
|
||||
urls, err := types.NewURLs([]string{peerURL})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req := &membersAPIActionAdd{peerURLs: urls}
|
||||
code, body, err := m.client.doWithTimeout(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -128,11 +134,11 @@ func (d *membersAPIActionRemove) httpRequest(ep url.URL) *http.Request {
|
||||
}
|
||||
|
||||
type membersAPIActionAdd struct {
|
||||
peerURL string
|
||||
peerURLs types.URLs
|
||||
}
|
||||
|
||||
func (a *membersAPIActionAdd) httpRequest(ep url.URL) *http.Request {
|
||||
m := httptypes.Member{PeerURLs: []string{a.peerURL}}
|
||||
m := httptypes.MemberCreateRequest{PeerURLs: a.peerURLs}
|
||||
b, _ := json.Marshal(&m)
|
||||
req, _ := http.NewRequest("POST", ep.String(), bytes.NewReader(b))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
@ -20,6 +20,8 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
"github.com/coreos/etcd/pkg/types"
|
||||
)
|
||||
|
||||
func TestMembersAPIListAction(t *testing.T) {
|
||||
@ -37,3 +39,29 @@ func TestMembersAPIListAction(t *testing.T) {
|
||||
t.Errorf(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestMembersAPIActionAdd(t *testing.T) {
|
||||
ep := url.URL{Scheme: "http", Host: "example.com/v2/admin/members"}
|
||||
act := &membersAPIActionAdd{
|
||||
peerURLs: types.URLs([]url.URL{
|
||||
url.URL{Scheme: "https", Host: "127.0.0.1:8081"},
|
||||
url.URL{Scheme: "http", Host: "127.0.0.1:8080"},
|
||||
}),
|
||||
}
|
||||
|
||||
wantURL := &url.URL{
|
||||
Scheme: "http",
|
||||
Host: "example.com",
|
||||
Path: "/v2/admin/members",
|
||||
}
|
||||
wantHeader := http.Header{
|
||||
"Content-Type": []string{"application/json"},
|
||||
}
|
||||
wantBody := []byte(`{"peerURLs":["https://127.0.0.1:8081","http://127.0.0.1:8080"]}`)
|
||||
|
||||
got := *act.httpRequest(ep)
|
||||
err := assertResponse(got, wantURL, wantHeader, wantBody)
|
||||
if err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user