mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
client: use v2MembersURL helper
This commit is contained in:
parent
f0c3385cfc
commit
eab4692744
@ -121,8 +121,8 @@ func (m *httpMembersAPI) Remove(memberID string) error {
|
||||
type membersAPIActionList struct{}
|
||||
|
||||
func (l *membersAPIActionList) httpRequest(ep url.URL) *http.Request {
|
||||
ep.Path = path.Join(ep.Path, DefaultV2MembersPrefix)
|
||||
req, _ := http.NewRequest("GET", ep.String(), nil)
|
||||
u := v2MembersURL(ep)
|
||||
req, _ := http.NewRequest("GET", u.String(), nil)
|
||||
return req
|
||||
}
|
||||
|
||||
@ -131,8 +131,9 @@ type membersAPIActionRemove struct {
|
||||
}
|
||||
|
||||
func (d *membersAPIActionRemove) httpRequest(ep url.URL) *http.Request {
|
||||
ep.Path = path.Join(ep.Path, DefaultV2MembersPrefix, d.memberID)
|
||||
req, _ := http.NewRequest("DELETE", ep.String(), nil)
|
||||
u := v2MembersURL(ep)
|
||||
u.Path = path.Join(u.Path, d.memberID)
|
||||
req, _ := http.NewRequest("DELETE", u.String(), nil)
|
||||
return req
|
||||
}
|
||||
|
||||
@ -141,10 +142,10 @@ type membersAPIActionAdd struct {
|
||||
}
|
||||
|
||||
func (a *membersAPIActionAdd) httpRequest(ep url.URL) *http.Request {
|
||||
ep.Path = path.Join(ep.Path, DefaultV2MembersPrefix)
|
||||
u := v2MembersURL(ep)
|
||||
m := httptypes.MemberCreateRequest{PeerURLs: a.peerURLs}
|
||||
b, _ := json.Marshal(&m)
|
||||
req, _ := http.NewRequest("POST", ep.String(), bytes.NewReader(b))
|
||||
req, _ := http.NewRequest("POST", u.String(), bytes.NewReader(b))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
return req
|
||||
}
|
||||
@ -155,3 +156,10 @@ func assertStatusCode(want, got int) (err error) {
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// v2MembersURL add the necessary path to the provided endpoint
|
||||
// to route requests to the default v2 members API.
|
||||
func v2MembersURL(ep url.URL) *url.URL {
|
||||
ep.Path = path.Join(ep.Path, DefaultV2MembersPrefix)
|
||||
return &ep
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ package client
|
||||
import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/coreos/etcd/pkg/types"
|
||||
@ -93,3 +94,20 @@ func TestAssertStatusCode(t *testing.T) {
|
||||
t.Errorf("assertStatusCode found conflict in 400 vs 400: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestV2MembersURL(t *testing.T) {
|
||||
got := v2MembersURL(url.URL{
|
||||
Scheme: "http",
|
||||
Host: "foo.example.com:4002",
|
||||
Path: "/pants",
|
||||
})
|
||||
want := &url.URL{
|
||||
Scheme: "http",
|
||||
Host: "foo.example.com:4002",
|
||||
Path: "/pants/v2/members",
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(want, got) {
|
||||
t.Fatalf("v2MembersURL got %#v, want %#v", got, want)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user