Replace usage of io/ioutil package (#9613)

`io/ioutil` has been deprecated since go 1.16 and the linter started to
complain about it.
This commit is contained in:
Alejandro Pedraza 2022-10-13 12:10:58 -05:00 committed by GitHub
parent 90a893194e
commit e6fa5a7156
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 76 additions and 86 deletions

View File

@ -4,7 +4,7 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"os"
"testing"
"github.com/linkerd/linkerd2/pkg/healthcheck"
@ -33,7 +33,7 @@ func TestCheckStatus(t *testing.T) {
output := bytes.NewBufferString("")
healthcheck.RunChecks(output, stderr, hc, tableOutput)
goldenFileBytes, err := ioutil.ReadFile("testdata/check_output.golden")
goldenFileBytes, err := os.ReadFile("testdata/check_output.golden")
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
@ -67,7 +67,7 @@ func TestCheckStatus(t *testing.T) {
output := bytes.NewBufferString("")
healthcheck.RunChecks(output, stderr, hc, jsonOutput)
goldenFileBytes, err := ioutil.ReadFile("testdata/check_output_json.golden")
goldenFileBytes, err := os.ReadFile("testdata/check_output_json.golden")
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}

View File

@ -5,7 +5,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"
@ -630,10 +629,10 @@ func TestWalk(t *testing.T) {
file1 = filepath.Join(tmpFolderRoot, "root.txt")
file2 = filepath.Join(tmpFolderData, "data.txt")
)
if err := ioutil.WriteFile(file1, data, 0600); err != nil {
if err := os.WriteFile(file1, data, 0600); err != nil {
t.Fatal("Unexpected error: ", err)
}
if err := ioutil.WriteFile(file2, data, 0600); err != nil {
if err := os.WriteFile(file2, data, 0600); err != nil {
t.Fatal("Unexpected error: ", err)
}

View File

@ -4,7 +4,7 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
@ -319,7 +319,7 @@ func testInstallOptionsHA(ha bool) (*charts.Values, error) {
return nil, err
}
data, err := ioutil.ReadFile(filepath.Join("testdata", "valid-crt.pem"))
data, err := os.ReadFile(filepath.Join("testdata", "valid-crt.pem"))
if err != nil {
return nil, err
}
@ -336,7 +336,7 @@ func testInstallOptionsHA(ha bool) (*charts.Values, error) {
}
values.Identity.Issuer.TLS.KeyPEM = key
data, err = ioutil.ReadFile(filepath.Join("testdata", "valid-trust-anchors.pem"))
data, err = os.ReadFile(filepath.Join("testdata", "valid-trust-anchors.pem"))
if err != nil {
return nil, err
}
@ -376,15 +376,15 @@ func testInstallValues() (*charts.Values, error) {
values.PolicyController.Image.Version = installControlPlaneVersion
values.HeartbeatSchedule = fakeHeartbeatSchedule()
identityCert, err := ioutil.ReadFile(filepath.Join("testdata", "valid-crt.pem"))
identityCert, err := os.ReadFile(filepath.Join("testdata", "valid-crt.pem"))
if err != nil {
return nil, err
}
identityKey, err := ioutil.ReadFile(filepath.Join("testdata", "valid-key.pem"))
identityKey, err := os.ReadFile(filepath.Join("testdata", "valid-key.pem"))
if err != nil {
return nil, err
}
trustAnchorsPEM, err := ioutil.ReadFile(filepath.Join("testdata", "valid-trust-anchors.pem"))
trustAnchorsPEM, err := os.ReadFile(filepath.Join("testdata", "valid-trust-anchors.pem"))
if err != nil {
return nil, err
}
@ -516,7 +516,7 @@ func TestValidate(t *testing.T) {
}
values.Identity.Issuer.TLS.KeyPEM = key
ca, err := ioutil.ReadFile(filepath.Join("testdata", tc.crtFilePrefix+"-trust-anchors.pem"))
ca, err := os.ReadFile(filepath.Join("testdata", tc.crtFilePrefix+"-trust-anchors.pem"))
if err != nil {
t.Fatal(err)
}

View File

@ -4,7 +4,7 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"io"
"os"
"testing"
@ -84,7 +84,7 @@ func Test_obfuscateMetrics(t *testing.T) {
t.Errorf("error opening test input file: %v\n", err)
}
fileBytes, err := ioutil.ReadAll(file)
fileBytes, err := io.ReadAll(file)
if err != nil {
t.Errorf("error reading test input file: %v\n", err)
}

View File

@ -7,7 +7,6 @@ import (
"path/filepath"
"fmt"
"io/ioutil"
"net"
"strings"
"time"
@ -152,7 +151,7 @@ func makeInstallUpgradeFlags(defaults *l5dcharts.Values) ([]flag.Flag, *pflag.Fl
"A path to a PEM-encoded file containing Linkerd Identity trust anchors (generated by default)",
func(values *l5dcharts.Values, value string) error {
if value != "" {
data, err := ioutil.ReadFile(filepath.Clean(value))
data, err := os.ReadFile(filepath.Clean(value))
if err != nil {
return err
}
@ -184,7 +183,7 @@ func makeInstallUpgradeFlags(defaults *l5dcharts.Values) ([]flag.Flag, *pflag.Fl
}
func loadCrtPEM(path string) (string, error) {
data, err := ioutil.ReadFile(filepath.Clean(path))
data, err := os.ReadFile(filepath.Clean(path))
if err != nil {
return "", err
}
@ -197,7 +196,7 @@ func loadCrtPEM(path string) (string, error) {
}
func loadKeyPEM(path string) (string, error) {
data, err := ioutil.ReadFile(filepath.Clean(path))
data, err := os.ReadFile(filepath.Clean(path))
if err != nil {
return "", err
}

View File

@ -6,7 +6,6 @@ import (
"encoding/base64"
"fmt"
"io"
"io/ioutil"
"os"
"strings"
"testing"
@ -462,15 +461,15 @@ func generateCerts(t *testing.T, name string, b64encode bool) issuerCerts {
keyPem := strings.TrimSpace(issuer.Cred.EncodePrivateKeyPEM())
crtPem := strings.TrimSpace(issuer.Cred.EncodeCertificatePEM())
caFile, err := ioutil.TempFile("", "ca.*.pem")
caFile, err := os.CreateTemp("", "ca.*.pem")
if err != nil {
t.Fatal(err)
}
crtFile, err := ioutil.TempFile("", "crt.*.pem")
crtFile, err := os.CreateTemp("", "crt.*.pem")
if err != nil {
t.Fatal(err)
}
keyFile, err := ioutil.TempFile("", "key.*.pem")
keyFile, err := os.CreateTemp("", "key.*.pem")
if err != nil {
t.Fatal(err)
}

View File

@ -19,7 +19,6 @@ import (
"bytes"
"flag"
"fmt"
"io/ioutil"
"os"
"os/exec"
"os/user"
@ -58,7 +57,7 @@ func setEnv(key, value string, t *testing.T) {
}
func mktemp(dir, prefix string, t *testing.T) string {
tempDir, err := ioutil.TempDir(dir, prefix)
tempDir, err := os.MkdirTemp(dir, prefix)
if err != nil {
testutil.AnnotatedFatalf(t, "couldn't get current working directory",
"couldn't get current working directory: %v", err)
@ -77,7 +76,7 @@ func pwd(t *testing.T) string {
}
func ls(dir string, t *testing.T) []string {
files, err := ioutil.ReadDir(dir)
files, err := os.ReadDir(dir)
if err != nil {
testutil.AnnotatedFatalf(t, "failed to list files",
"failed to list files: %v", err)
@ -90,12 +89,12 @@ func ls(dir string, t *testing.T) []string {
}
func cp(src, dest string, t *testing.T) {
data, err := ioutil.ReadFile(src)
data, err := os.ReadFile(src)
if err != nil {
testutil.AnnotatedFatalf(t, fmt.Sprintf("failed to read file %v", src),
"failed to read file %v: %v", src, err)
}
if err = ioutil.WriteFile(dest, data, 0600); err != nil {
if err = os.WriteFile(dest, data, 0600); err != nil {
testutil.AnnotatedFatalf(t, fmt.Sprintf("failed to write file %v", dest),
"failed to write file %v: %v", dest, err)
}
@ -192,7 +191,7 @@ func startDocker(testNum int, wd string, testWorkRootDir string, tempCNINetDir s
containerID, err := cmd.Output()
if err != nil {
errFileContents, _ := ioutil.ReadFile(errFileName)
errFileContents, _ := os.ReadFile(errFileName)
t.Logf("%v contents:\n\n%v\n\n", errFileName, string(errFileContents))
testutil.Fatalf(t,
"test %v ERROR: failed to start docker container '%v', see %v", testNum, dockerImage, errFileName)
@ -214,13 +213,13 @@ func docker(cmd, containerID string, t *testing.T) {
// compareConfResult does a string compare of 2 test files.
func compareConfResult(testWorkRootDir string, tempCNINetDir string, result string, expected string, t *testing.T) {
tempResult := tempCNINetDir + "/" + result
resultFile, err := ioutil.ReadFile(tempResult)
resultFile, err := os.ReadFile(tempResult)
if err != nil {
testutil.AnnotatedFatalf(t, "failed to read file",
"failed to read file %v: %v", tempResult, err)
}
expectedFile, err := ioutil.ReadFile(expected)
expectedFile, err := os.ReadFile(expected)
if err != nil {
testutil.AnnotatedFatalf(t, fmt.Sprintf("failed to read file %v", expected),
"failed to read file %v, err: %v", expected, err)
@ -265,7 +264,7 @@ func doTest(testNum int, wd string, initialNetConfFile string, finalNetConfFile
if initialNetConfFile != "NONE" {
setEnv(cniConfName, initialNetConfFile, t)
}
defaultData, err := ioutil.ReadFile(wd + "../deployment/linkerd-cni.conf.default")
defaultData, err := os.ReadFile(wd + "../deployment/linkerd-cni.conf.default")
if err != nil {
testutil.AnnotatedFatalf(t, "failed to read file linkerd-cni.conf.default",
"failed to read file %v, err: %v", wd+"../deployment/linkerd-cni.conf.default", err)

View File

@ -4,7 +4,6 @@ import (
"context"
"flag"
"fmt"
"io/ioutil"
"net"
"os"
"os/signal"
@ -53,7 +52,7 @@ func Main(args []string) {
flags.ConfigureAndParse(cmd, args)
identityTrustAnchorPEM, err := ioutil.ReadFile(k8s.MountPathTrustRootsPEM)
identityTrustAnchorPEM, err := os.ReadFile(k8s.MountPathTrustRootsPEM)
if err != nil {
log.Fatalf("could not read identity trust anchors PEM: %s", err.Error())
}

View File

@ -1,7 +1,7 @@
package fake
import (
"io/ioutil"
"os"
"path/filepath"
admissionv1beta1 "k8s.io/api/admission/v1beta1"
@ -31,7 +31,7 @@ func NewFactory(rootDir string) *Factory {
// bytes. If the file doesn't exist in the 'fake/data' folder, an error will be
// returned.
func (f *Factory) FileContents(filename string) ([]byte, error) {
return ioutil.ReadFile(filepath.Join(f.rootDir, filename))
return os.ReadFile(filepath.Join(f.rootDir, filename))
}
// AdmissionReview returns the content of the specified file as an
@ -40,7 +40,7 @@ func (f *Factory) FileContents(filename string) ([]byte, error) {
// ii. the file content isn't a valid YAML structure that can be unmarshalled
// into AdmissionReview type
func (f *Factory) AdmissionReview(filename string) (*admissionv1beta1.AdmissionReview, error) {
b, err := ioutil.ReadFile(filepath.Join(f.rootDir, filename))
b, err := os.ReadFile(filepath.Join(f.rootDir, filename))
if err != nil {
return nil, err
}
@ -58,7 +58,7 @@ func (f *Factory) AdmissionReview(filename string) (*admissionv1beta1.AdmissionR
// ii. the file content isn't a valid YAML structure that can be unmarshalled
// into Deployment type
func (f *Factory) Deployment(filename string) (*appsv1.Deployment, error) {
b, err := ioutil.ReadFile(filepath.Join(f.rootDir, filename))
b, err := os.ReadFile(filepath.Join(f.rootDir, filename))
if err != nil {
return nil, err
}
@ -77,7 +77,7 @@ func (f *Factory) Deployment(filename string) (*appsv1.Deployment, error) {
// ii. the file content isn't a valid YAML structure that can be unmarshalled
// into Container type
func (f *Factory) Container(filename string) (*corev1.Container, error) {
b, err := ioutil.ReadFile(filepath.Join(f.rootDir, filename))
b, err := os.ReadFile(filepath.Join(f.rootDir, filename))
if err != nil {
return nil, err
}
@ -96,7 +96,7 @@ func (f *Factory) Container(filename string) (*corev1.Container, error) {
// ii. the file content isn't a valid YAML structure that can be unmarshalled
// into ConfigMap type
func (f *Factory) ConfigMap(filename string) (*corev1.ConfigMap, error) {
b, err := ioutil.ReadFile(filepath.Join(f.rootDir, filename))
b, err := os.ReadFile(filepath.Join(f.rootDir, filename))
if err != nil {
return nil, err
}
@ -115,7 +115,7 @@ func (f *Factory) ConfigMap(filename string) (*corev1.ConfigMap, error) {
// ii. the file content isn't a valid YAML structure that can be unmarshalled
// into Namespace type
func (f *Factory) Namespace(filename string) (*corev1.Namespace, error) {
b, err := ioutil.ReadFile(filepath.Join(f.rootDir, filename))
b, err := os.ReadFile(filepath.Join(f.rootDir, filename))
if err != nil {
return nil, err
}
@ -134,7 +134,7 @@ func (f *Factory) Namespace(filename string) (*corev1.Namespace, error) {
// ii. the file content isn't a valid YAML structure that can be unmarshalled
// into Volume type
func (f *Factory) Volume(filename string) (*corev1.Volume, error) {
b, err := ioutil.ReadFile(filepath.Join(f.rootDir, filename))
b, err := os.ReadFile(filepath.Join(f.rootDir, filename))
if err != nil {
return nil, err
}

View File

@ -3,7 +3,7 @@ package injector
import (
"context"
"fmt"
"io/ioutil"
"os"
"strings"
"github.com/linkerd/linkerd2/controller/k8s"
@ -45,7 +45,7 @@ func Inject(linkerdNamespace string) webhook.Handler {
return nil, err
}
caPEM, err := ioutil.ReadFile(pkgK8s.MountPathTrustRootsPEM)
caPEM, err := os.ReadFile(pkgK8s.MountPathTrustRootsPEM)
if err != nil {
return nil, err
}

View File

@ -3,7 +3,7 @@ package config
import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"github.com/linkerd/linkerd2/pkg/k8s"
@ -19,7 +19,7 @@ import (
// Values returns the Value struct from the linkerd-config ConfigMap
func Values(path string) (*l5dcharts.Values, error) {
p := filepath.Clean(path)
configYaml, err := ioutil.ReadFile(p)
configYaml, err := os.ReadFile(p)
if err != nil {
return nil, fmt.Errorf("failed to read config file: %w", err)
}

View File

@ -6,7 +6,7 @@ import (
"crypto/rsa"
"crypto/x509"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"time"
@ -86,12 +86,12 @@ func FetchExternalIssuerData(ctx context.Context, api kubernetes.Interface, cont
// LoadIssuerCrtAndKeyFromFiles loads the issuer certificate and key from files
func LoadIssuerCrtAndKeyFromFiles(keyPEMFile, crtPEMFile string) (string, string, error) {
key, err := ioutil.ReadFile(filepath.Clean(keyPEMFile))
key, err := os.ReadFile(filepath.Clean(keyPEMFile))
if err != nil {
return "", "", err
}
crt, err := ioutil.ReadFile(filepath.Clean(crtPEMFile))
crt, err := os.ReadFile(filepath.Clean(crtPEMFile))
if err != nil {
return "", "", err
}
@ -106,7 +106,7 @@ func LoadIssuerDataFromFiles(keyPEMFile, crtPEMFile, trustPEMFile string) (*Issu
return nil, err
}
anchors, err := ioutil.ReadFile(filepath.Clean(trustPEMFile))
anchors, err := os.ReadFile(filepath.Clean(trustPEMFile))
if err != nil {
return nil, err
}

View File

@ -2,7 +2,7 @@ package k8s
import (
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
@ -45,5 +45,5 @@ func getResponse(url string) ([]byte, error) {
return nil, err
}
defer resp.Body.Close()
return ioutil.ReadAll(resp.Body)
return io.ReadAll(resp.Body)
}

View File

@ -3,7 +3,7 @@ package k8s
import (
"context"
"fmt"
"io/ioutil"
"io"
"net"
"net/http"
"net/url"
@ -178,8 +178,8 @@ func (pf *PortForward) run() error {
return err
}
out := ioutil.Discard
errOut := ioutil.Discard
out := io.Discard
errOut := io.Discard
if pf.emitLogs {
out = os.Stdout
errOut = os.Stderr

View File

@ -3,7 +3,6 @@ package profiles
import (
"fmt"
"io"
"io/ioutil"
"net/http"
"path"
"sort"
@ -29,7 +28,7 @@ func RenderOpenAPI(fileName, namespace, name, clusterDomain string, w io.Writer)
return err
}
bytes, err := ioutil.ReadAll(input)
bytes, err := io.ReadAll(input)
if err != nil {
return fmt.Errorf("Error reading file: %w", err)
}

View File

@ -6,7 +6,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"strings"
@ -363,7 +363,7 @@ func TestCheckIfResponseHasError(t *testing.T) {
message := SerializeAsPayload(protoInBytes)
response := &http.Response{
Header: make(http.Header),
Body: ioutil.NopCloser(bytes.NewReader(message)),
Body: io.NopCloser(bytes.NewReader(message)),
StatusCode: http.StatusInternalServerError,
}
response.Header.Set(errorHeader, "error")
@ -394,7 +394,7 @@ func TestCheckIfResponseHasError(t *testing.T) {
response := &http.Response{
Header: make(http.Header),
Body: ioutil.NopCloser(bytes.NewReader(j)),
Body: io.NopCloser(bytes.NewReader(j)),
StatusCode: http.StatusForbidden,
Status: "403 Forbidden",
}

View File

@ -9,7 +9,7 @@ import (
"encoding/pem"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"time"
)
@ -195,12 +195,12 @@ func ValidateAndCreateCreds(crt, key string) (*Cred, error) {
// ReadPEMCreds reads PEM-encoded credentials from the named files.
func ReadPEMCreds(keyPath, crtPath string) (*Cred, error) {
keyb, err := ioutil.ReadFile(filepath.Clean(keyPath))
keyb, err := os.ReadFile(filepath.Clean(keyPath))
if err != nil {
return nil, err
}
crtb, err := ioutil.ReadFile(filepath.Clean(crtPath))
crtb, err := os.ReadFile(filepath.Clean(crtPath))
if err != nil {
return nil, err
}

View File

@ -3,7 +3,6 @@ package util
import (
"fmt"
"io"
"io/ioutil"
"strings"
httpPb "github.com/linkerd/linkerd2-proxy-api/go/http_types"
@ -55,7 +54,7 @@ func ParseMethod(method string) *httpPb.HttpMethod {
// reached, the full bytes are returned. If the limit is reached, an error is
// returned.
func ReadAllLimit(r io.Reader, limit int) ([]byte, error) {
bytes, err := ioutil.ReadAll(io.LimitReader(r, int64(limit)))
bytes, err := io.ReadAll(io.LimitReader(r, int64(limit)))
if err != nil {
return nil, err
}

View File

@ -7,7 +7,6 @@ import (
"crypto/x509/pkix"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"syscall"
@ -116,7 +115,7 @@ func generateAndStoreKey(p string) (key *ecdsa.PrivateKey, err error) {
}
pemb := tls.EncodePrivateKeyP8(key)
err = ioutil.WriteFile(p, pemb, 0600)
err = os.WriteFile(p, pemb, 0600)
return
}
@ -138,7 +137,7 @@ func generateAndStoreCSR(p, id string, key *ecdsa.PrivateKey) ([]byte, error) {
return nil, fmt.Errorf("failed to create CSR: %w", err)
}
if err = ioutil.WriteFile(p, csrb, 0600); err != nil {
if err = os.WriteFile(p, csrb, 0600); err != nil {
return nil, fmt.Errorf("failed to write CSR: %w", err)
}

View File

@ -4,7 +4,6 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"os"
"regexp"
"strings"
@ -108,7 +107,7 @@ func TestDirectEdges(t *testing.T) {
}
ip = strings.Trim(ip, "\"") // strip quotes
b, err := ioutil.ReadFile("testdata/slow-cooker.yaml")
b, err := os.ReadFile("testdata/slow-cooker.yaml")
if err != nil {
testutil.AnnotatedError(t, "error reading file slow-cooker.yaml", err)
}

View File

@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"testing"
@ -83,7 +82,7 @@ func ReadTestdata(fileName string) string {
panic(fmt.Sprintf("Failed to open expected output file: %v", err))
}
fixture, err := ioutil.ReadAll(file)
fixture, err := io.ReadAll(file)
if err != nil {
panic(fmt.Sprintf("Failed to read expected output file: %v", err))
}
@ -110,14 +109,14 @@ func unmarshalYAML(data []byte) ([]interface{}, error) {
func writeTestdata(fileName string, data []byte) {
p := filepath.Join("testdata", fileName)
if err := ioutil.WriteFile(p, data, 0600); err != nil {
if err := os.WriteFile(p, data, 0600); err != nil {
panic(err)
}
}
func writeRejects(origFileName string, data []byte, rejectPath string) {
p := filepath.Join(rejectPath, origFileName+".rej")
if err := ioutil.WriteFile(p, data, 0600); err != nil {
if err := os.WriteFile(p, data, 0600); err != nil {
panic(err)
}
}

View File

@ -9,7 +9,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"os/exec"
@ -656,7 +655,7 @@ func (h *TestHelper) HTTPGetURL(url string) (string, error) {
}
defer resp.Body.Close()
bytes, err := ioutil.ReadAll(resp.Body)
bytes, err := io.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("Error reading response body: %w", err)
}
@ -728,7 +727,7 @@ func (h *TestHelper) DownloadCLIBinary(filepath, version string) error {
// ReadFile reads a file from disk and returns the contents as a string.
func ReadFile(file string) (string, error) {
b, err := ioutil.ReadFile(file)
b, err := os.ReadFile(file)
if err != nil {
return "", err
}

View File

@ -3,9 +3,9 @@ package cmd
import (
"bytes"
"context"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"testing"
"github.com/golang/protobuf/ptypes/duration"
@ -149,7 +149,7 @@ func busyTest(t *testing.T, output string) {
goldenFilePath = "testdata/tap_busy_output.golden"
}
goldenFileBytes, err := ioutil.ReadFile(goldenFilePath)
goldenFileBytes, err := os.ReadFile(goldenFilePath)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
@ -207,7 +207,7 @@ func TestRequestTapByResourceFromAPI(t *testing.T) {
t.Fatalf("Unexpected error: %v", err)
}
goldenFileBytes, err := ioutil.ReadFile("testdata/tap_empty_output.golden")
goldenFileBytes, err := os.ReadFile("testdata/tap_empty_output.golden")
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}

View File

@ -4,9 +4,10 @@ import (
"bytes"
"encoding/json"
"errors"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"os"
"testing"
"github.com/go-test/deep"
@ -71,7 +72,7 @@ func TestHandleApiCheck(t *testing.T) {
h.handleAPICheck(w, req, httprouter.Params{})
resp := w.Result()
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatalf("not expecting error reading response body but got: %v", err)
}
@ -83,7 +84,7 @@ func TestHandleApiCheck(t *testing.T) {
if diff := deep.Equal(resp.Header, expectedHeaders); diff != nil {
t.Errorf("Unexpected header: %v", diff)
}
apiCheckOutputGolden, err := ioutil.ReadFile("testdata/api_check_output.json")
apiCheckOutputGolden, err := os.ReadFile("testdata/api_check_output.json")
if err != nil {
t.Fatalf("not expecting error reading api check output golden file but got: %v", err)
}
@ -129,7 +130,7 @@ func TestHandleApiGateway(t *testing.T) {
handler.handleAPIGateways(recorder, req, httprouter.Params{})
resp := recorder.Result()
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatalf("not expecting error reading response body but got: %v", err)
}
@ -146,7 +147,7 @@ func TestHandleApiGateway(t *testing.T) {
t.Errorf("Unexpected header: %v", diff)
}
apiGatewayOutputGolden, err := ioutil.ReadFile("testdata/api_gateway_output.json")
apiGatewayOutputGolden, err := os.ReadFile("testdata/api_gateway_output.json")
if err != nil {
t.Fatalf("not expecting error reading api check output golden file but got: %v", err)
}
@ -171,7 +172,7 @@ func TestHandleApiGateway(t *testing.T) {
handler.handleAPIGateways(recorder, req, httprouter.Params{})
resp := recorder.Result()
defer resp.Body.Close()
_, err := ioutil.ReadAll(resp.Body)
_, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatalf("not expecting error reading response body but got: %v", err)
}