Merge pull request #3187 from chengzhichao-xydt/codex/http-guard-test-body-close
test(utils): explicitly ignore resp.Body.Close() errors in tests
This commit is contained in:
commit
7ee4f41b7e
2 changed files with 7 additions and 7 deletions
|
|
@ -62,7 +62,7 @@ func TestCreateSafeHTTPClient_BlocksPrivateRedirect(t *testing.T) {
|
||||||
allowPrivateHosts = false
|
allowPrivateHosts = false
|
||||||
resp, err := client.Get(server.URL)
|
resp, err := client.Get(server.URL)
|
||||||
if resp != nil && resp.Body != nil {
|
if resp != nil && resp.Body != nil {
|
||||||
resp.Body.Close()
|
_ = resp.Body.Close()
|
||||||
}
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("expected redirect to private host to fail")
|
t.Fatal("expected redirect to private host to fail")
|
||||||
|
|
|
||||||
|
|
@ -68,11 +68,11 @@ func TestDoRequestWithRetry(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, resp)
|
require.NotNil(t, resp)
|
||||||
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
||||||
resp.Body.Close()
|
_ = resp.Body.Close()
|
||||||
} else {
|
} else {
|
||||||
require.NotNil(t, resp)
|
require.NotNil(t, resp)
|
||||||
assert.Equal(t, http.StatusInternalServerError, resp.StatusCode)
|
assert.Equal(t, http.StatusInternalServerError, resp.StatusCode)
|
||||||
resp.Body.Close()
|
_ = resp.Body.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Equal(t, tc.wantAttempts, attempts)
|
assert.Equal(t, tc.wantAttempts, attempts)
|
||||||
|
|
@ -111,7 +111,7 @@ func TestDoRequestWithRetry_RetryAfter429Honored(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, resp)
|
require.NotNil(t, resp)
|
||||||
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
||||||
resp.Body.Close()
|
_ = resp.Body.Close()
|
||||||
require.Equal(t, 2, attempts)
|
require.Equal(t, 2, attempts)
|
||||||
|
|
||||||
assert.GreaterOrEqual(t, secondAttemptAt.Sub(firstAttemptAt), 900*time.Millisecond)
|
assert.GreaterOrEqual(t, secondAttemptAt.Sub(firstAttemptAt), 900*time.Millisecond)
|
||||||
|
|
@ -148,7 +148,7 @@ func TestDoRequestWithRetry_RetryAfter429InvalidFallsBack(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, resp)
|
require.NotNil(t, resp)
|
||||||
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
||||||
resp.Body.Close()
|
_ = resp.Body.Close()
|
||||||
require.Equal(t, 2, attempts)
|
require.Equal(t, 2, attempts)
|
||||||
|
|
||||||
assert.GreaterOrEqual(t, secondAttemptAt.Sub(firstAttemptAt), 45*time.Millisecond)
|
assert.GreaterOrEqual(t, secondAttemptAt.Sub(firstAttemptAt), 45*time.Millisecond)
|
||||||
|
|
@ -200,7 +200,7 @@ func TestDoRequestWithRetry_ContextCancel(t *testing.T) {
|
||||||
|
|
||||||
resp, err := DoRequestWithRetry(client, req)
|
resp, err := DoRequestWithRetry(client, req)
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
resp.Body.Close()
|
_ = resp.Body.Close()
|
||||||
}
|
}
|
||||||
require.Error(t, err, "expected error from context cancellation")
|
require.Error(t, err, "expected error from context cancellation")
|
||||||
assert.Nil(t, resp, "expected nil response when context is canceled")
|
assert.Nil(t, resp, "expected nil response when context is canceled")
|
||||||
|
|
@ -275,7 +275,7 @@ func TestDoRequestWithRetry_Delay(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, resp)
|
require.NotNil(t, resp)
|
||||||
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
||||||
resp.Body.Close()
|
_ = resp.Body.Close()
|
||||||
|
|
||||||
assert.GreaterOrEqual(t, delays[2], time.Millisecond)
|
assert.GreaterOrEqual(t, delays[2], time.Millisecond)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue