Skip to content

Commit 9ad50a3

Browse files
authored
chore(storage): remove references to ioutil (#11953)
1 parent d2e6583 commit 9ad50a3

File tree

7 files changed

+22
-28
lines changed

7 files changed

+22
-28
lines changed

storage/conformance_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"encoding/base64"
2020
"encoding/json"
2121
"fmt"
22-
"io/ioutil"
2322
"net/url"
2423
"os"
2524
"strconv"
@@ -230,7 +229,7 @@ func headersAsSlice(m map[string]string) []string {
230229
func parseFiles(t *testing.T) (googleAccessID, privateKey string, testFiles []*storage_v1_tests.TestFile) {
231230
dir := "internal/test/conformance"
232231

233-
inBytes, err := ioutil.ReadFile(dir + "/service-account")
232+
inBytes, err := os.ReadFile(dir + "/service-account")
234233
if err != nil {
235234
t.Fatal(err)
236235
}

storage/example_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"fmt"
2222
"hash/crc32"
2323
"io"
24-
"io/ioutil"
2524
"log"
2625
"mime/multipart"
2726
"net/http"
@@ -273,7 +272,7 @@ func ExampleObjectIterator_Next() {
273272
}
274273

275274
func ExampleSignedURL() {
276-
pkey, err := ioutil.ReadFile("my-private-key.pem")
275+
pkey, err := os.ReadFile("my-private-key.pem")
277276
if err != nil {
278277
// TODO: handle error.
279278
}
@@ -351,7 +350,7 @@ func ExampleObjectHandle_NewReader() {
351350
if err != nil {
352351
// TODO: handle error.
353352
}
354-
slurp, err := ioutil.ReadAll(rc)
353+
slurp, err := io.ReadAll(rc)
355354
rc.Close()
356355
if err != nil {
357356
// TODO: handle error.
@@ -372,7 +371,7 @@ func ExampleObjectHandle_NewRangeReader() {
372371
}
373372
defer rc.Close()
374373

375-
slurp, err := ioutil.ReadAll(rc)
374+
slurp, err := io.ReadAll(rc)
376375
if err != nil {
377376
// TODO: handle error.
378377
}
@@ -392,7 +391,7 @@ func ExampleObjectHandle_NewRangeReader_lastNBytes() {
392391
}
393392
defer rc.Close()
394393

395-
slurp, err := ioutil.ReadAll(rc)
394+
slurp, err := io.ReadAll(rc)
396395
if err != nil {
397396
// TODO: handle error.
398397
}
@@ -412,7 +411,7 @@ func ExampleObjectHandle_NewRangeReader_untilEnd() {
412411
}
413412
defer rc.Close()
414413

415-
slurp, err := ioutil.ReadAll(rc)
414+
slurp, err := io.ReadAll(rc)
416415
if err != nil {
417416
// TODO: handle error.
418417
}

storage/http_client.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"fmt"
2222
"hash/crc32"
2323
"io"
24-
"io/ioutil"
2524
"log"
2625
"net/http"
2726
"net/url"
@@ -1428,7 +1427,7 @@ func readerReopen(ctx context.Context, header http.Header, params *newRangeReade
14281427
// https://cloud.google.com/storage/docs/transcoding#range,
14291428
// thus we have to manually move the body forward by seen bytes.
14301429
if decompressiveTranscoding(res) && seen > 0 {
1431-
_, _ = io.CopyN(ioutil.Discard, res.Body, seen)
1430+
_, _ = io.CopyN(io.Discard, res.Body, seen)
14321431
}
14331432

14341433
// If a generation hasn't been specified, and this is the first response we get, let's record the

storage/mock_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"encoding/json"
2020
"fmt"
2121
"io"
22-
"io/ioutil"
2322
"net/http"
2423
"strings"
2524
"testing"
@@ -46,7 +45,7 @@ func (t *mockTransport) RoundTrip(req *http.Request) (*http.Response, error) {
4645
t.gotReq = req
4746
t.gotBody = nil
4847
if req.Body != nil {
49-
bytes, err := ioutil.ReadAll(req.Body)
48+
bytes, err := io.ReadAll(req.Body)
5049
if err != nil {
5150
return nil, err
5251
}
@@ -78,5 +77,5 @@ func mockClient(t *testing.T, m *mockTransport, opts ...option.ClientOption) *Cl
7877
}
7978

8079
func bodyReader(s string) io.ReadCloser {
81-
return ioutil.NopCloser(strings.NewReader(s))
80+
return io.NopCloser(strings.NewReader(s))
8281
}

storage/reader_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"errors"
2222
"fmt"
2323
"io"
24-
"io/ioutil"
2524
"net/http"
2625
"net/http/httptest"
2726
"net/url"
@@ -60,7 +59,7 @@ func TestRangeReader(t *testing.T) {
6059
t.Errorf("%d/%d: %v", test.offset, test.length, err)
6160
continue
6261
}
63-
gotb, err := ioutil.ReadAll(r)
62+
gotb, err := io.ReadAll(r)
6463
if err != nil {
6564
t.Errorf("%d/%d: %v", test.offset, test.length, err)
6665
continue
@@ -472,7 +471,7 @@ func TestContentEncodingGzipWithReader(t *testing.T) {
472471
}
473472
defer rd.Close()
474473

475-
got, err := ioutil.ReadAll(rd)
474+
got, err := io.ReadAll(rd)
476475
if err != nil {
477476
t.Fatal(err)
478477
}
@@ -540,7 +539,7 @@ func TestMetadataParsingWithReader(t *testing.T) {
540539
t.Fatalf("metadata mismatch diff got vs want: %v", diff)
541540
}
542541

543-
got, err := ioutil.ReadAll(rd)
542+
got, err := io.ReadAll(rd)
544543
if err != nil {
545544
t.Fatal(err)
546545
}

storage/retry_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"context"
1818
"errors"
1919
"fmt"
20-
"io/ioutil"
20+
"io"
2121
"net/http"
2222
"net/http/httptest"
2323
"strings"
@@ -100,7 +100,7 @@ func TestIndefiniteRetries(t *testing.T) {
100100
}
101101

102102
// Consume the body since we can accept this body.
103-
ioutil.ReadAll(r.Body)
103+
io.ReadAll(r.Body)
104104
w.Header().Set("X-Http-Status-Code-Override", "308")
105105
return
106106

storage/storage_test.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"encoding/json"
2121
"fmt"
2222
"io"
23-
"io/ioutil"
2423
"log"
2524
"net"
2625
"net/http"
@@ -697,7 +696,7 @@ func TestPathEncodeV4(t *testing.T) {
697696
}
698697

699698
func dummyKey(kind string) []byte {
700-
slurp, err := ioutil.ReadFile(fmt.Sprintf("./internal/test/dummy_%s", kind))
699+
slurp, err := os.ReadFile(fmt.Sprintf("./internal/test/dummy_%s", kind))
701700
if err != nil {
702701
log.Fatal(err)
703702
}
@@ -793,7 +792,7 @@ func TestCondition(t *testing.T) {
793792
t.Parallel()
794793
gotReq := make(chan *http.Request, 1)
795794
hc, close := newTestServer(func(w http.ResponseWriter, r *http.Request) {
796-
io.Copy(ioutil.Discard, r.Body)
795+
io.Copy(io.Discard, r.Body)
797796
gotReq <- r
798797
w.WriteHeader(200)
799798
})
@@ -1441,7 +1440,7 @@ func TestObjectCompose(t *testing.T) {
14411440
gotURL := make(chan string, 1)
14421441
gotBody := make(chan []byte, 1)
14431442
hc, close := newTestServer(func(w http.ResponseWriter, r *http.Request) {
1444-
body, _ := ioutil.ReadAll(r.Body)
1443+
body, _ := io.ReadAll(r.Body)
14451444
gotURL <- r.URL.String()
14461445
gotBody <- body
14471446
w.Write([]byte("{}"))
@@ -1640,7 +1639,7 @@ func TestObjectCompose(t *testing.T) {
16401639
func TestEmptyObjectIterator(t *testing.T) {
16411640
t.Parallel()
16421641
hClient, close := newTestServer(func(w http.ResponseWriter, r *http.Request) {
1643-
io.Copy(ioutil.Discard, r.Body)
1642+
io.Copy(io.Discard, r.Body)
16441643
fmt.Fprintf(w, "{}")
16451644
})
16461645
defer close()
@@ -1661,7 +1660,7 @@ func TestEmptyObjectIterator(t *testing.T) {
16611660
func TestEmptyBucketIterator(t *testing.T) {
16621661
t.Parallel()
16631662
hClient, close := newTestServer(func(w http.ResponseWriter, r *http.Request) {
1664-
io.Copy(ioutil.Discard, r.Body)
1663+
io.Copy(io.Discard, r.Body)
16651664
fmt.Fprintf(w, "{}")
16661665
})
16671666
defer close()
@@ -1698,7 +1697,7 @@ func TestUserProject(t *testing.T) {
16981697
ctx := context.Background()
16991698
gotURL := make(chan *url.URL, 1)
17001699
hClient, close := newTestServer(func(w http.ResponseWriter, r *http.Request) {
1701-
io.Copy(ioutil.Discard, r.Body)
1700+
io.Copy(io.Discard, r.Body)
17021701
gotURL <- r.URL
17031702
if strings.Contains(r.URL.String(), "/rewriteTo/") {
17041703
res := &raw.RewriteResponse{Done: true}
@@ -2202,7 +2201,7 @@ func TestOperationsWithEndpoint(t *testing.T) {
22022201

22032202
hClient, closeServer := newTestServer(func(w http.ResponseWriter, r *http.Request) {
22042203
done := make(chan bool, 1)
2205-
io.Copy(ioutil.Discard, r.Body)
2204+
io.Copy(io.Discard, r.Body)
22062205
fmt.Fprintf(w, "{}")
22072206
go func() {
22082207
gotHost <- r.Host
@@ -2308,7 +2307,7 @@ func TestOperationsWithEndpoint(t *testing.T) {
23082307
return err
23092308
}
23102309

2311-
_, err = io.Copy(ioutil.Discard, rc)
2310+
_, err = io.Copy(io.Discard, rc)
23122311
if err != nil {
23132312
return err
23142313
}

0 commit comments

Comments
 (0)