Skip to content

Commit

Permalink
Remove use of deprecated io/ioutil package
Browse files Browse the repository at this point in the history
Remove deprecated calls and replace with suggestions from the deprecation notice.
  • Loading branch information
allenporter committed Aug 24, 2021
1 parent 580f74a commit 7609370
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 27 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ meeting](https://docs.google.com/document/d/1l_M0om0qUEN_NNiGgpqJ2tvsF2iioHkaARD
You can run the unit tests by simply doing

```bash
make test
make all
```

## Acceptance policy
Expand Down
4 changes: 2 additions & 2 deletions gittestserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ package gittestserver
import (
"crypto/tls"
"crypto/x509"
"io/ioutil"
"net/http/httptest"
"net/url"
"os"
"path/filepath"

"github.com/sosedoff/gitkit"
Expand All @@ -30,7 +30,7 @@ import (
// NewTempGitServer returns a GitServer with a newly created temp
// dir as repository docroot.
func NewTempGitServer() (*GitServer, error) {
tmpDir, err := ioutil.TempDir("", "git-server-test-")
tmpDir, err := os.MkdirTemp("", "git-server-test-")
if err != nil {
return nil, err
}
Expand Down
7 changes: 3 additions & 4 deletions gittestserver/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package gittestserver

import (
"fmt"
"io/ioutil"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -83,15 +82,15 @@ func TestHTTPSServer(t *testing.T) {
}
defer os.RemoveAll(srv.Root())

examplePublicKey, err := ioutil.ReadFile("../testdata/certs/server.pem")
examplePublicKey, err := os.ReadFile("../testdata/certs/server.pem")
if err != nil {
t.Fatal(err)
}
examplePrivateKey, err := ioutil.ReadFile("../testdata/certs/server-key.pem")
examplePrivateKey, err := os.ReadFile("../testdata/certs/server-key.pem")
if err != nil {
t.Fatal(err)
}
exampleCA, err := ioutil.ReadFile("../testdata/certs/ca.pem")
exampleCA, err := os.ReadFile("../testdata/certs/ca.pem")
if err != nil {
t.Fatal(err)
}
Expand Down
6 changes: 3 additions & 3 deletions helmtestserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package helmtestserver

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

"helm.sh/helm/v3/pkg/action"
Expand All @@ -30,7 +30,7 @@ import (
// NewTempHelmServer returns a HTTP HelmServer with a newly created
// temp dir as repository docroot.
func NewTempHelmServer() (*HelmServer, error) {
tmpDir, err := ioutil.TempDir("", "helm-test-")
tmpDir, err := os.MkdirTemp("", "helm-test-")
if err != nil {
return nil, err
}
Expand All @@ -56,7 +56,7 @@ func (s *HelmServer) GenerateIndex() error {
return err
}
f := filepath.Join(s.HTTPServer.Root(), "index.yaml")
return ioutil.WriteFile(f, d, 0644)
return os.WriteFile(f, d, 0644)
}

// PackageChart attempts to package the chart at the given path, to be served
Expand Down
5 changes: 2 additions & 3 deletions lockedfile/lockedfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package lockedfile
import (
"fmt"
"io"
"io/ioutil"
"os"
"runtime"
)
Expand Down Expand Up @@ -103,7 +102,7 @@ func Read(name string) ([]byte, error) {
}
defer f.Close()

return ioutil.ReadAll(f)
return io.ReadAll(f)
}

// Write opens the named file (creating it with the given permissions if needed),
Expand Down Expand Up @@ -135,7 +134,7 @@ func Transform(name string, t func([]byte) ([]byte, error)) (err error) {
}
defer f.Close()

old, err := ioutil.ReadAll(f)
old, err := io.ReadAll(f)
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions runtime/events/recorder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package events

import (
"encoding/json"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"testing"
Expand All @@ -29,7 +29,7 @@ import (

func TestEventRecorder_Eventf(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
require.NoError(t, err)

var payload Event
Expand Down Expand Up @@ -63,7 +63,7 @@ func TestEventRecorder_Eventf(t *testing.T) {

func TestEventRecorder_Eventf_Retry(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
require.NoError(t, err)

var payload Event
Expand All @@ -90,7 +90,7 @@ func TestEventRecorder_Eventf_Retry(t *testing.T) {

func TestEventRecorder_Eventf_RateLimited(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
require.NoError(t, err)

var payload Event
Expand Down
3 changes: 1 addition & 2 deletions testserver/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ import (
"crypto/sha1"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
)

// NewTempArtifactServer returns an ArtifactServer with a newly created temp
// dir as the artifact docroot.
func NewTempArtifactServer() (*ArtifactServer, error) {
tmpDir, err := ioutil.TempDir("", "artifact-test-")
tmpDir, err := os.MkdirTemp("", "artifact-test-")
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions testserver/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ package testserver
import (
"crypto/tls"
"crypto/x509"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
)

// NewTempHTTPServer returns a HTTPServer with a newly created temp
// dir as the docroot.
func NewTempHTTPServer() (*HTTPServer, error) {
tmpDir, err := ioutil.TempDir("", "http-test-")
tmpDir, err := os.MkdirTemp("", "http-test-")
if err != nil {
return nil, err
}
Expand Down
12 changes: 6 additions & 6 deletions testserver/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package testserver
import (
"crypto/tls"
"crypto/x509"
"io/ioutil"
"io"
"net/http"
"os"
"strings"
Expand All @@ -44,7 +44,7 @@ func testMiddlewareResult(t *testing.T, client *http.Client, addr string, want s
t.Errorf("failed to GET %s: %v", addr, err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -79,19 +79,19 @@ func TestHTTPSServer(t *testing.T) {
}
defer os.RemoveAll(srv.Root())

examplePublicKey, err := ioutil.ReadFile("../testdata/certs/server.pem")
examplePublicKey, err := os.ReadFile("../testdata/certs/server.pem")
if err != nil {
t.Fatal(err)
}
examplePrivateKey, err := ioutil.ReadFile("../testdata/certs/server-key.pem")
examplePrivateKey, err := os.ReadFile("../testdata/certs/server-key.pem")
if err != nil {
t.Fatal(err)
}
exampleCA, err := ioutil.ReadFile("../testdata/certs/ca.pem")
exampleCA, err := os.ReadFile("../testdata/certs/ca.pem")
if err != nil {
t.Fatal(err)
}
caCert, err := ioutil.ReadFile("../testdata/certs/ca.pem")
caCert, err := os.ReadFile("../testdata/certs/ca.pem")
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 7609370

Please sign in to comment.