2015-01-25 06:19:16 +03:00
|
|
|
// Copyright 2015 CoreOS, Inc.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2014-10-25 20:49:35 +04:00
|
|
|
|
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
2015-01-29 02:22:27 +03:00
|
|
|
"encoding/json"
|
2015-01-29 23:23:08 +03:00
|
|
|
"errors"
|
2014-10-25 20:49:35 +04:00
|
|
|
"net/http"
|
|
|
|
"net/url"
|
2014-10-31 21:44:28 +03:00
|
|
|
"reflect"
|
2014-10-25 20:49:35 +04:00
|
|
|
"testing"
|
2014-10-30 02:14:26 +03:00
|
|
|
|
2015-01-29 23:23:08 +03:00
|
|
|
"github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/net/context"
|
|
|
|
|
2014-10-30 02:14:26 +03:00
|
|
|
"github.com/coreos/etcd/pkg/types"
|
2014-10-25 20:49:35 +04:00
|
|
|
)
|
|
|
|
|
2014-10-30 02:14:49 +03:00
|
|
|
func TestMembersAPIActionList(t *testing.T) {
|
2014-10-31 01:42:34 +03:00
|
|
|
ep := url.URL{Scheme: "http", Host: "example.com"}
|
2014-10-30 02:14:49 +03:00
|
|
|
act := &membersAPIActionList{}
|
|
|
|
|
2014-10-25 20:49:35 +04:00
|
|
|
wantURL := &url.URL{
|
|
|
|
Scheme: "http",
|
|
|
|
Host: "example.com",
|
2014-10-29 22:11:26 +03:00
|
|
|
Path: "/v2/members",
|
2014-10-25 20:49:35 +04:00
|
|
|
}
|
|
|
|
|
2014-11-01 00:24:14 +03:00
|
|
|
got := *act.HTTPRequest(ep)
|
2015-01-23 01:30:58 +03:00
|
|
|
err := assertRequest(got, "GET", wantURL, http.Header{}, nil)
|
2014-10-25 20:49:35 +04:00
|
|
|
if err != nil {
|
2014-10-30 02:14:49 +03:00
|
|
|
t.Error(err.Error())
|
2014-10-25 20:49:35 +04:00
|
|
|
}
|
|
|
|
}
|
2014-10-30 02:14:26 +03:00
|
|
|
|
|
|
|
func TestMembersAPIActionAdd(t *testing.T) {
|
2014-10-31 01:42:34 +03:00
|
|
|
ep := url.URL{Scheme: "http", Host: "example.com"}
|
2014-10-30 02:14:26 +03:00
|
|
|
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",
|
2014-10-31 01:42:34 +03:00
|
|
|
Path: "/v2/members",
|
2014-10-30 02:14:26 +03:00
|
|
|
}
|
|
|
|
wantHeader := http.Header{
|
|
|
|
"Content-Type": []string{"application/json"},
|
|
|
|
}
|
|
|
|
wantBody := []byte(`{"peerURLs":["https://127.0.0.1:8081","http://127.0.0.1:8080"]}`)
|
|
|
|
|
2014-11-01 00:24:14 +03:00
|
|
|
got := *act.HTTPRequest(ep)
|
2015-01-23 01:30:58 +03:00
|
|
|
err := assertRequest(got, "POST", wantURL, wantHeader, wantBody)
|
2014-10-30 02:14:26 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err.Error())
|
|
|
|
}
|
|
|
|
}
|
2014-10-30 02:13:20 +03:00
|
|
|
|
|
|
|
func TestMembersAPIActionRemove(t *testing.T) {
|
2014-10-31 01:42:34 +03:00
|
|
|
ep := url.URL{Scheme: "http", Host: "example.com"}
|
2014-10-30 02:13:20 +03:00
|
|
|
act := &membersAPIActionRemove{memberID: "XXX"}
|
|
|
|
|
|
|
|
wantURL := &url.URL{
|
|
|
|
Scheme: "http",
|
|
|
|
Host: "example.com",
|
|
|
|
Path: "/v2/members/XXX",
|
|
|
|
}
|
|
|
|
|
2014-11-01 00:24:14 +03:00
|
|
|
got := *act.HTTPRequest(ep)
|
2015-01-23 01:30:58 +03:00
|
|
|
err := assertRequest(got, "DELETE", wantURL, http.Header{}, nil)
|
2014-10-30 02:13:20 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err.Error())
|
|
|
|
}
|
|
|
|
}
|
2014-10-30 21:46:44 +03:00
|
|
|
|
|
|
|
func TestAssertStatusCode(t *testing.T) {
|
2014-11-06 23:31:24 +03:00
|
|
|
if err := assertStatusCode(404, 400); err == nil {
|
2014-10-30 21:46:44 +03:00
|
|
|
t.Errorf("assertStatusCode failed to detect conflict in 400 vs 404")
|
|
|
|
}
|
|
|
|
|
2014-11-06 23:31:24 +03:00
|
|
|
if err := assertStatusCode(404, 400, 404); err != nil {
|
|
|
|
t.Errorf("assertStatusCode found conflict in (404,400) vs 400: %v", err)
|
2014-10-30 21:46:44 +03:00
|
|
|
}
|
|
|
|
}
|
2014-10-31 21:44:28 +03:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
2015-01-29 02:22:27 +03:00
|
|
|
|
|
|
|
func TestMemberUnmarshal(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
body []byte
|
|
|
|
wantMember Member
|
|
|
|
wantError bool
|
|
|
|
}{
|
|
|
|
// no URLs, just check ID & Name
|
|
|
|
{
|
|
|
|
body: []byte(`{"id": "c", "name": "dungarees"}`),
|
|
|
|
wantMember: Member{ID: "c", Name: "dungarees", PeerURLs: nil, ClientURLs: nil},
|
|
|
|
},
|
|
|
|
|
|
|
|
// both client and peer URLs
|
|
|
|
{
|
2015-04-06 18:38:13 +03:00
|
|
|
body: []byte(`{"peerURLs": ["http://127.0.0.1:2379"], "clientURLs": ["http://127.0.0.1:2379"]}`),
|
2015-01-29 02:22:27 +03:00
|
|
|
wantMember: Member{
|
|
|
|
PeerURLs: []string{
|
2015-04-06 18:38:13 +03:00
|
|
|
"http://127.0.0.1:2379",
|
2015-01-29 02:22:27 +03:00
|
|
|
},
|
|
|
|
ClientURLs: []string{
|
2015-04-06 18:38:13 +03:00
|
|
|
"http://127.0.0.1:2379",
|
2015-01-29 02:22:27 +03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// multiple peer URLs
|
|
|
|
{
|
2015-04-06 18:38:13 +03:00
|
|
|
body: []byte(`{"peerURLs": ["http://127.0.0.1:2379", "https://example.com"]}`),
|
2015-01-29 02:22:27 +03:00
|
|
|
wantMember: Member{
|
|
|
|
PeerURLs: []string{
|
2015-04-06 18:38:13 +03:00
|
|
|
"http://127.0.0.1:2379",
|
2015-01-29 02:22:27 +03:00
|
|
|
"https://example.com",
|
|
|
|
},
|
|
|
|
ClientURLs: nil,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// multiple client URLs
|
|
|
|
{
|
2015-04-06 18:38:13 +03:00
|
|
|
body: []byte(`{"clientURLs": ["http://127.0.0.1:2379", "https://example.com"]}`),
|
2015-01-29 02:22:27 +03:00
|
|
|
wantMember: Member{
|
|
|
|
PeerURLs: nil,
|
|
|
|
ClientURLs: []string{
|
2015-04-06 18:38:13 +03:00
|
|
|
"http://127.0.0.1:2379",
|
2015-01-29 02:22:27 +03:00
|
|
|
"https://example.com",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// invalid JSON
|
|
|
|
{
|
|
|
|
body: []byte(`{"peerU`),
|
|
|
|
wantError: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, tt := range tests {
|
|
|
|
got := Member{}
|
|
|
|
err := json.Unmarshal(tt.body, &got)
|
|
|
|
if tt.wantError != (err != nil) {
|
|
|
|
t.Errorf("#%d: want error %t, got %v", i, tt.wantError, err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(tt.wantMember, got) {
|
|
|
|
t.Errorf("#%d: incorrect output: want=%#v, got=%#v", i, tt.wantMember, got)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-29 23:23:08 +03:00
|
|
|
func TestMemberCollectionUnmarshalFail(t *testing.T) {
|
|
|
|
mc := &memberCollection{}
|
|
|
|
if err := mc.UnmarshalJSON([]byte(`{`)); err == nil {
|
|
|
|
t.Errorf("got nil error")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-29 02:22:27 +03:00
|
|
|
func TestMemberCollectionUnmarshal(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
body []byte
|
|
|
|
want memberCollection
|
|
|
|
}{
|
2015-01-29 23:23:08 +03:00
|
|
|
{
|
|
|
|
body: []byte(`{}`),
|
|
|
|
want: memberCollection([]Member{}),
|
|
|
|
},
|
2015-01-29 02:22:27 +03:00
|
|
|
{
|
|
|
|
body: []byte(`{"members":[]}`),
|
|
|
|
want: memberCollection([]Member{}),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
body: []byte(`{"members":[{"id":"2745e2525fce8fe","peerURLs":["http://127.0.0.1:7003"],"name":"node3","clientURLs":["http://127.0.0.1:4003"]},{"id":"42134f434382925","peerURLs":["http://127.0.0.1:2380","http://127.0.0.1:7001"],"name":"node1","clientURLs":["http://127.0.0.1:2379","http://127.0.0.1:4001"]},{"id":"94088180e21eb87b","peerURLs":["http://127.0.0.1:7002"],"name":"node2","clientURLs":["http://127.0.0.1:4002"]}]}`),
|
|
|
|
want: memberCollection(
|
|
|
|
[]Member{
|
|
|
|
{
|
|
|
|
ID: "2745e2525fce8fe",
|
|
|
|
Name: "node3",
|
|
|
|
PeerURLs: []string{
|
|
|
|
"http://127.0.0.1:7003",
|
|
|
|
},
|
|
|
|
ClientURLs: []string{
|
|
|
|
"http://127.0.0.1:4003",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "42134f434382925",
|
|
|
|
Name: "node1",
|
|
|
|
PeerURLs: []string{
|
|
|
|
"http://127.0.0.1:2380",
|
|
|
|
"http://127.0.0.1:7001",
|
|
|
|
},
|
|
|
|
ClientURLs: []string{
|
|
|
|
"http://127.0.0.1:2379",
|
|
|
|
"http://127.0.0.1:4001",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "94088180e21eb87b",
|
|
|
|
Name: "node2",
|
|
|
|
PeerURLs: []string{
|
|
|
|
"http://127.0.0.1:7002",
|
|
|
|
},
|
|
|
|
ClientURLs: []string{
|
|
|
|
"http://127.0.0.1:4002",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, tt := range tests {
|
|
|
|
var got memberCollection
|
|
|
|
err := json.Unmarshal(tt.body, &got)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("#%d: unexpected error: %v", i, err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(tt.want, got) {
|
|
|
|
t.Errorf("#%d: incorrect output: want=%#v, got=%#v", i, tt.want, got)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMemberCreateRequestMarshal(t *testing.T) {
|
|
|
|
req := memberCreateRequest{
|
|
|
|
PeerURLs: types.URLs([]url.URL{
|
|
|
|
url.URL{Scheme: "http", Host: "127.0.0.1:8081"},
|
|
|
|
url.URL{Scheme: "https", Host: "127.0.0.1:8080"},
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
want := []byte(`{"peerURLs":["http://127.0.0.1:8081","https://127.0.0.1:8080"]}`)
|
|
|
|
|
|
|
|
got, err := json.Marshal(&req)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Marshal returned unexpected err=%v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(want, got) {
|
|
|
|
t.Fatalf("Failed to marshal memberCreateRequest: want=%s, got=%s", want, got)
|
|
|
|
}
|
|
|
|
}
|
2015-01-29 23:23:08 +03:00
|
|
|
|
|
|
|
func TestHTTPMembersAPIAddSuccess(t *testing.T) {
|
|
|
|
wantAction := &membersAPIActionAdd{
|
|
|
|
peerURLs: types.URLs([]url.URL{
|
|
|
|
url.URL{Scheme: "http", Host: "127.0.0.1:7002"},
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
|
|
|
|
mAPI := &httpMembersAPI{
|
|
|
|
client: &actionAssertingHTTPClient{
|
|
|
|
t: t,
|
|
|
|
act: wantAction,
|
|
|
|
resp: http.Response{
|
|
|
|
StatusCode: http.StatusCreated,
|
|
|
|
},
|
|
|
|
body: []byte(`{"id":"94088180e21eb87b","peerURLs":["http://127.0.0.1:7002"]}`),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
wantResponseMember := &Member{
|
|
|
|
ID: "94088180e21eb87b",
|
|
|
|
PeerURLs: []string{"http://127.0.0.1:7002"},
|
|
|
|
}
|
|
|
|
|
|
|
|
m, err := mAPI.Add(context.Background(), "http://127.0.0.1:7002")
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("got non-nil err: %#v", err)
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(wantResponseMember, m) {
|
|
|
|
t.Errorf("incorrect Member: want=%#v got=%#v", wantResponseMember, m)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHTTPMembersAPIAddError(t *testing.T) {
|
2015-04-06 18:38:13 +03:00
|
|
|
okPeer := "http://example.com:2379"
|
2015-01-29 23:23:08 +03:00
|
|
|
tests := []struct {
|
|
|
|
peerURL string
|
|
|
|
client httpClient
|
|
|
|
|
|
|
|
// if wantErr == nil, assert that the returned error is non-nil
|
|
|
|
// if wantErr != nil, assert that the returned error matches
|
|
|
|
wantErr error
|
|
|
|
}{
|
|
|
|
// malformed peer URL
|
|
|
|
{
|
2015-01-30 03:23:51 +03:00
|
|
|
peerURL: ":",
|
2015-01-29 23:23:08 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
// generic httpClient failure
|
|
|
|
{
|
|
|
|
peerURL: okPeer,
|
|
|
|
client: &staticHTTPClient{err: errors.New("fail!")},
|
|
|
|
},
|
|
|
|
|
|
|
|
// unrecognized HTTP status code
|
|
|
|
{
|
|
|
|
peerURL: okPeer,
|
|
|
|
client: &staticHTTPClient{
|
|
|
|
resp: http.Response{StatusCode: http.StatusTeapot},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// unmarshal body into membersError on StatusConflict
|
|
|
|
{
|
|
|
|
peerURL: okPeer,
|
|
|
|
client: &staticHTTPClient{
|
|
|
|
resp: http.Response{
|
|
|
|
StatusCode: http.StatusConflict,
|
|
|
|
},
|
|
|
|
body: []byte(`{"message":"fail!"}`),
|
|
|
|
},
|
|
|
|
wantErr: membersError{Message: "fail!"},
|
|
|
|
},
|
|
|
|
|
|
|
|
// fail to unmarshal body on StatusConflict
|
|
|
|
{
|
|
|
|
peerURL: okPeer,
|
|
|
|
client: &staticHTTPClient{
|
|
|
|
resp: http.Response{
|
|
|
|
StatusCode: http.StatusConflict,
|
|
|
|
},
|
|
|
|
body: []byte(`{"`),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// fail to unmarshal body on StatusCreated
|
|
|
|
{
|
|
|
|
peerURL: okPeer,
|
|
|
|
client: &staticHTTPClient{
|
|
|
|
resp: http.Response{
|
|
|
|
StatusCode: http.StatusCreated,
|
|
|
|
},
|
|
|
|
body: []byte(`{"id":"XX`),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, tt := range tests {
|
|
|
|
mAPI := &httpMembersAPI{client: tt.client}
|
|
|
|
m, err := mAPI.Add(context.Background(), tt.peerURL)
|
|
|
|
if err == nil {
|
|
|
|
t.Errorf("#%d: got nil err", i)
|
|
|
|
}
|
|
|
|
if tt.wantErr != nil && !reflect.DeepEqual(tt.wantErr, err) {
|
|
|
|
t.Errorf("#%d: incorrect error: want=%#v got=%#v", i, tt.wantErr, err)
|
|
|
|
}
|
|
|
|
if m != nil {
|
|
|
|
t.Errorf("#%d: got non-nil Member", i)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHTTPMembersAPIRemoveSuccess(t *testing.T) {
|
|
|
|
wantAction := &membersAPIActionRemove{
|
|
|
|
memberID: "94088180e21eb87b",
|
|
|
|
}
|
|
|
|
|
|
|
|
mAPI := &httpMembersAPI{
|
|
|
|
client: &actionAssertingHTTPClient{
|
|
|
|
t: t,
|
|
|
|
act: wantAction,
|
|
|
|
resp: http.Response{
|
|
|
|
StatusCode: http.StatusNoContent,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := mAPI.Remove(context.Background(), "94088180e21eb87b"); err != nil {
|
|
|
|
t.Errorf("got non-nil err: %#v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHTTPMembersAPIRemoveFail(t *testing.T) {
|
|
|
|
tests := []httpClient{
|
|
|
|
// generic error
|
|
|
|
&staticHTTPClient{
|
|
|
|
err: errors.New("fail!"),
|
|
|
|
},
|
|
|
|
|
|
|
|
// unexpected HTTP status code
|
|
|
|
&staticHTTPClient{
|
|
|
|
resp: http.Response{
|
|
|
|
StatusCode: http.StatusInternalServerError,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, tt := range tests {
|
|
|
|
mAPI := &httpMembersAPI{client: tt}
|
|
|
|
if err := mAPI.Remove(context.Background(), "94088180e21eb87b"); err == nil {
|
|
|
|
t.Errorf("#%d: got nil err", i)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHTTPMembersAPIListSuccess(t *testing.T) {
|
|
|
|
wantAction := &membersAPIActionList{}
|
|
|
|
mAPI := &httpMembersAPI{
|
|
|
|
client: &actionAssertingHTTPClient{
|
|
|
|
t: t,
|
|
|
|
act: wantAction,
|
|
|
|
resp: http.Response{
|
|
|
|
StatusCode: http.StatusOK,
|
|
|
|
},
|
|
|
|
body: []byte(`{"members":[{"id":"94088180e21eb87b","name":"node2","peerURLs":["http://127.0.0.1:7002"],"clientURLs":["http://127.0.0.1:4002"]}]}`),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
wantResponseMembers := []Member{
|
|
|
|
Member{
|
|
|
|
ID: "94088180e21eb87b",
|
|
|
|
Name: "node2",
|
|
|
|
PeerURLs: []string{"http://127.0.0.1:7002"},
|
|
|
|
ClientURLs: []string{"http://127.0.0.1:4002"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
m, err := mAPI.List(context.Background())
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("got non-nil err: %#v", err)
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(wantResponseMembers, m) {
|
|
|
|
t.Errorf("incorrect Members: want=%#v got=%#v", wantResponseMembers, m)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHTTPMembersAPIListError(t *testing.T) {
|
|
|
|
tests := []httpClient{
|
|
|
|
// generic httpClient failure
|
|
|
|
&staticHTTPClient{err: errors.New("fail!")},
|
|
|
|
|
|
|
|
// unrecognized HTTP status code
|
|
|
|
&staticHTTPClient{
|
|
|
|
resp: http.Response{StatusCode: http.StatusTeapot},
|
|
|
|
},
|
|
|
|
|
|
|
|
// fail to unmarshal body on StatusOK
|
|
|
|
&staticHTTPClient{
|
|
|
|
resp: http.Response{
|
|
|
|
StatusCode: http.StatusOK,
|
|
|
|
},
|
|
|
|
body: []byte(`[{"id":"XX`),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, tt := range tests {
|
|
|
|
mAPI := &httpMembersAPI{client: tt}
|
|
|
|
ms, err := mAPI.List(context.Background())
|
|
|
|
if err == nil {
|
|
|
|
t.Errorf("#%d: got nil err", i)
|
|
|
|
}
|
|
|
|
if ms != nil {
|
|
|
|
t.Errorf("#%d: got non-nil Member slice", i)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|