refactor: move from io/ioutil to io and os package
The io/ioutil package has been deprecated as of Go 1.16, see https://golang.org/doc/go1.16#ioutil. This commit replaces the existing io/ioutil functions with their new definitions in io and os packages. Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
@@ -17,7 +17,6 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@@ -66,11 +65,11 @@ func TestEnsureRemoveAllWithMount(t *testing.T) {
|
||||
t.Skip("skipping test that requires root")
|
||||
}
|
||||
|
||||
dir1, err := ioutil.TempDir("", "test-ensure-removeall-with-dir1")
|
||||
dir1, err := os.MkdirTemp("", "test-ensure-removeall-with-dir1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
dir2, err := ioutil.TempDir("", "test-ensure-removeall-with-dir2")
|
||||
dir2, err := os.MkdirTemp("", "test-ensure-removeall-with-dir2")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -489,7 +489,7 @@ func TestEnsureRemoveAllNotExist(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestEnsureRemoveAllWithDir(t *testing.T) {
|
||||
dir, err := ioutil.TempDir("", "test-ensure-removeall-with-dir")
|
||||
dir, err := os.MkdirTemp("", "test-ensure-removeall-with-dir")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -499,7 +499,7 @@ func TestEnsureRemoveAllWithDir(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestEnsureRemoveAllWithFile(t *testing.T) {
|
||||
tmp, err := ioutil.TempFile("", "test-ensure-removeall-with-dir")
|
||||
tmp, err := os.CreateTemp("", "test-ensure-removeall-with-dir")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -21,10 +21,10 @@ import (
|
||||
"crypto/x509"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -301,7 +301,7 @@ func (c *criService) getTLSConfig(registryTLSConfig criconfig.TLSConfig) (*tls.C
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get system cert pool")
|
||||
}
|
||||
caCert, err := ioutil.ReadFile(registryTLSConfig.CAFile)
|
||||
caCert, err := os.ReadFile(registryTLSConfig.CAFile)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to load CA file")
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
goruntime "runtime"
|
||||
@@ -458,7 +457,7 @@ func (c *criService) loadImages(ctx context.Context, cImages []containerd.Image)
|
||||
|
||||
func cleanupOrphanedIDDirs(ctx context.Context, cntrs []containerd.Container, base string) error {
|
||||
// Cleanup orphaned id directories.
|
||||
dirs, err := ioutil.ReadDir(base)
|
||||
dirs, err := os.ReadDir(base)
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
return errors.Wrap(err, "failed to read base directory")
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ package server
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
@@ -73,7 +72,7 @@ func newTestCRIService() *criService {
|
||||
func TestLoadBaseOCISpec(t *testing.T) {
|
||||
spec := oci.Spec{Version: "1.0.2", Hostname: "default"}
|
||||
|
||||
file, err := ioutil.TempFile("", "spec-test-")
|
||||
file, err := os.CreateTemp("", "spec-test-")
|
||||
require.NoError(t, err)
|
||||
|
||||
defer func() {
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@@ -94,11 +93,11 @@ func TestUpdateRuntimeConfig(t *testing.T) {
|
||||
},
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
testDir, err := ioutil.TempDir(os.TempDir(), "test-runtime-config")
|
||||
testDir, err := os.MkdirTemp(os.TempDir(), "test-runtime-config")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(testDir)
|
||||
templateName := filepath.Join(testDir, "template")
|
||||
err = ioutil.WriteFile(templateName, []byte(testTemplate), 0666)
|
||||
err = os.WriteFile(templateName, []byte(testTemplate), 0666)
|
||||
require.NoError(t, err)
|
||||
confDir := filepath.Join(testDir, "net.d")
|
||||
confName := filepath.Join(confDir, cniConfigFileName)
|
||||
@@ -131,7 +130,7 @@ func TestUpdateRuntimeConfig(t *testing.T) {
|
||||
_, err := os.Stat(confName)
|
||||
assert.Error(t, err)
|
||||
} else {
|
||||
got, err := ioutil.ReadFile(confName)
|
||||
got, err := os.ReadFile(confName)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, expected, string(got))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user