Skip to content

Commit 6ac1b9d

Browse files
committed
refactor: fix deprecated for ioutil
1 parent 10fbeed commit 6ac1b9d

8 files changed

+27
-32
lines changed

io/ringbuffer_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package io
33
import (
44
"bytes"
55
"io"
6-
"io/ioutil"
76
"strconv"
87
"strings"
98
"testing"
@@ -449,7 +448,7 @@ func TestRingBufferWriteRead(t *testing.T) {
449448
t.Errorf("expect %v, got %v", e, a)
450449
}
451450

452-
actual, err := ioutil.ReadAll(ringBuffer)
451+
actual, err := io.ReadAll(ringBuffer)
453452
if err != nil {
454453
t.Errorf("unexpected error, %v", err)
455454
return

middleware/logging_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package middleware_test
22

33
import (
44
"context"
5-
"io/ioutil"
5+
"io"
66
"testing"
77

88
"github.com/aws/smithy-go/logging"
@@ -26,7 +26,7 @@ func TestGetLogger(t *testing.T) {
2626
t.Fatal("expect GetLogger to fallback to Nop")
2727
}
2828

29-
standardLogger := logging.NewStandardLogger(ioutil.Discard)
29+
standardLogger := logging.NewStandardLogger(io.Discard)
3030
ctx := middleware.SetLogger(context.Background(), standardLogger)
3131

3232
if logger := middleware.GetLogger(ctx); logger == nil {

private/protocol/middleware_capture_request_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ package protocol
22

33
import (
44
"context"
5-
"github.com/aws/smithy-go/middleware"
6-
smithytesting "github.com/aws/smithy-go/testing"
7-
smithyhttp "github.com/aws/smithy-go/transport/http"
85
"io"
9-
"io/ioutil"
106
"net/http"
117
"net/url"
128
"strings"
139
"testing"
10+
11+
"github.com/aws/smithy-go/middleware"
12+
smithytesting "github.com/aws/smithy-go/testing"
13+
smithyhttp "github.com/aws/smithy-go/transport/http"
1414
)
1515

1616
// TestAddCaptureRequestMiddleware tests AddCaptureRequestMiddleware
@@ -45,7 +45,7 @@ func TestAddCaptureRequestMiddleware(t *testing.T) {
4545
Path: "test/path",
4646
RawPath: "test/path",
4747
},
48-
Body: ioutil.NopCloser(strings.NewReader("hello world.")),
48+
Body: io.NopCloser(strings.NewReader("hello world.")),
4949
},
5050
ExpectQuery: []smithytesting.QueryItem{
5151
{
@@ -95,11 +95,11 @@ func TestAddCaptureRequestMiddleware(t *testing.T) {
9595
t.Errorf("expect %v path, got %v", e, a)
9696
}
9797
if c.ExpectRequest.Body != nil {
98-
expect, err := ioutil.ReadAll(c.ExpectRequest.Body)
98+
expect, err := io.ReadAll(c.ExpectRequest.Body)
9999
if capturedRequest.Body == nil {
100100
t.Errorf("Expect request stream %v captured, get nil", string(expect))
101101
}
102-
actual, err := ioutil.ReadAll(capturedRequest.Body)
102+
actual, err := io.ReadAll(capturedRequest.Body)
103103
if err != nil {
104104
t.Errorf("unable to read captured request body, %v", err)
105105
}

testing/bytes.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"encoding/hex"
66
"fmt"
77
"io"
8-
"io/ioutil"
98
)
109

1110
// Enumeration values for supported compress Algorithms.
@@ -25,7 +24,7 @@ func CompareReaderEmpty(r io.Reader) error {
2524
if r == nil {
2625
return nil
2726
}
28-
b, err := ioutil.ReadAll(r)
27+
b, err := io.ReadAll(r)
2928
if err != nil && err != io.EOF {
3029
return fmt.Errorf("unable to read from reader, %v", err)
3130
}
@@ -41,7 +40,7 @@ func CompareReaderBytes(r io.Reader, expect []byte) error {
4140
if r == nil {
4241
return fmt.Errorf("missing body")
4342
}
44-
actual, err := ioutil.ReadAll(r)
43+
actual, err := io.ReadAll(r)
4544
if err != nil {
4645
return fmt.Errorf("unable to read, %v", err)
4746
}
@@ -60,7 +59,7 @@ func CompareJSONReaderBytes(r io.Reader, expect []byte) error {
6059
if r == nil {
6160
return fmt.Errorf("missing body")
6261
}
63-
actual, err := ioutil.ReadAll(r)
62+
actual, err := io.ReadAll(r)
6463
if err != nil {
6564
return fmt.Errorf("unable to read, %v", err)
6665
}
@@ -77,7 +76,7 @@ func CompareXMLReaderBytes(r io.Reader, expect []byte) error {
7776
return fmt.Errorf("missing body")
7877
}
7978

80-
actual, err := ioutil.ReadAll(r)
79+
actual, err := io.ReadAll(r)
8180
if err != nil {
8281
return err
8382
}
@@ -95,7 +94,7 @@ func CompareURLFormReaderBytes(r io.Reader, expect []byte) error {
9594
if r == nil {
9695
return fmt.Errorf("missing body")
9796
}
98-
actual, err := ioutil.ReadAll(r)
97+
actual, err := io.ReadAll(r)
9998
if err != nil {
10099
return fmt.Errorf("unable to read, %v", err)
101100
}

testing/struct_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package testing
33
import (
44
"bytes"
55
"io"
6-
"io/ioutil"
76
"math"
87
"strings"
98
"testing"
@@ -83,7 +82,7 @@ func TestCompareValues(t *testing.T) {
8382
Foo io.Reader
8483
Bar int
8584
}{
86-
Foo: ioutil.NopCloser(strings.NewReader("abc123")),
85+
Foo: io.NopCloser(strings.NewReader("abc123")),
8786
Bar: 123,
8887
},
8988
},
@@ -99,7 +98,7 @@ func TestCompareValues(t *testing.T) {
9998
Foo io.Reader
10099
Bar int
101100
}{
102-
Foo: ioutil.NopCloser(strings.NewReader("123abc")),
101+
Foo: io.NopCloser(strings.NewReader("123abc")),
103102
Bar: 123,
104103
},
105104
ExpectErr: "<root>.Foo: bytes do not match",

transport/http/middleware_close_response_body.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ package http
22

33
import (
44
"context"
5+
"io"
6+
57
"github.com/aws/smithy-go/logging"
68
"github.com/aws/smithy-go/middleware"
7-
"io"
8-
"io/ioutil"
99
)
1010

1111
// AddErrorCloseResponseBodyMiddleware adds the middleware to automatically
@@ -30,7 +30,7 @@ func (m *errorCloseResponseBodyMiddleware) HandleDeserialize(
3030
if err != nil {
3131
if resp, ok := out.RawResponse.(*Response); ok && resp != nil && resp.Body != nil {
3232
// Consume the full body to prevent TCP connection resets on some platforms
33-
_, _ = io.Copy(ioutil.Discard, resp.Body)
33+
_, _ = io.Copy(io.Discard, resp.Body)
3434
// Do not validate that the response closes successfully.
3535
resp.Body.Close()
3636
}
@@ -64,7 +64,7 @@ func (m *closeResponseBody) HandleDeserialize(
6464

6565
if resp, ok := out.RawResponse.(*Response); ok {
6666
// Consume the full body to prevent TCP connection resets on some platforms
67-
_, copyErr := io.Copy(ioutil.Discard, resp.Body)
67+
_, copyErr := io.Copy(io.Discard, resp.Body)
6868
if copyErr != nil {
6969
middleware.GetLogger(ctx).Logf(logging.Warn, "failed to discard remaining HTTP response body, this may affect connection reuse")
7070
}

transport/http/middleware_http_logging_test.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"context"
66
"fmt"
77
"io"
8-
"io/ioutil"
98
"net/http"
109
"net/url"
1110
"testing"
@@ -49,7 +48,7 @@ func TestRequestResponseLogger(t *testing.T) {
4948
},
5049
},
5150
},
52-
InputBody: ioutil.NopCloser(bytes.NewReader([]byte(`this is the body`))),
51+
InputBody: io.NopCloser(bytes.NewReader([]byte(`this is the body`))),
5352
ExpectedLog: "Request\n" +
5453
"GET /foo HTTP/1.1\r\n" +
5554
"Host: example.amazonaws.com\r\n" +
@@ -75,7 +74,7 @@ func TestRequestResponseLogger(t *testing.T) {
7574
ContentLength: 16,
7675
},
7776
},
78-
InputBody: ioutil.NopCloser(bytes.NewReader([]byte(`this is the body`))),
77+
InputBody: io.NopCloser(bytes.NewReader([]byte(`this is the body`))),
7978
ExpectedLog: "Request\n" +
8079
"GET /foo HTTP/1.1\r\n" +
8180
"Host: example.amazonaws.com\r\n" +
@@ -98,7 +97,7 @@ func TestRequestResponseLogger(t *testing.T) {
9897
Header: map[string][]string{
9998
"Foo": {"Bar"},
10099
},
101-
Body: ioutil.NopCloser(bytes.NewReader([]byte(`this is the body`))),
100+
Body: io.NopCloser(bytes.NewReader([]byte(`this is the body`))),
102101
},
103102
},
104103
ExpectedLog: "Response\n" +
@@ -119,7 +118,7 @@ func TestRequestResponseLogger(t *testing.T) {
119118
Header: map[string][]string{
120119
"Foo": {"Bar"},
121120
},
122-
Body: ioutil.NopCloser(bytes.NewReader([]byte(`this is the body`))),
121+
Body: io.NopCloser(bytes.NewReader([]byte(`this is the body`))),
123122
},
124123
},
125124
ExpectedLog: "Response\n" +

transport/http/request.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"fmt"
66
"io"
7-
"io/ioutil"
87
"net/http"
98
"net/url"
109
"strings"
@@ -167,15 +166,15 @@ func (r *Request) Build(ctx context.Context) *http.Request {
167166

168167
switch stream := r.stream.(type) {
169168
case *io.PipeReader:
170-
req.Body = ioutil.NopCloser(stream)
169+
req.Body = io.NopCloser(stream)
171170
req.ContentLength = -1
172171
default:
173172
// HTTP Client Request must only have a non-nil body if the
174173
// ContentLength is explicitly unknown (-1) or non-zero. The HTTP
175174
// Client will interpret a non-nil body and ContentLength 0 as
176175
// "unknown". This is unwanted behavior.
177176
if req.ContentLength != 0 && r.stream != nil {
178-
req.Body = iointernal.NewSafeReadCloser(ioutil.NopCloser(stream))
177+
req.Body = iointernal.NewSafeReadCloser(io.NopCloser(stream))
179178
}
180179
}
181180

0 commit comments

Comments
 (0)