Replace deprecated ioutil

As of Go 1.16, the same functionality is now provided by package io or
package os, and those implementations should be preferred in new code.
This commit is contained in:
albertony
2022-08-20 16:38:02 +02:00
committed by Nick Craig-Wood
parent 776e5ea83a
commit 5d6b8141ec
108 changed files with 295 additions and 359 deletions

View File

@ -1,7 +1,6 @@
package genautocomplete
import (
"io/ioutil"
"os"
"testing"
@ -9,7 +8,7 @@ import (
)
func TestCompletionBash(t *testing.T) {
tempFile, err := ioutil.TempFile("", "completion_bash")
tempFile, err := os.CreateTemp("", "completion_bash")
assert.NoError(t, err)
defer func() {
_ = tempFile.Close()
@ -18,14 +17,14 @@ func TestCompletionBash(t *testing.T) {
bashCommandDefinition.Run(bashCommandDefinition, []string{tempFile.Name()})
bs, err := ioutil.ReadFile(tempFile.Name())
bs, err := os.ReadFile(tempFile.Name())
assert.NoError(t, err)
assert.NotEmpty(t, string(bs))
}
func TestCompletionBashStdout(t *testing.T) {
originalStdout := os.Stdout
tempFile, err := ioutil.TempFile("", "completion_zsh")
tempFile, err := os.CreateTemp("", "completion_zsh")
assert.NoError(t, err)
defer func() {
_ = tempFile.Close()
@ -37,13 +36,13 @@ func TestCompletionBashStdout(t *testing.T) {
bashCommandDefinition.Run(bashCommandDefinition, []string{"-"})
output, err := ioutil.ReadFile(tempFile.Name())
output, err := os.ReadFile(tempFile.Name())
assert.NoError(t, err)
assert.NotEmpty(t, string(output))
}
func TestCompletionZsh(t *testing.T) {
tempFile, err := ioutil.TempFile("", "completion_zsh")
tempFile, err := os.CreateTemp("", "completion_zsh")
assert.NoError(t, err)
defer func() {
_ = tempFile.Close()
@ -52,14 +51,14 @@ func TestCompletionZsh(t *testing.T) {
zshCommandDefinition.Run(zshCommandDefinition, []string{tempFile.Name()})
bs, err := ioutil.ReadFile(tempFile.Name())
bs, err := os.ReadFile(tempFile.Name())
assert.NoError(t, err)
assert.NotEmpty(t, string(bs))
}
func TestCompletionZshStdout(t *testing.T) {
originalStdout := os.Stdout
tempFile, err := ioutil.TempFile("", "completion_zsh")
tempFile, err := os.CreateTemp("", "completion_zsh")
assert.NoError(t, err)
defer func() {
_ = tempFile.Close()
@ -70,13 +69,13 @@ func TestCompletionZshStdout(t *testing.T) {
defer func() { os.Stdout = originalStdout }()
zshCommandDefinition.Run(zshCommandDefinition, []string{"-"})
output, err := ioutil.ReadFile(tempFile.Name())
output, err := os.ReadFile(tempFile.Name())
assert.NoError(t, err)
assert.NotEmpty(t, string(output))
}
func TestCompletionFish(t *testing.T) {
tempFile, err := ioutil.TempFile("", "completion_fish")
tempFile, err := os.CreateTemp("", "completion_fish")
assert.NoError(t, err)
defer func() {
_ = tempFile.Close()
@ -85,14 +84,14 @@ func TestCompletionFish(t *testing.T) {
fishCommandDefinition.Run(fishCommandDefinition, []string{tempFile.Name()})
bs, err := ioutil.ReadFile(tempFile.Name())
bs, err := os.ReadFile(tempFile.Name())
assert.NoError(t, err)
assert.NotEmpty(t, string(bs))
}
func TestCompletionFishStdout(t *testing.T) {
originalStdout := os.Stdout
tempFile, err := ioutil.TempFile("", "completion_zsh")
tempFile, err := os.CreateTemp("", "completion_zsh")
assert.NoError(t, err)
defer func() {
_ = tempFile.Close()
@ -104,7 +103,7 @@ func TestCompletionFishStdout(t *testing.T) {
fishCommandDefinition.Run(fishCommandDefinition, []string{"-"})
output, err := ioutil.ReadFile(tempFile.Name())
output, err := os.ReadFile(tempFile.Name())
assert.NoError(t, err)
assert.NotEmpty(t, string(output))
}