mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 21:31:37 +00:00
all: ensure resp.body closed (#26969)
This commit is contained in:
parent
6e055a601d
commit
54570300cc
4 changed files with 9 additions and 2 deletions
|
|
@ -87,9 +87,11 @@ func (lc *LibratoClient) PostMetrics(batch Batch) (err error) {
|
|||
req.Header.Set("Content-Type", "application/json")
|
||||
req.SetBasicAuth(lc.Email, lc.Token)
|
||||
|
||||
if resp, err = http.DefaultClient.Do(req); err != nil {
|
||||
resp, err = http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
var body []byte
|
||||
|
|
|
|||
|
|
@ -651,5 +651,6 @@ func doHTTPRequest(t *testing.T, req *http.Request) *http.Response {
|
|||
if err != nil {
|
||||
t.Error("could not issue a GET request to the given endpoint", err)
|
||||
}
|
||||
t.Cleanup(func() { resp.Body.Close() })
|
||||
return resp
|
||||
}
|
||||
|
|
|
|||
|
|
@ -127,6 +127,7 @@ func TestMocker(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("Could not start mocker: %s", err)
|
||||
}
|
||||
resp.Body.Close()
|
||||
if resp.StatusCode != 200 {
|
||||
t.Fatalf("Invalid Status Code received for starting mocker, expected 200, got %d", resp.StatusCode)
|
||||
}
|
||||
|
|
@ -148,15 +149,17 @@ func TestMocker(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("Could not stop mocker: %s", err)
|
||||
}
|
||||
resp.Body.Close()
|
||||
if resp.StatusCode != 200 {
|
||||
t.Fatalf("Invalid Status Code received for stopping mocker, expected 200, got %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
//reset the network
|
||||
_, err = http.Post(s.URL+"/reset", "", nil)
|
||||
resp, err = http.Post(s.URL+"/reset", "", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Could not reset network: %s", err)
|
||||
}
|
||||
resp.Body.Close()
|
||||
|
||||
//now the number of nodes in the network should be zero
|
||||
nodes_info, err = client.GetNodes()
|
||||
|
|
|
|||
|
|
@ -92,6 +92,7 @@ func confirmHTTPRequestYieldsStatusCode(t *testing.T, method, contentType, body
|
|||
if err != nil {
|
||||
t.Fatalf("request failed: %v", err)
|
||||
}
|
||||
resp.Body.Close()
|
||||
confirmStatusCode(t, resp.StatusCode, expectedStatusCode)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue