Skip to content

Commit

Permalink
Merge pull request #58 from xmidt-org/hotfix/delint
Browse files Browse the repository at this point in the history
chore: delint ioutil
  • Loading branch information
johnabass authored Jul 6, 2023
2 parents 8365bf3 + c51c576 commit d03ec37
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 28 deletions.
3 changes: 1 addition & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package httpaux

import (
"io"
"io/ioutil"
"net/http"
)

Expand All @@ -20,7 +19,7 @@ var _ Client = (*http.Client)(nil)
// does nothing.
func Cleanup(r *http.Response) {
if r != nil && r.Body != nil {
io.Copy(ioutil.Discard, r.Body)
io.Copy(io.Discard, r.Body)
r.Body.Close()
}
}
3 changes: 1 addition & 2 deletions client/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package client
import (
"errors"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"strconv"
Expand Down Expand Up @@ -77,7 +76,7 @@ func (suite *ChainTestSuite) assertRequest(expectedOrder []int, client httpaux.C
suite.Require().NoError(err)

defer response.Body.Close()
io.Copy(ioutil.Discard, response.Body)
io.Copy(io.Discard, response.Body)
suite.Equal(expectedOrder, suite.order, "the decorators did not run in the expected order")
suite.Equal(299, response.StatusCode, "the test server was not invoked")
}
Expand Down
4 changes: 2 additions & 2 deletions erraux/encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package erraux
import (
"context"
"errors"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"testing"
Expand All @@ -29,7 +29,7 @@ func (suite *EncoderTestSuite) result(rw *httptest.ResponseRecorder) (statusCode
h = result.Header
suite.Equal("application/json", h.Get("Content-Type"))

b, err := ioutil.ReadAll(result.Body)
b, err := io.ReadAll(result.Body)
suite.Require().NoError(err)
body = string(b)

Expand Down
17 changes: 8 additions & 9 deletions gate/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package gate
import (
"errors"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -174,7 +173,7 @@ func (suite *ClientTestSuite) TestDefaultOpen() {
suite.NoError(err)
suite.Require().NotNil(response)
suite.Equal(277, response.StatusCode)
io.Copy(ioutil.Discard, response.Body)
io.Copy(io.Discard, response.Body)
response.Body.Close()
})

Expand All @@ -185,7 +184,7 @@ func (suite *ClientTestSuite) TestDefaultOpen() {
suite.NoError(err)
suite.Require().NotNil(response)
suite.Equal(277, response.StatusCode)
io.Copy(ioutil.Discard, response.Body)
io.Copy(io.Discard, response.Body)
response.Body.Close()
})
}
Expand All @@ -198,7 +197,7 @@ func (suite *ClientTestSuite) TestDefaultClosed() {
response, err := suite.checkRoundTripper(rt)

if !suite.Nil(response) {
io.Copy(ioutil.Discard, response.Body)
io.Copy(io.Discard, response.Body)
response.Body.Close()
}

Expand All @@ -210,7 +209,7 @@ func (suite *ClientTestSuite) TestDefaultClosed() {
response, err := suite.checkRoundTripper(rt)

if !suite.Nil(response) {
io.Copy(ioutil.Discard, response.Body)
io.Copy(io.Discard, response.Body)
response.Body.Close()
}

Expand All @@ -229,7 +228,7 @@ func (suite *ClientTestSuite) TestCustomOpen() {
suite.NoError(err)
suite.Require().NotNil(response)
suite.Equal(277, response.StatusCode)
io.Copy(ioutil.Discard, response.Body)
io.Copy(io.Discard, response.Body)
response.Body.Close()
})

Expand All @@ -243,7 +242,7 @@ func (suite *ClientTestSuite) TestCustomOpen() {
suite.NoError(err)
suite.Require().NotNil(response)
suite.Equal(277, response.StatusCode)
io.Copy(ioutil.Discard, response.Body)
io.Copy(io.Discard, response.Body)
response.Body.Close()
})
}
Expand All @@ -259,7 +258,7 @@ func (suite *ClientTestSuite) TestCustomClosed() {
response, err := suite.checkRoundTripper(rt)

if !suite.Nil(response) {
io.Copy(ioutil.Discard, response.Body)
io.Copy(io.Discard, response.Body)
response.Body.Close()
}

Expand All @@ -274,7 +273,7 @@ func (suite *ClientTestSuite) TestCustomClosed() {
response, err := suite.checkRoundTripper(rt)

if !suite.Nil(response) {
io.Copy(ioutil.Discard, response.Body)
io.Copy(io.Discard, response.Body)
response.Body.Close()
}

Expand Down
5 changes: 2 additions & 3 deletions httpmock/body_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"testing"

"github.com/stretchr/testify/suite"
Expand All @@ -17,7 +16,7 @@ type BodyReadCloserTestSuite struct {
func (suite *BodyReadCloserTestSuite) testBodyReadCloser(body *BodyReadCloser, expected []byte) {
suite.Require().NotNil(body)

actual, err := ioutil.ReadAll(body)
actual, err := io.ReadAll(body)
suite.Equal(expected, actual)
suite.NoError(err)

Expand Down Expand Up @@ -58,7 +57,7 @@ func (suite *BodyReadCloserTestSuite) TestBodyf() {
}

func (suite *BodyReadCloserTestSuite) TestNopCloser() {
body := ioutil.NopCloser(
body := io.NopCloser(
bytes.NewBufferString("this body doesn't implement Closeable"),
)

Expand Down
5 changes: 2 additions & 3 deletions httpmock/requestChecker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package httpmock
import (
"errors"
"io"
"io/ioutil"
"net/http"
"net/url"
"strconv"
Expand Down Expand Up @@ -370,7 +369,7 @@ func (suite *RequestCheckerTestSuite) TestBody() {
}()

request := &http.Request{
Body: ioutil.NopCloser(reader),
Body: io.NopCloser(reader),
}

t := wrapTestingT(suite.T())
Expand Down Expand Up @@ -462,7 +461,7 @@ func (suite *RequestCheckerTestSuite) TestBodyJSON() {
}()

request := &http.Request{
Body: ioutil.NopCloser(reader),
Body: io.NopCloser(reader),
}

t := wrapTestingT(suite.T())
Expand Down
3 changes: 1 addition & 2 deletions httpmock/roundTripper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package httpmock
import (
"errors"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
Expand Down Expand Up @@ -32,7 +31,7 @@ func (suite *RoundTripperSuite) assertResponse(r *http.Response) {

if suite.NotNil(r.Body) {
defer r.Body.Close()
b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
if suite.NoError(err) {
suite.Equal("RoundTripperSuite", string(b))
}
Expand Down
5 changes: 2 additions & 3 deletions retry/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"context"
"errors"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"strconv"
Expand Down Expand Up @@ -86,7 +85,7 @@ func (suite *ClientTestSuite) handler(rw http.ResponseWriter, actual *http.Reque
suite.Equal(suite.expected.URL.Path, actual.URL.Path)
suite.Equal(int64(len(suite.expectedBody)), actual.ContentLength)

b, err := ioutil.ReadAll(actual.Body)
b, err := io.ReadAll(actual.Body)
suite.NoError(err)
suite.Equal(suite.expectedBody, string(b))

Expand All @@ -105,7 +104,7 @@ func (suite *ClientTestSuite) assertResponse(r *http.Response) {

suite.Require().NotNil(r.Body)
defer r.Body.Close()
b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
suite.NoError(err)
suite.Equal("ClientTestSuite", string(b))
}
Expand Down
3 changes: 1 addition & 2 deletions roundtrip/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package roundtrip
import (
"errors"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"strconv"
Expand Down Expand Up @@ -80,7 +79,7 @@ func (suite *ChainTestSuite) assertRequest(expectedOrder []int, transport http.R
suite.Require().NoError(err)

defer response.Body.Close()
io.Copy(ioutil.Discard, response.Body)
io.Copy(io.Discard, response.Body)
suite.Equal(expectedOrder, suite.order, "the decorators did not run in the expected order")
suite.Equal(299, response.StatusCode, "the test server was not invoked")
}
Expand Down

0 comments on commit d03ec37

Please sign in to comment.