diff --git a/execabs/execabs_test.go b/execabs/execabs_test.go index 6e96fdf8..30d371ef 100644 --- a/execabs/execabs_test.go +++ b/execabs/execabs_test.go @@ -7,7 +7,6 @@ package execabs import ( "context" "fmt" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -63,8 +62,8 @@ func TestCommand(t *testing.T) { if runtime.GOOS == "windows" { executable += ".exe" } - if err := ioutil.WriteFile(filepath.Join(tmpDir, executable), []byte{1, 2, 3}, 0111); err != nil { - t.Fatalf("ioutil.WriteFile failed: %s", err) + if err := os.WriteFile(filepath.Join(tmpDir, executable), []byte{1, 2, 3}, 0111); err != nil { + t.Fatal(err) } cwd, err := os.Getwd() if err != nil { @@ -98,8 +97,8 @@ func TestLookPath(t *testing.T) { if runtime.GOOS == "windows" { executable += ".exe" } - if err := ioutil.WriteFile(filepath.Join(tmpDir, executable), []byte{1, 2, 3}, 0111); err != nil { - t.Fatalf("ioutil.WriteFile failed: %s", err) + if err := os.WriteFile(filepath.Join(tmpDir, executable), []byte{1, 2, 3}, 0111); err != nil { + t.Fatal(err) } cwd, err := os.Getwd() if err != nil { diff --git a/unix/dirent_test.go b/unix/dirent_test.go index e9dc3cb4..df6d422f 100644 --- a/unix/dirent_test.go +++ b/unix/dirent_test.go @@ -10,7 +10,7 @@ package unix_test import ( "bytes" "fmt" - "io/ioutil" + "os" "path/filepath" "runtime" "sort" @@ -33,9 +33,9 @@ func TestDirent(t *testing.T) { for i, c := range []byte("0123456789") { name := string(bytes.Repeat([]byte{c}, filenameMinSize+i)) - err := ioutil.WriteFile(filepath.Join(d, name), nil, 0644) + err := os.WriteFile(filepath.Join(d, name), nil, 0644) if err != nil { - t.Fatalf("writefile: %v", err) + t.Fatal(err) } } @@ -100,9 +100,9 @@ func TestDirentRepeat(t *testing.T) { files = append(files, fmt.Sprintf("file%d", i)) } for _, file := range files { - err := ioutil.WriteFile(filepath.Join(d, file), []byte("contents"), 0644) + err := os.WriteFile(filepath.Join(d, file), []byte("contents"), 0644) if err != nil { - t.Fatalf("writefile: %v", err) + t.Fatal(err) } } diff --git a/unix/getdirentries_test.go b/unix/getdirentries_test.go index e73e8f95..023e6a14 100644 --- a/unix/getdirentries_test.go +++ b/unix/getdirentries_test.go @@ -9,7 +9,6 @@ package unix_test import ( "fmt" - "io/ioutil" "os" "path/filepath" "sort" @@ -39,9 +38,9 @@ func testGetdirentries(t *testing.T, count int) { // Make files in the temp directory for _, name := range names { - err := ioutil.WriteFile(filepath.Join(d, name), []byte("data"), 0) + err := os.WriteFile(filepath.Join(d, name), []byte("data"), 0) if err != nil { - t.Fatalf("WriteFile: %v", err) + t.Fatal(err) } } diff --git a/unix/mmap_zos_test.go b/unix/mmap_zos_test.go index b9e6cd7a..513cc553 100644 --- a/unix/mmap_zos_test.go +++ b/unix/mmap_zos_test.go @@ -12,7 +12,6 @@ package unix_test import ( "fmt" - "io/ioutil" "os" "path/filepath" "testing" @@ -63,7 +62,7 @@ func TestMmap(t *testing.T) { } // Read file from FS to ensure flag flipped after msync - buf, err := ioutil.ReadFile(filename) + buf, err := os.ReadFile(filename) if err != nil { t.Fatalf("Could not read mmapped file from disc for test: %v", err) } diff --git a/unix/openbsd_test.go b/unix/openbsd_test.go index 8da2cba8..4955943a 100644 --- a/unix/openbsd_test.go +++ b/unix/openbsd_test.go @@ -14,7 +14,6 @@ package unix_test import ( "flag" "fmt" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -92,7 +91,7 @@ func init() { os.Exit(0) }, func() error { - files, err := ioutil.ReadDir(".") + files, err := os.ReadDir(".") if err != nil { return err } diff --git a/unix/sendfile_test.go b/unix/sendfile_test.go index 0c028431..c4494e01 100644 --- a/unix/sendfile_test.go +++ b/unix/sendfile_test.go @@ -8,7 +8,7 @@ package unix_test import ( - "io/ioutil" + "io" "net" "os" "path/filepath" @@ -21,7 +21,7 @@ func TestSendfile(t *testing.T) { // Set up source data file. name := filepath.Join(t.TempDir(), "source") const contents = "contents" - err := ioutil.WriteFile(name, []byte(contents), 0666) + err := os.WriteFile(name, []byte(contents), 0666) if err != nil { t.Fatal(err) } @@ -41,7 +41,7 @@ func TestSendfile(t *testing.T) { return } defer conn.Close() - b, err := ioutil.ReadAll(conn) + b, err := io.ReadAll(conn) if err != nil { t.Errorf("failed to read: %v", err) return diff --git a/unix/syscall_darwin_test.go b/unix/syscall_darwin_test.go index 119f7df4..f17116a6 100644 --- a/unix/syscall_darwin_test.go +++ b/unix/syscall_darwin_test.go @@ -6,7 +6,6 @@ package unix_test import ( "bytes" - "io/ioutil" "net" "os" "path/filepath" @@ -51,7 +50,7 @@ func TestClonefile(t *testing.T) { t.Fatal(err) } - clonedData, err := ioutil.ReadFile(clonedName) + clonedData, err := os.ReadFile(clonedName) if err != nil { t.Fatal(err) } @@ -72,7 +71,7 @@ func TestClonefileatWithCwd(t *testing.T) { t.Fatal(err) } - clonedData, err := ioutil.ReadFile(clonedName) + clonedData, err := os.ReadFile(clonedName) if err != nil { t.Fatal(err) } @@ -116,7 +115,7 @@ func TestClonefileatWithRelativePaths(t *testing.T) { t.Fatal(err) } - clonedData, err := ioutil.ReadFile(dstFile.Name()) + clonedData, err := os.ReadFile(dstFile.Name()) if err != nil { t.Fatal(err) } @@ -149,7 +148,7 @@ func TestFclonefileat(t *testing.T) { t.Fatal(err) } - clonedData, err := ioutil.ReadFile(dstFile.Name()) + clonedData, err := os.ReadFile(dstFile.Name()) if err != nil { t.Fatal(err) } diff --git a/unix/syscall_linux_test.go b/unix/syscall_linux_test.go index b0e3404b..ae2d6f43 100644 --- a/unix/syscall_linux_test.go +++ b/unix/syscall_linux_test.go @@ -12,7 +12,7 @@ import ( "bytes" "errors" "fmt" - "io/ioutil" + "io" "net" "os" "os/exec" @@ -810,7 +810,7 @@ func TestOpenByHandleAt(t *testing.T) { f := os.NewFile(uintptr(fd), "") defer f.Close() - slurp, err := ioutil.ReadAll(f) + slurp, err := io.ReadAll(f) if err != nil { t.Fatal(err) } diff --git a/unix/syscall_unix_test.go b/unix/syscall_unix_test.go index ac2092cb..10cddb43 100644 --- a/unix/syscall_unix_test.go +++ b/unix/syscall_unix_test.go @@ -11,7 +11,7 @@ import ( "bytes" "flag" "fmt" - "io/ioutil" + "io" "net" "os" "os/exec" @@ -260,7 +260,7 @@ func TestPassFD(t *testing.T) { f := os.NewFile(uintptr(gotFds[0]), "fd-from-child") defer f.Close() - got, err := ioutil.ReadAll(f) + got, err := io.ReadAll(f) want := "Hello from child process!\n" if string(got) != want { t.Errorf("child process ReadAll: %q, %v; want %q", got, err, want) diff --git a/unix/syscall_zos_test.go b/unix/syscall_zos_test.go index fefe3f8a..30ace208 100644 --- a/unix/syscall_zos_test.go +++ b/unix/syscall_zos_test.go @@ -10,7 +10,7 @@ package unix_test import ( "flag" "fmt" - "io/ioutil" + "io" "net" "os" "os/exec" @@ -258,7 +258,7 @@ func TestPassFD(t *testing.T) { f := os.NewFile(uintptr(gotFds[0]), "fd-from-child") defer f.Close() - got, err := ioutil.ReadAll(f) + got, err := io.ReadAll(f) want := "Hello from child process!\n" if string(got) != want { t.Errorf("child process ReadAll: %q, %v; want %q", got, err, want) @@ -628,7 +628,7 @@ func TestChroot(t *testing.T) { t.Fatalf("Chroot: %s", err.Error()) } // check if tempDir contains test file - files, err := ioutil.ReadDir("/") + files, err := os.ReadDir("/") if err != nil { t.Fatalf("ReadDir: %s", err.Error()) } diff --git a/windows/svc/svc_test.go b/windows/svc/svc_test.go index 549cfeec..81161b85 100644 --- a/windows/svc/svc_test.go +++ b/windows/svc/svc_test.go @@ -9,7 +9,6 @@ package svc_test import ( "fmt" - "io/ioutil" "math/rand" "os" "os/exec" @@ -202,7 +201,7 @@ func TestIsWindowsServiceWhenParentExits(t *testing.T) { if isSvc { msg = "IsWindowsService returns true when not running in a service." } - err = ioutil.WriteFile(dumpPath, []byte(msg), 0644) + err = os.WriteFile(dumpPath, []byte(msg), 0644) if err != nil { // We cannot report this error. But main test will notice // that we did not create dump file. @@ -232,7 +231,7 @@ func TestIsWindowsServiceWhenParentExits(t *testing.T) { t.Fatal("timed out waiting for child output file to be created.") } } - childOutput, err := ioutil.ReadFile(childDumpPath) + childOutput, err := os.ReadFile(childDumpPath) if err != nil { t.Fatalf("reading child output failed: %v", err) } diff --git a/windows/syscall_windows_test.go b/windows/syscall_windows_test.go index 40b4d54e..f8996492 100644 --- a/windows/syscall_windows_test.go +++ b/windows/syscall_windows_test.go @@ -10,7 +10,6 @@ import ( "debug/pe" "errors" "fmt" - "io/ioutil" "math/rand" "os" "path/filepath" @@ -667,14 +666,14 @@ func TestWinVerifyTrust(t *testing.T) { // Now that we've verified the legitimate file verifies, let's corrupt it and see if it correctly fails. corruptedEvsignedfile := filepath.Join(t.TempDir(), "corrupted-file") - evsignedfileBytes, err := ioutil.ReadFile(evsignedfile) + evsignedfileBytes, err := os.ReadFile(evsignedfile) if err != nil { t.Fatalf("unable to read %s bytes: %v", evsignedfile, err) } if len(evsignedfileBytes) > 0 { evsignedfileBytes[len(evsignedfileBytes)/2-1]++ } - err = ioutil.WriteFile(corruptedEvsignedfile, evsignedfileBytes, 0755) + err = os.WriteFile(corruptedEvsignedfile, evsignedfileBytes, 0755) if err != nil { t.Fatalf("unable to write corrupted ntoskrnl.exe bytes: %v", err) }