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:
Eng Zer Jun
2021-09-10 20:28:11 +08:00
parent c16be1a5e2
commit 50da673592
126 changed files with 291 additions and 399 deletions

View File

@@ -22,7 +22,6 @@ package btrfs
import (
"bytes"
"context"
"io/ioutil"
"os"
"path/filepath"
"strings"
@@ -46,7 +45,7 @@ func boltSnapshotter(t *testing.T) func(context.Context, string) (snapshots.Snap
t.Skipf("could not find mkfs.btrfs: %v", err)
}
procModules, err := ioutil.ReadFile("/proc/modules")
procModules, err := os.ReadFile("/proc/modules")
if err == nil && !bytes.Contains(procModules, []byte("btrfs")) {
t.Skip("check for btrfs kernel module failed, skipping test")
}
@@ -122,14 +121,14 @@ func TestBtrfsMounts(t *testing.T) {
ctx := context.Background()
// create temporary directory for mount point
mountPoint, err := ioutil.TempDir("", "containerd-btrfs-test")
mountPoint, err := os.MkdirTemp("", "containerd-btrfs-test")
if err != nil {
t.Fatal("could not create mount point for btrfs test", err)
}
defer os.RemoveAll(mountPoint)
t.Log("temporary mount point created", mountPoint)
root, err := ioutil.TempDir(mountPoint, "TestBtrfsPrepare-")
root, err := os.MkdirTemp(mountPoint, "TestBtrfsPrepare-")
if err != nil {
t.Fatal(err)
}
@@ -168,7 +167,7 @@ func TestBtrfsMounts(t *testing.T) {
defer testutil.Unmount(t, target)
// write in some data
if err := ioutil.WriteFile(filepath.Join(target, "foo"), []byte("content"), 0777); err != nil {
if err := os.WriteFile(filepath.Join(target, "foo"), []byte("content"), 0777); err != nil {
t.Fatal(err)
}
@@ -198,7 +197,7 @@ func TestBtrfsMounts(t *testing.T) {
defer testutil.Unmount(t, target)
// TODO(stevvooe): Verify contents of "foo"
if err := ioutil.WriteFile(filepath.Join(target, "bar"), []byte("content"), 0777); err != nil {
if err := os.WriteFile(filepath.Join(target, "bar"), []byte("content"), 0777); err != nil {
t.Fatal(err)
}