mirror of
https://github.com/interviewstreet/go-jira.git
synced 2025-06-04 23:07:35 +02:00
Merge pull request #6 from matrix-solutions/development
Close response, only v was given
This commit is contained in:
commit
04e71ea77c
4
jira.go
4
jira.go
@ -97,8 +97,6 @@ func (c *Client) Do(req *http.Request, v interface{}) (*http.Response, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
err = CheckResponse(resp)
|
err = CheckResponse(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Even though there was an error, we still return the response
|
// Even though there was an error, we still return the response
|
||||||
@ -107,6 +105,8 @@ func (c *Client) Do(req *http.Request, v interface{}) (*http.Response, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if v != nil {
|
if v != nil {
|
||||||
|
// Open a NewDecoder and defer closing the reader only if there is a provided interface to decode to
|
||||||
|
defer resp.Body.Close()
|
||||||
err = json.NewDecoder(resp.Body).Decode(v)
|
err = json.NewDecoder(resp.Body).Decode(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
26
jira_test.go
26
jira_test.go
@ -215,6 +215,32 @@ func TestDo(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDo_HTTPResponse(t *testing.T) {
|
||||||
|
setup()
|
||||||
|
defer teardown()
|
||||||
|
|
||||||
|
type foo struct {
|
||||||
|
A string
|
||||||
|
}
|
||||||
|
|
||||||
|
testMux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if m := "GET"; m != r.Method {
|
||||||
|
t.Errorf("Request method = %v, want %v", r.Method, m)
|
||||||
|
}
|
||||||
|
fmt.Fprint(w, `{"A":"a"}`)
|
||||||
|
})
|
||||||
|
|
||||||
|
req, _ := testClient.NewRequest("GET", "/", nil)
|
||||||
|
res, _ := testClient.Do(req, nil)
|
||||||
|
_, err := ioutil.ReadAll(res.Body)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Error on parsing HTTP Response = %v", err.Error())
|
||||||
|
} else if res.StatusCode != 200 {
|
||||||
|
t.Errorf("Response code = %v, want %v", res.StatusCode, 200)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestDo_HTTPError(t *testing.T) {
|
func TestDo_HTTPError(t *testing.T) {
|
||||||
setup()
|
setup()
|
||||||
defer teardown()
|
defer teardown()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user