mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 11:42:12 +08:00
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:
@ -5,8 +5,9 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
@ -86,7 +87,7 @@ func TestPlugins(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, tc.expStatus, resp.StatusCode)
|
||||
b, err := ioutil.ReadAll(resp.Body)
|
||||
b, err := io.ReadAll(resp.Body)
|
||||
require.NoError(t, err)
|
||||
|
||||
expResp := expectedResp(t, tc.expRespPath)
|
||||
@ -128,7 +129,7 @@ func makePostRequest(t *testing.T, URL string) (int, map[string]interface{}) {
|
||||
_ = resp.Body.Close()
|
||||
fmt.Printf("Failed to close response body err: %s", err)
|
||||
})
|
||||
b, err := ioutil.ReadAll(resp.Body)
|
||||
b, err := io.ReadAll(resp.Body)
|
||||
require.NoError(t, err)
|
||||
|
||||
var body = make(map[string]interface{})
|
||||
@ -144,7 +145,7 @@ func grafanaAPIURL(username string, grafanaListedAddr string, path string) strin
|
||||
|
||||
func expectedResp(t *testing.T, filename string) string {
|
||||
//nolint:GOSEC
|
||||
contents, err := ioutil.ReadFile(filepath.Join("data", filename))
|
||||
contents, err := os.ReadFile(filepath.Join("data", filename))
|
||||
if err != nil {
|
||||
t.Errorf("failed to load %s: %v", filename, err)
|
||||
}
|
||||
@ -153,7 +154,7 @@ func expectedResp(t *testing.T, filename string) string {
|
||||
}
|
||||
|
||||
func updateRespSnapshot(t *testing.T, filename string, body string) {
|
||||
err := ioutil.WriteFile(filepath.Join("data", filename), []byte(body), 0600)
|
||||
err := os.WriteFile(filepath.Join("data", filename), []byte(body), 0600)
|
||||
if err != nil {
|
||||
t.Errorf("error writing snapshot %s: %v", filename, err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user