Remove deprecated io/ioutil (#15707)

This commit is contained in:
Klaus Post
2022-09-19 20:05:16 +02:00
committed by GitHub
parent 0b6175b742
commit ff12080ff5
89 changed files with 315 additions and 370 deletions
+19 -20
View File
@@ -23,7 +23,6 @@ import (
"encoding/xml"
"fmt"
"io"
"io/ioutil"
"math/rand"
"net/http"
"net/url"
@@ -34,7 +33,7 @@ import (
"testing"
"time"
humanize "github.com/dustin/go-humanize"
"github.com/dustin/go-humanize"
"github.com/minio/minio-go/v7/pkg/set"
xhttp "github.com/minio/minio/internal/http"
"github.com/minio/pkg/bucket/policy"
@@ -65,7 +64,7 @@ func (c *check) Assert(gotValue interface{}, expectedValue interface{}) {
}
func verifyError(c *check, response *http.Response, code, description string, statusCode int) {
data, err := ioutil.ReadAll(response.Body)
data, err := io.ReadAll(response.Body)
c.Assert(err, nil)
errorResponse := APIErrorResponse{}
err = xml.Unmarshal(data, &errorResponse)
@@ -384,7 +383,7 @@ func (s *TestSuiteCommon) TestBucketPolicy(c *check) {
c.Assert(err, nil)
c.Assert(response.StatusCode, http.StatusOK)
bucketPolicyReadBuf, err := ioutil.ReadAll(response.Body)
bucketPolicyReadBuf, err := io.ReadAll(response.Body)
c.Assert(err, nil)
// Verify if downloaded policy matches with previously uploaded.
expectedPolicy, err := policy.ParseConfig(strings.NewReader(bucketPolicyStr), bucketName)
@@ -593,7 +592,7 @@ func (s *TestSuiteCommon) TestDeleteMultipleObjects(c *check) {
c.Assert(response.StatusCode, http.StatusOK)
deleteResp := DeleteObjectsResponse{}
delRespBytes, err := ioutil.ReadAll(response.Body)
delRespBytes, err := io.ReadAll(response.Body)
c.Assert(err, nil)
err = xml.Unmarshal(delRespBytes, &deleteResp)
c.Assert(err, nil)
@@ -616,7 +615,7 @@ func (s *TestSuiteCommon) TestDeleteMultipleObjects(c *check) {
c.Assert(response.StatusCode, http.StatusOK)
deleteResp = DeleteObjectsResponse{}
delRespBytes, err = ioutil.ReadAll(response.Body)
delRespBytes, err = io.ReadAll(response.Body)
c.Assert(err, nil)
err = xml.Unmarshal(delRespBytes, &deleteResp)
c.Assert(err, nil)
@@ -756,7 +755,7 @@ func (s *TestSuiteCommon) TestEmptyObject(c *check) {
var buffer bytes.Buffer
// extract the body of the response.
responseBody, err := ioutil.ReadAll(response.Body)
responseBody, err := io.ReadAll(response.Body)
c.Assert(err, nil)
// assert the http response body content.
c.Assert(true, bytes.Equal(responseBody, buffer.Bytes()))
@@ -877,7 +876,7 @@ func (s *TestSuiteCommon) TestMultipleObjects(c *check) {
c.Assert(response.StatusCode, http.StatusOK)
// extract the response body.
responseBody, err := ioutil.ReadAll(response.Body)
responseBody, err := io.ReadAll(response.Body)
c.Assert(err, nil)
// assert the content body for the expected object data.
c.Assert(true, bytes.Equal(responseBody, []byte("hello one")))
@@ -906,7 +905,7 @@ func (s *TestSuiteCommon) TestMultipleObjects(c *check) {
c.Assert(response.StatusCode, http.StatusOK)
// verify response data
responseBody, err = ioutil.ReadAll(response.Body)
responseBody, err = io.ReadAll(response.Body)
c.Assert(err, nil)
c.Assert(true, bytes.Equal(responseBody, []byte("hello two")))
@@ -933,7 +932,7 @@ func (s *TestSuiteCommon) TestMultipleObjects(c *check) {
c.Assert(response.StatusCode, http.StatusOK)
// verify object.
responseBody, err = ioutil.ReadAll(response.Body)
responseBody, err = io.ReadAll(response.Body)
c.Assert(err, nil)
c.Assert(true, bytes.Equal(responseBody, []byte("hello three")))
}
@@ -1059,7 +1058,7 @@ func (s *TestSuiteCommon) TestCopyObject(c *check) {
c.Assert(response.StatusCode, http.StatusOK)
// reading the response body.
// response body is expected to have the copied content of the first uploaded object.
object, err := ioutil.ReadAll(response.Body)
object, err := io.ReadAll(response.Body)
c.Assert(err, nil)
c.Assert(string(object), "hello world")
}
@@ -1233,7 +1232,7 @@ func (s *TestSuiteCommon) TestSHA256Mismatch(c *check) {
// Set the body to generate signature mismatch.
helloReader := bytes.NewReader([]byte("Hello, World"))
request.ContentLength = helloReader.Size()
request.Body = ioutil.NopCloser(helloReader)
request.Body = io.NopCloser(helloReader)
c.Assert(err, nil)
// execute the HTTP request.
@@ -1562,7 +1561,7 @@ func (s *TestSuiteCommon) TestPartialContent(c *check) {
response, err = s.client.Do(request)
c.Assert(err, nil)
c.Assert(response.StatusCode, http.StatusPartialContent)
partialObject, err := ioutil.ReadAll(response.Body)
partialObject, err := io.ReadAll(response.Body)
c.Assert(err, nil)
c.Assert(string(partialObject), "Wo")
@@ -1628,7 +1627,7 @@ func (s *TestSuiteCommon) TestListObjectsHandler(c *check) {
c.Assert(err, nil)
c.Assert(response.StatusCode, http.StatusOK)
getContent, err := ioutil.ReadAll(response.Body)
getContent, err := io.ReadAll(response.Body)
c.Assert(err, nil)
for _, expectedStr := range testCase.expectedStrings {
@@ -1703,7 +1702,7 @@ func (s *TestSuiteCommon) TestListObjectsSpecialCharactersHandler(c *check) {
c.Assert(err, nil)
c.Assert(response.StatusCode, http.StatusOK)
getContent, err := ioutil.ReadAll(response.Body)
getContent, err := io.ReadAll(response.Body)
c.Assert(err, nil)
for _, expectedStr := range testCase.expectedStrings {
@@ -1837,7 +1836,7 @@ func (s *TestSuiteCommon) TestGetObjectLarge10MiB(c *check) {
c.Assert(err, nil)
c.Assert(response.StatusCode, http.StatusOK)
// extract the content from response body.
getContent, err := ioutil.ReadAll(response.Body)
getContent, err := io.ReadAll(response.Body)
c.Assert(err, nil)
// Compare putContent and getContent.
@@ -1898,7 +1897,7 @@ func (s *TestSuiteCommon) TestGetObjectLarge11MiB(c *check) {
c.Assert(err, nil)
c.Assert(response.StatusCode, http.StatusOK)
// fetch the content from response body.
getContent, err := ioutil.ReadAll(response.Body)
getContent, err := io.ReadAll(response.Body)
c.Assert(err, nil)
// Get etag of the response content.
@@ -1986,7 +1985,7 @@ func (s *TestSuiteCommon) TestGetPartialObjectMisAligned(c *check) {
// Since only part of the object is requested, expecting response status to be http.StatusPartialContent .
c.Assert(response.StatusCode, http.StatusPartialContent)
// parse the HTTP response body.
getContent, err := ioutil.ReadAll(response.Body)
getContent, err := io.ReadAll(response.Body)
c.Assert(err, nil)
// Compare putContent and getContent.
@@ -2052,7 +2051,7 @@ func (s *TestSuiteCommon) TestGetPartialObjectLarge11MiB(c *check) {
// Since only part of the object is requested, expecting response status to be http.StatusPartialContent .
c.Assert(response.StatusCode, http.StatusPartialContent)
// read the downloaded content from the response body.
getContent, err := ioutil.ReadAll(response.Body)
getContent, err := io.ReadAll(response.Body)
c.Assert(err, nil)
// Compare putContent and getContent.
@@ -2119,7 +2118,7 @@ func (s *TestSuiteCommon) TestGetPartialObjectLarge10MiB(c *check) {
// Since only part of the object is requested, expecting response status to be http.StatusPartialContent .
c.Assert(response.StatusCode, http.StatusPartialContent)
// read the downloaded content from the response body.
getContent, err := ioutil.ReadAll(response.Body)
getContent, err := io.ReadAll(response.Body)
c.Assert(err, nil)
// Compare putContent and getContent.