Skip to content

Commit

Permalink
chore: remove refs to deprecated io/ioutil (#790)
Browse files Browse the repository at this point in the history
Signed-off-by: guoguangwu <[email protected]>
  • Loading branch information
testwill authored Aug 9, 2023
1 parent 1725a44 commit 96ce95c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
4 changes: 2 additions & 2 deletions pkg/kapp/cmd/appgroup/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ package appgroup

import (
"fmt"
"io/ioutil"
"math"
"os"
"path/filepath"

"github.com/cppforlife/go-cli-ui/ui"
Expand Down Expand Up @@ -121,7 +121,7 @@ func (o *DeployOptions) appsToUpdate() (map[string]appGroupApp, error) {
result := map[string]appGroupApp{}
dir := o.DeployFlags.Directory

fileInfos, err := ioutil.ReadDir(dir)
fileInfos, err := os.ReadDir(dir)
if err != nil {
return nil, fmt.Errorf("Reading directory '%s': %w", dir, err)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/kapp/diffgraph/change_graph_cf_for_k8s_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package diffgraph_test

import (
"io/ioutil"
"os"
"strings"
"testing"
"time"
Expand All @@ -16,7 +16,7 @@ import (
)

func TestChangeGraphCFForK8sUpsert(t *testing.T) {
configYAML, err := ioutil.ReadFile("assets/cf-for-k8s.yml")
configYAML, err := os.ReadFile("assets/cf-for-k8s.yml")
require.NoErrorf(t, err, "Reading cf-for-k8s asset")

configRs, err := ctlres.NewFileResource(ctlres.NewBytesSource([]byte(configYAML))).Resources()
Expand Down Expand Up @@ -46,7 +46,7 @@ func TestChangeGraphCFForK8sUpsert(t *testing.T) {
}

func TestChangeGraphCFForK8sDelete(t *testing.T) {
configYAML, err := ioutil.ReadFile("assets/cf-for-k8s.yml")
configYAML, err := os.ReadFile("assets/cf-for-k8s.yml")
require.NoErrorf(t, err, "Reading cf-for-k8s asset")

configRs, err := ctlres.NewFileResource(ctlres.NewBytesSource([]byte(configYAML))).Resources()
Expand Down
8 changes: 4 additions & 4 deletions pkg/kapp/resources/file_sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package resources

import (
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
)
Expand All @@ -31,7 +31,7 @@ var _ FileSource = StdinSource{}

func NewStdinSource() StdinSource { return StdinSource{} }
func (s StdinSource) Description() string { return "stdin" }
func (s StdinSource) Bytes() ([]byte, error) { return ioutil.ReadAll(os.Stdin) }
func (s StdinSource) Bytes() ([]byte, error) { return io.ReadAll(os.Stdin) }

type LocalFileSource struct {
path string
Expand All @@ -41,7 +41,7 @@ var _ FileSource = LocalFileSource{}

func NewLocalFileSource(path string) LocalFileSource { return LocalFileSource{path} }
func (s LocalFileSource) Description() string { return fmt.Sprintf("file '%s'", s.path) }
func (s LocalFileSource) Bytes() ([]byte, error) { return ioutil.ReadFile(s.path) }
func (s LocalFileSource) Bytes() ([]byte, error) { return os.ReadFile(s.path) }

type HTTPFileSource struct {
url string
Expand All @@ -68,7 +68,7 @@ func (s HTTPFileSource) Bytes() ([]byte, error) {
return nil, fmt.Errorf("Requesting URL '%s': %s", s.url, resp.Status)
}

result, err := ioutil.ReadAll(resp.Body)
result, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("Reading URL '%s': %w", s.url, err)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/kapp/resources/file_sources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package resources_test
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"net/http"
"testing"

Expand All @@ -23,7 +23,7 @@ func TestHTTPFileSources(t *testing.T) {
return &http.Response{
StatusCode: http.StatusOK,
// Send response to be tested
Body: ioutil.NopCloser(bytes.NewBufferString(`OK`)),
Body: io.NopCloser(bytes.NewBufferString(`OK`)),
// Must be set to non-nil value or it panics
Header: make(http.Header),
}
Expand All @@ -41,7 +41,7 @@ func TestHTTPFileSources(t *testing.T) {
require.Equal(t, req.URL.String(), url)
return &http.Response{
StatusCode: http.StatusIMUsed,
Body: ioutil.NopCloser(bytes.NewBufferString(`OK`)),
Body: io.NopCloser(bytes.NewBufferString(`OK`)),
Header: make(http.Header),
}
})
Expand Down
3 changes: 1 addition & 2 deletions test/e2e/update_retry_on_conflict_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package e2e
import (
"bufio"
"io"
"io/ioutil"
"os"
"regexp"
"strings"
Expand Down Expand Up @@ -325,7 +324,7 @@ func (p promptOutput) WaitPresented() {
}

func newTmpFile(content string, t *testing.T) *os.File {
file, err := ioutil.TempFile("", "kapp-test-update-retry-on-conflict")
file, err := os.CreateTemp("", "kapp-test-update-retry-on-conflict")
require.NoError(t, err)

_, err = file.Write([]byte(content))
Expand Down

0 comments on commit 96ce95c

Please sign in to comment.