Skip to content

Commit

Permalink
Revert ioutil.ReadAll migration (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
vearutop authored Dec 2, 2022
1 parent ca4fe47 commit ad8f1a6
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
test:
strategy:
matrix:
go-version: [ 1.16.x, 1.17.x, 1.18.x, 1.19.x ]
go-version: [ 1.13.x, 1.14.x, 1.15.x, 1.16.x, 1.17.x, 1.18.x, 1.19.x ]
runs-on: ubuntu-latest
steps:
- name: Install Go stable
Expand Down
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ linters:
issues:
exclude-use-default: false
exclude-rules:
- linters:
- staticcheck
path: ".go"
text: "\"io/ioutil\" has been deprecated since Go 1.16" # Keeping backwards compatibility with go1.13.
- linters:
- gomnd
- goconst
Expand Down
3 changes: 2 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/cookiejar"
"net/url"
Expand Down Expand Up @@ -230,7 +231,7 @@ func (c *Client) do() (err error) {
return
}

body, er := io.ReadAll(resp.Body)
body, er := ioutil.ReadAll(resp.Body)
if er != nil {
return
}
Expand Down
4 changes: 2 additions & 2 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package httpmock_test
import (
"context"
"errors"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"sync/atomic"
Expand All @@ -18,7 +18,7 @@ func TestNewClient(t *testing.T) {
cnt := int64(0)
srv := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
assert.Equal(t, "/foo?q=1", r.URL.String())
b, err := io.ReadAll(r.Body)
b, err := ioutil.ReadAll(r.Body)
assert.NoError(t, err)
assert.Equal(t, `{"foo":"bar"}`, string(b))
assert.Equal(t, "application/json", r.Header.Get("Content-Type"))
Expand Down
6 changes: 3 additions & 3 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"sync"
Expand Down Expand Up @@ -191,7 +191,7 @@ func (sm *Server) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
}

if len(sm.expectations) == 0 {
body, err := io.ReadAll(req.Body)
body, err := ioutil.ReadAll(req.Body)
if err == nil && len(body) > 0 {
if sm.OnBodyMismatch != nil {
sm.OnBodyMismatch(body)
Expand Down Expand Up @@ -285,7 +285,7 @@ func (sm *Server) checkRequest(req *http.Request, expectation Expectation) error
}
}

reqBody, err := io.ReadAll(req.Body)
reqBody, err := ioutil.ReadAll(req.Body)
if err != nil {
return err
}
Expand Down
21 changes: 11 additions & 10 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package httpmock_test
import (
"bytes"
"io"
"io/ioutil"
"net/http"
"strings"
"sync"
Expand Down Expand Up @@ -37,7 +38,7 @@ func assertRoundTrip(t *testing.T, baseURL string, expectation httpmock.Expectat
resp, err := http.DefaultTransport.RoundTrip(req)
require.NoError(t, err)

body, err := io.ReadAll(resp.Body)
body, err := ioutil.ReadAll(resp.Body)
require.NoError(t, resp.Body.Close())
require.NoError(t, err)

Expand Down Expand Up @@ -160,7 +161,7 @@ func TestServer_ServeHTTP_error(t *testing.T) {
resp, err := http.DefaultTransport.RoundTrip(req)
require.NoError(t, err)

respBody, err := io.ReadAll(resp.Body)
respBody, err := ioutil.ReadAll(resp.Body)
require.NoError(t, resp.Body.Close())
require.NoError(t, err)

Expand All @@ -175,7 +176,7 @@ func TestServer_ServeHTTP_error(t *testing.T) {
resp, err = http.DefaultTransport.RoundTrip(req)
require.NoError(t, err)

respBody, err = io.ReadAll(resp.Body)
respBody, err = ioutil.ReadAll(resp.Body)
require.NoError(t, resp.Body.Close())
require.NoError(t, err)

Expand All @@ -190,7 +191,7 @@ func TestServer_ServeHTTP_error(t *testing.T) {
resp, err = http.DefaultTransport.RoundTrip(req)
require.NoError(t, err)

respBody, err = io.ReadAll(resp.Body)
respBody, err = ioutil.ReadAll(resp.Body)
require.NoError(t, resp.Body.Close())
require.NoError(t, err)

Expand All @@ -205,7 +206,7 @@ func TestServer_ServeHTTP_error(t *testing.T) {
resp, err = http.DefaultTransport.RoundTrip(req)
require.NoError(t, err)

respBody, err = io.ReadAll(resp.Body)
respBody, err = ioutil.ReadAll(resp.Body)
require.NoError(t, resp.Body.Close())
require.NoError(t, err)

Expand Down Expand Up @@ -249,7 +250,7 @@ func TestServer_ServeHTTP_concurrency(t *testing.T) {
resp, err := http.DefaultTransport.RoundTrip(req)
require.NoError(t, err)

respBody, err := io.ReadAll(resp.Body)
respBody, err := ioutil.ReadAll(resp.Body)
require.NoError(t, resp.Body.Close())
require.NoError(t, err)

Expand Down Expand Up @@ -300,7 +301,7 @@ func TestServer_vars(t *testing.T) {
resp, err := http.DefaultTransport.RoundTrip(req)
require.NoError(t, err)

body, err := io.ReadAll(resp.Body)
body, err := ioutil.ReadAll(resp.Body)
require.NoError(t, err)

require.NoError(t, resp.Body.Close())
Expand Down Expand Up @@ -339,7 +340,7 @@ func TestServer_ExpectAsync(t *testing.T) {
resp, err := http.DefaultTransport.RoundTrip(req)
require.NoError(t, err)

body, err := io.ReadAll(resp.Body)
body, err := ioutil.ReadAll(resp.Body)
require.NoError(t, err)

require.NoError(t, resp.Body.Close())
Expand All @@ -356,7 +357,7 @@ func TestServer_ExpectAsync(t *testing.T) {
resp, err := http.DefaultTransport.RoundTrip(req)
require.NoError(t, err)

body, err := io.ReadAll(resp.Body)
body, err := ioutil.ReadAll(resp.Body)
require.NoError(t, err)

require.NoError(t, resp.Body.Close())
Expand All @@ -370,7 +371,7 @@ func TestServer_ExpectAsync(t *testing.T) {
resp, err := http.DefaultTransport.RoundTrip(req)
require.NoError(t, err)

body, err := io.ReadAll(resp.Body)
body, err := ioutil.ReadAll(resp.Body)
require.NoError(t, err)

require.NoError(t, resp.Body.Close())
Expand Down

0 comments on commit ad8f1a6

Please sign in to comment.