Handle ioutil deprecations (#53526)

* replace ioutil.ReadFile -> os.ReadFile

* replace ioutil.ReadAll -> io.ReadAll

* replace ioutil.TempFile -> os.CreateTemp

* replace ioutil.NopCloser -> io.NopCloser

* replace ioutil.WriteFile -> os.WriteFile

* replace ioutil.TempDir -> os.MkdirTemp

* replace ioutil.Discard -> io.Discard
This commit is contained in:
Jo
2022-08-10 15:37:51 +02:00
committed by GitHub
parent 4926767737
commit 062d255124
140 changed files with 462 additions and 492 deletions
@@ -2,7 +2,7 @@ package httpclient
import (
"fmt"
"io/ioutil"
"io"
"strings"
"testing"
@@ -20,14 +20,14 @@ func TestCountBytesReader(t *testing.T) {
for index, tc := range tcs {
t.Run(fmt.Sprintf("Test CountBytesReader %d", index), func(t *testing.T) {
body := ioutil.NopCloser(strings.NewReader(tc.body))
body := io.NopCloser(strings.NewReader(tc.body))
var actualBytesRead int64
readCloser := CountBytesReader(body, func(bytesRead int64) {
actualBytesRead = bytesRead
})
bodyBytes, err := ioutil.ReadAll(readCloser)
bodyBytes, err := io.ReadAll(readCloser)
require.NoError(t, err)
err = readCloser.Close()
require.NoError(t, err)
@@ -4,7 +4,7 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"
"testing"
@@ -27,7 +27,7 @@ func TestResponseLimitMiddleware(t *testing.T) {
for _, tc := range tcs {
t.Run(fmt.Sprintf("Test ResponseLimitMiddleware with limit: %d", tc.limit), func(t *testing.T) {
finalRoundTripper := httpclient.RoundTripperFunc(func(req *http.Request) (*http.Response, error) {
return &http.Response{StatusCode: http.StatusOK, Request: req, Body: ioutil.NopCloser(strings.NewReader("dummy"))}, nil
return &http.Response{StatusCode: http.StatusOK, Request: req, Body: io.NopCloser(strings.NewReader("dummy"))}, nil
})
mw := ResponseLimitMiddleware(tc.limit)
@@ -46,7 +46,7 @@ func TestResponseLimitMiddleware(t *testing.T) {
require.NotNil(t, res.Body)
require.NoError(t, res.Body.Close())
bodyBytes, err := ioutil.ReadAll(res.Body)
bodyBytes, err := io.ReadAll(res.Body)
if err != nil {
require.EqualError(t, tc.err, err.Error())
} else {
@@ -2,7 +2,7 @@ package httpclientprovider
import (
"bytes"
"io/ioutil"
"io"
"net/http"
"github.com/grafana/grafana-plugin-sdk-go/backend/httpclient"
@@ -18,7 +18,7 @@ func (c *testContext) createRoundTripper(name string) http.RoundTripper {
return &http.Response{
StatusCode: http.StatusOK,
Request: req,
Body: ioutil.NopCloser(bytes.NewBufferString("")),
Body: io.NopCloser(bytes.NewBufferString("")),
}, nil
})
}
@@ -3,7 +3,7 @@ package httpclient
import (
"errors"
"fmt"
"io/ioutil"
"io"
"strings"
"testing"
@@ -23,10 +23,10 @@ func TestMaxBytesReader(t *testing.T) {
}
for _, tc := range tcs {
t.Run(fmt.Sprintf("Test MaxBytesReader with limit: %d", tc.limit), func(t *testing.T) {
body := ioutil.NopCloser(strings.NewReader("dummy"))
body := io.NopCloser(strings.NewReader("dummy"))
readCloser := MaxBytesReader(body, tc.limit)
bodyBytes, err := ioutil.ReadAll(readCloser)
bodyBytes, err := io.ReadAll(readCloser)
if err != nil {
require.EqualError(t, tc.err, err.Error())
} else {