Skip to content

Commit

Permalink
*: remove use of deprecated io/ioutil package
Browse files Browse the repository at this point in the history
  • Loading branch information
abursavich committed Aug 18, 2022
1 parent 74769c8 commit ad873da
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
8 changes: 4 additions & 4 deletions dynamictls.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"fmt"
"hash"
"hash/fnv"
"io/ioutil"
"net"
"os"
"path/filepath"
"sort"
"sync/atomic"
Expand Down Expand Up @@ -356,11 +356,11 @@ func (cfg *Config) watch() {
func readCerts(h hash.Hash, pairs []keyPair) ([]tls.Certificate, error) {
var certs []tls.Certificate
for _, pair := range pairs {
certPEMBlock, err := ioutil.ReadFile(pair.certFile)
certPEMBlock, err := os.ReadFile(pair.certFile)
if err != nil {
return nil, fmt.Errorf("dynamictls: cert read error: %w", err)
}
keyPEMBlock, err := ioutil.ReadFile(pair.keyFile)
keyPEMBlock, err := os.ReadFile(pair.keyFile)
if err != nil {
return nil, fmt.Errorf("dynamictls: key read error: %w", err)
}
Expand All @@ -382,7 +382,7 @@ func readCAs(h hash.Hash, files []string) (*x509.CertPool, error) {
}
pool := x509.NewCertPool()
for _, file := range files {
caPEMCerts, err := ioutil.ReadFile(file)
caPEMCerts, err := os.ReadFile(file)
if err != nil {
return nil, fmt.Errorf("dynamictls: certificate authorities read error: %w", err)
}
Expand Down
17 changes: 8 additions & 9 deletions dynamictls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"crypto/x509"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"os"
Expand All @@ -27,7 +26,7 @@ import (

func TestOptions(t *testing.T) {
// create temp dir
dir, err := ioutil.TempDir("", "")
dir, err := os.MkdirTemp("", "")
check(t, "Failed to create directory", err)
defer os.RemoveAll(dir)

Expand Down Expand Up @@ -253,7 +252,7 @@ func (o *testObserver) ObserveReadError(err error) {

func TestNotifyError(t *testing.T) {
// create temp dir
dir, err := ioutil.TempDir("", "")
dir, err := os.MkdirTemp("", "")
check(t, "Failed to create directory", err)
defer os.RemoveAll(dir)

Expand Down Expand Up @@ -318,7 +317,7 @@ func TestKubernetes(t *testing.T) {
cert1, certPEMBlock1, keyPEMBlock1, err := tlstest.GenerateCert(&tlstest.CertOptions{Parent: ca})
check(t, "Failed to create certificate", err)

dir, err := ioutil.TempDir("", "")
dir, err := os.MkdirTemp("", "")
check(t, "Failed to create directory", err)
defer os.RemoveAll(dir)

Expand Down Expand Up @@ -403,7 +402,7 @@ func TestKubernetes(t *testing.T) {

func TestMTLS(t *testing.T) {
// create temp dir
dir, err := ioutil.TempDir("", "")
dir, err := os.MkdirTemp("", "")
check(t, "Failed to create directory", err)
defer os.RemoveAll(dir)

Expand Down Expand Up @@ -488,7 +487,7 @@ func TestMTLS(t *testing.T) {
check(t, "Failed to get listen port", err)
resp, err := client.Get("https://localhost:" + port)
check(t, "Failed HTTP request", err)
buf, err := ioutil.ReadAll(resp.Body)
buf, err := io.ReadAll(resp.Body)
check(t, "Failed reading HTTP response body", err)
if got := string(buf); got != msg {
t.Fatalf("Unexpected response; want: %q; got: %q", msg, got)
Expand All @@ -497,7 +496,7 @@ func TestMTLS(t *testing.T) {

func TestListenError(t *testing.T) {
// create temp dir
dir, err := ioutil.TempDir("", "")
dir, err := os.MkdirTemp("", "")
check(t, "Failed to create directory", err)
defer os.RemoveAll(dir)

Expand Down Expand Up @@ -528,7 +527,7 @@ func TestListenError(t *testing.T) {

func TestDialErrors(t *testing.T) {
// create temp dir
dir, err := ioutil.TempDir("", "")
dir, err := os.MkdirTemp("", "")
check(t, "Failed to create directory", err)
defer os.RemoveAll(dir)

Expand Down Expand Up @@ -589,7 +588,7 @@ func createDir(t *testing.T, dir string, files map[string][]byte) {
func createFile(t *testing.T, dir, base string, buf []byte) string {
t.Helper()
path := filepath.Join(dir, base)
check(t, "Failed to write file", ioutil.WriteFile(path, buf, os.ModePerm))
check(t, "Failed to write file", os.WriteFile(path, buf, os.ModePerm))
return path
}

Expand Down
9 changes: 4 additions & 5 deletions grpctls/grpctls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"crypto/tls"
"crypto/x509"
"io"
"io/ioutil"
"net"
"os"
"path/filepath"
Expand All @@ -27,7 +26,7 @@ import (

func TestInvalidConfig(t *testing.T) {
// create temp dir
dir, err := ioutil.TempDir("", "")
dir, err := os.MkdirTemp("", "")
check(t, "Failed to create directory", err)
defer os.RemoveAll(dir)

Expand All @@ -54,7 +53,7 @@ func TestInvalidConfig(t *testing.T) {

func TestHandshakeErrors(t *testing.T) {
// create temp dir
dir, err := ioutil.TempDir("", "")
dir, err := os.MkdirTemp("", "")
check(t, "Failed to create directory", err)
defer os.RemoveAll(dir)

Expand Down Expand Up @@ -138,7 +137,7 @@ func (errConn) SetWriteDeadline(t time.Time) error { return nil }

func TestGRPC(t *testing.T) {
// create temp dir
dir, err := ioutil.TempDir("", "")
dir, err := os.MkdirTemp("", "")
check(t, "Failed to create directory", err)
defer os.RemoveAll(dir)

Expand Down Expand Up @@ -240,7 +239,7 @@ func (*testServer) UnaryCall(ctx context.Context, req *pb.SimpleRequest) (*pb.Si
func createFile(t *testing.T, dir, base string, buf []byte) string {
t.Helper()
path := filepath.Join(dir, base)
check(t, "Failed to write file", ioutil.WriteFile(path, buf, os.ModePerm))
check(t, "Failed to write file", os.WriteFile(path, buf, os.ModePerm))
return path
}

Expand Down

0 comments on commit ad873da

Please sign in to comment.