Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test] clean up io/ioutil package #5894

Merged
merged 1 commit into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions test/artifact_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package test
import (
"context"
"fmt"
"io/ioutil"
"os"
"testing"
"time"
Expand Down Expand Up @@ -280,7 +279,7 @@ func updateConfigMap(ctx context.Context, client kubernetes.Interface, name stri

func getBucketSecret(t *testing.T, configFilePath, namespace string) *corev1.Secret {
t.Helper()
f, err := ioutil.ReadFile(configFilePath)
f, err := os.ReadFile(configFilePath)
if err != nil {
t.Fatalf("Failed to read json key file %s at path %s", err, configFilePath)
}
Expand Down
4 changes: 2 additions & 2 deletions test/build_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package test
import (
"context"
"fmt"
"io/ioutil"
"io"
"strings"

corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -65,7 +65,7 @@ func getContainerLogsFromPod(ctx context.Context, c kubernetes.Interface, pod, c
if err != nil {
return "", err
}
bs, err := ioutil.ReadAll(rc)
bs, err := io.ReadAll(rc)
if err != nil {
return "", err
}
Expand Down
3 changes: 1 addition & 2 deletions test/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"bytes"
"context"
"errors"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -137,7 +136,7 @@ func exampleTest(path string, waitValidateFunc waitFunc, createFunc createFunc,
knativetest.CleanupOnInterrupt(func() { tearDown(ctx, t, c, namespace) }, t.Logf)
defer tearDown(ctx, t, c, namespace)

inputExample, err := ioutil.ReadFile(path)
inputExample, err := os.ReadFile(path)
if err != nil {
t.Fatalf("Error reading file: %v", err)
}
Expand Down
3 changes: 1 addition & 2 deletions test/pullrequest/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"net"
"net/http"
"os"
Expand All @@ -45,7 +44,7 @@ var (
)

func TestPullRequest(t *testing.T) {
tmpdir, err := ioutil.TempDir("", t.Name())
tmpdir, err := os.MkdirTemp("", t.Name())
if err != nil {
t.Fatalf("could not create test temp dir: %v", err)
}
Expand Down
5 changes: 2 additions & 3 deletions test/pullrequest/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package pullrequest
import (
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"path/filepath"
Expand All @@ -21,8 +20,8 @@ type handler struct {
func reflect(w http.ResponseWriter, r *http.Request) {
t := io.TeeReader(r.Body, w)
defer r.Body.Close()
if _, err := ioutil.ReadAll(t); err != nil {
log.Printf("ioutil.ReadAll: %v", err)
if _, err := io.ReadAll(t); err != nil {
log.Printf("io.ReadAll: %v", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
Expand Down
6 changes: 3 additions & 3 deletions test/resolvers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"context"
"encoding/base64"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp"
"testing"
Expand Down Expand Up @@ -540,7 +540,7 @@ spec:
// just confused things.
func setupGitea(ctx context.Context, t *testing.T, c *clients, namespace string) (string, string) {
t.Helper()
giteaYaml, err := ioutil.ReadFile(filepath.Join("git-resolver", "gitea.yaml"))
giteaYaml, err := os.ReadFile(filepath.Join("git-resolver", "gitea.yaml"))
if err != nil {
t.Fatalf("failed to read gitea.yaml: %v", err)
}
Expand Down Expand Up @@ -640,7 +640,7 @@ spec:
t.Fatalf("Failed to create gitea token secret %s: %v", secretName, err)
}

remoteTaskBytes, err := ioutil.ReadFile(filepath.Join("git-resolver", "remote-task.yaml"))
remoteTaskBytes, err := os.ReadFile(filepath.Join("git-resolver", "remote-task.yaml"))
if err != nil {
t.Fatalf("Failed to read git-resolver/remote-task.yaml: %v", err)
}
Expand Down
3 changes: 1 addition & 2 deletions test/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package test
import (
"context"
"fmt"
"io/ioutil"
"os"
"testing"

Expand Down Expand Up @@ -53,7 +52,7 @@ func CreateGCPServiceAccountSecret(t *testing.T, c kubernetes.Interface, namespa
},
}

bs, err := ioutil.ReadFile(file)
bs, err := os.ReadFile(file)
if err != nil {
return false, fmt.Errorf("couldn't read secret json from %s: %w", file, err)
}
Expand Down
5 changes: 2 additions & 3 deletions test/tektonbundles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -540,7 +539,7 @@ spec:

func tarImageInOCIFormat(namespace string, img v1.Image) ([]byte, error) {
// Write the image in the OCI layout and then tar it up.
dir, err := ioutil.TempDir(os.TempDir(), namespace)
dir, err := os.MkdirTemp(os.TempDir(), namespace)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -588,7 +587,7 @@ func tarImageInOCIFormat(namespace string, img v1.Image) ([]byte, error) {
}

// Pull out the tar bundle into a bytes object.
return ioutil.ReadAll(&buf)
return io.ReadAll(&buf)
}

// publishImg will generate a Pod that runs in the namespace to publish an OCI compliant image into the local registry
Expand Down
3 changes: 1 addition & 2 deletions test/trusted_resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"context"
"crypto"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -448,7 +447,7 @@ func setSecretAndConfig(ctx context.Context, t *testing.T, client kubernetes.Int
t.Errorf("error getting signer from key file: %v", err)
}

fileBytes, err := ioutil.ReadFile(filepath.Clean(pubKey))
fileBytes, err := os.ReadFile(filepath.Clean(pubKey))
if err != nil {
t.Fatal(err)
}
Expand Down