Move response errors checking from portainerClientImp.do() to doJSON()

This commit is contained in:
Juan Carlos Mejías Rodríguez 2019-09-01 18:07:28 -04:00
parent be6aa497d8
commit 16517713ac
2 changed files with 19 additions and 14 deletions

View File

@ -116,11 +116,6 @@ func (n *portainerClientImp) do(uri, method string, requestBody io.Reader, heade
}
}
err = checkResponseForErrors(resp)
if err != nil {
return
}
return
}
@ -160,6 +155,11 @@ func (n *portainerClientImp) doJSON(uri, method string, headers http.Header, req
return err
}
err = checkResponseForErrors(resp)
if err != nil {
return err
}
// Decode response body, if any
if responseBody != nil {
d := json.NewDecoder(resp.Body)

View File

@ -105,15 +105,6 @@ func Test_portainerClientImp_do(t *testing.T) {
},
wantErr: true,
},
{
name: "returns error on response error",
fields: fields{
server: httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
})),
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
@ -229,6 +220,20 @@ func Test_portainerClientImp_doJSON(t *testing.T) {
wantRespBody: map[string]interface{}{},
wantErr: true,
},
{
name: "returns error on response error",
fields: fields{
server: httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
})),
},
args: args{
uri: "stacks",
method: http.MethodPost,
headers: http.Header{},
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {