diff --git a/pkg/cmd/template/regular_input_test.go b/pkg/cmd/template/regular_input_test.go index b94e3f13..71da5a05 100644 --- a/pkg/cmd/template/regular_input_test.go +++ b/pkg/cmd/template/regular_input_test.go @@ -7,7 +7,7 @@ import ( "bytes" "errors" "fmt" - "io/ioutil" + "io" "os" "testing" @@ -66,7 +66,7 @@ organization=Acme Widgets Inc.`) files.MustNewFileFromSource(files.NewBytesSource("foo.yaml", yamlData)), } - outputDir, err := ioutil.TempDir(os.TempDir(), "fakedir") + outputDir, err := os.MkdirTemp(os.TempDir(), "fakedir") require.NoError(t, err) defer os.RemoveAll(outputDir) @@ -252,12 +252,12 @@ func TestFileMarkMultipleExcludes(t *testing.T) { } func assertStdoutAndStderr(t *testing.T, stdout *bytes.Buffer, stderr *bytes.Buffer, expectedStdOut string, expectedStdErr string) { - stdoutOutput, err := ioutil.ReadAll(stdout) + stdoutOutput, err := io.ReadAll(stdout) require.NoError(t, err, "reading stdout") require.Equal(t, expectedStdOut, string(stdoutOutput), "comparing stdout") - stderrOutput, err := ioutil.ReadAll(stderr) + stderrOutput, err := io.ReadAll(stderr) require.NoError(t, err, "reading stdout") require.Equal(t, expectedStdErr, string(stderrOutput), "comparing stderr") diff --git a/pkg/files/sources.go b/pkg/files/sources.go index 7119309c..7a59a6a9 100644 --- a/pkg/files/sources.go +++ b/pkg/files/sources.go @@ -5,7 +5,7 @@ package files import ( "fmt" - "io/ioutil" + "io" "net/http" "os" "path" @@ -81,7 +81,8 @@ func (s LocalSource) RelativePath() (string, error) { return "", fmt.Errorf("unknown relative path for %s", s.path) } -func (s LocalSource) Bytes() ([]byte, error) { return ioutil.ReadFile(s.path) } +// Bytes returns bytes of the read file +func (s LocalSource) Bytes() ([]byte, error) { return os.ReadFile(s.path) } type HTTPSource struct { url string @@ -109,7 +110,7 @@ func (s HTTPSource) Bytes() ([]byte, error) { return nil, fmt.Errorf("Requesting URL '%s': %s", s.url, resp.Status) } - result, err := ioutil.ReadAll(resp.Body) + result, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("Reading URL '%s': %s", s.url, err) } diff --git a/pkg/files/sources_test.go b/pkg/files/sources_test.go index 09a0e5d0..0562abef 100644 --- a/pkg/files/sources_test.go +++ b/pkg/files/sources_test.go @@ -6,7 +6,7 @@ package files_test import ( "bytes" "fmt" - "io/ioutil" + "io" "net/http" "testing" @@ -23,7 +23,7 @@ func TestHTTPFileSources(t *testing.T) { return &http.Response{ StatusCode: http.StatusOK, // Send response to be tested - Body: ioutil.NopCloser(bytes.NewBufferString(`OK`)), + Body: io.NopCloser(bytes.NewBufferString(`OK`)), // Must be set to non-nil value or it panics Header: make(http.Header), } @@ -41,7 +41,7 @@ func TestHTTPFileSources(t *testing.T) { require.Equal(t, req.URL.String(), url) return &http.Response{ StatusCode: http.StatusIMUsed, - Body: ioutil.NopCloser(bytes.NewBufferString(`OK`)), + Body: io.NopCloser(bytes.NewBufferString(`OK`)), Header: make(http.Header), } }) diff --git a/pkg/files/stdin.go b/pkg/files/stdin.go index ad1bd0e6..f7f6c4d7 100644 --- a/pkg/files/stdin.go +++ b/pkg/files/stdin.go @@ -5,7 +5,7 @@ package files import ( "fmt" - "io/ioutil" + "io" "os" ) @@ -17,5 +17,5 @@ func ReadStdin() ([]byte, error) { return nil, fmt.Errorf("Standard input has already been read, has the '-' argument been used in more than one flag?") } hasStdinBeenRead = true - return ioutil.ReadAll(os.Stdin) + return io.ReadAll(os.Stdin) } diff --git a/pkg/texttemplate/template_test.go b/pkg/texttemplate/template_test.go index 71f0c51e..a615fd94 100644 --- a/pkg/texttemplate/template_test.go +++ b/pkg/texttemplate/template_test.go @@ -5,7 +5,6 @@ package texttemplate_test import ( "fmt" - "io/ioutil" "os" "path/filepath" "regexp" @@ -24,7 +23,7 @@ var ( ) func TestTextTemplate(t *testing.T) { - files, err := ioutil.ReadDir("filetests") + files, err := os.ReadDir("filetests") if err != nil { t.Fatal(err) } @@ -45,7 +44,7 @@ func TestTextTemplate(t *testing.T) { testDesc := fmt.Sprintf("checking %s ...\n", file.Name()) fmt.Printf("%s", testDesc) - contents, err := ioutil.ReadFile(filePath) + contents, err := os.ReadFile(filePath) if err != nil { t.Fatal(err) } diff --git a/pkg/website/server.go b/pkg/website/server.go index b5763019..bdd146a3 100644 --- a/pkg/website/server.go +++ b/pkg/website/server.go @@ -6,7 +6,7 @@ package website import ( "encoding/json" "fmt" - "io/ioutil" + "io" "log" "net" "net/http" @@ -115,7 +115,7 @@ func (s *Server) examplesHandler(w http.ResponseWriter, r *http.Request) { } func (s *Server) templateHandler(w http.ResponseWriter, r *http.Request) { - data, err := ioutil.ReadAll(r.Body) + data, err := io.ReadAll(r.Body) if err != nil { s.logError(w, err) return diff --git a/pkg/yamlfmt/printer_test.go b/pkg/yamlfmt/printer_test.go index 7b3db1fa..143049ed 100644 --- a/pkg/yamlfmt/printer_test.go +++ b/pkg/yamlfmt/printer_test.go @@ -5,7 +5,6 @@ package yamlfmt_test import ( "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -51,7 +50,7 @@ func TestYAMLFmt(t *testing.T) { testDesc := fmt.Sprintf("checking %s ...\n", filePath) fmt.Printf("%s", testDesc) - contents, err := ioutil.ReadFile(filePath) + contents, err := os.ReadFile(filePath) if err != nil { t.Fatal(err) } diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index 42078fb6..c79cf048 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -7,7 +7,6 @@ import ( "bytes" "fmt" "io/fs" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -111,7 +110,7 @@ float: 123.123 } actualOutput := runYtt(t, testInputFiles{testDir + "/config"}, "", flags, nil) - expectedOutput, err := ioutil.ReadFile(filepath.Join(testDir, "expected.txt")) + expectedOutput, err := os.ReadFile(filepath.Join(testDir, "expected.txt")) require.NoError(t, err) require.Equal(t, string(expectedOutput), actualOutput) @@ -138,7 +137,7 @@ float: 0 }) t.Run("can be 'required'", func(t *testing.T) { - expectedFileOutput, err := ioutil.ReadFile("../../examples/data-values-required/expected.txt") + expectedFileOutput, err := os.ReadFile("../../examples/data-values-required/expected.txt") require.NoError(t, err) dirs := []string{ @@ -212,7 +211,7 @@ func TestSchema(t *testing.T) { dirPath := fmt.Sprintf("../../examples/%s", dir) actualOutput := runYtt(t, testInputFiles{dirPath}, "", nil, nil) - expectedOutput, err := ioutil.ReadFile(filepath.Join(dirPath, "expected.txt")) + expectedOutput, err := os.ReadFile(filepath.Join(dirPath, "expected.txt")) require.NoError(t, err) require.Equal(t, string(expectedOutput), actualOutput) @@ -232,7 +231,7 @@ func TestOverlays(t *testing.T) { dirPath := fmt.Sprintf("../../examples/%s", dir) actualOutput := runYtt(t, testInputFiles{dirPath}, "", nil, nil) - expectedOutput, err := ioutil.ReadFile(filepath.Join(dirPath, "expected.txt")) + expectedOutput, err := os.ReadFile(filepath.Join(dirPath, "expected.txt")) require.NoError(t, err) require.Equal(t, string(expectedOutput), actualOutput) @@ -264,7 +263,7 @@ func TestReadingFromStandardIn(t *testing.T) { t.Run("through --file", func(t *testing.T) { actualOutput := runYtt(t, []string{"-", "../../examples/eirini/input.yml"}, "../../examples/eirini/config.yml", nil, nil) - expectedFileOutput, err := ioutil.ReadFile("../../examples/eirini/config-result.yml") + expectedFileOutput, err := os.ReadFile("../../examples/eirini/config-result.yml") require.NoError(t, err) require.Equal(t, string(expectedFileOutput), actualOutput) }) @@ -294,16 +293,16 @@ new_thing: new } func TestCheckDirectoryOutput(t *testing.T) { - tempOutputDir, err := ioutil.TempDir(os.TempDir(), "ytt-check-dir") + tempOutputDir, err := os.MkdirTemp(os.TempDir(), "ytt-check-dir") require.NoError(t, err) defer os.Remove(tempOutputDir) flags := yttFlags{{fmt.Sprintf("--dangerous-emptied-output-directory=%s", tempOutputDir): ""}} runYtt(t, []string{"../../examples/eirini/"}, "", flags, nil) - expectedFileOutput, err := ioutil.ReadFile("../../examples/eirini/config-result.yml") + expectedFileOutput, err := os.ReadFile("../../examples/eirini/config-result.yml") require.NoError(t, err) - actualOutput, err := ioutil.ReadFile(filepath.Join(tempOutputDir, "config-result.yml")) + actualOutput, err := os.ReadFile(filepath.Join(tempOutputDir, "config-result.yml")) require.NoError(t, err) require.Equal(t, string(expectedFileOutput), string(actualOutput)) @@ -371,7 +370,7 @@ func TestApplicationSpecificScenarios(t *testing.T) { dirPath := fmt.Sprintf("../../examples/%s", dir) actualOutput := runYtt(t, testInputFiles{dirPath}, "", nil, nil) - expectedOutput, err := ioutil.ReadFile(filepath.Join(dirPath, "expected.txt")) + expectedOutput, err := os.ReadFile(filepath.Join(dirPath, "expected.txt")) require.NoError(t, err) require.Equal(t, string(expectedOutput), actualOutput) @@ -385,7 +384,7 @@ func TestApplicationSpecificScenarios(t *testing.T) { dirPath := fmt.Sprintf("../../examples/%s", dir) actualOutput := runYtt(t, testInputFiles{dirPath}, "", nil, nil) - expectedOutput, err := ioutil.ReadFile(filepath.Join(dirPath, "expected.txt")) + expectedOutput, err := os.ReadFile(filepath.Join(dirPath, "expected.txt")) require.NoError(t, err) require.Equal(t, string(expectedOutput), actualOutput) @@ -396,14 +395,14 @@ func TestApplicationSpecificScenarios(t *testing.T) { t.Run("config.yml", func(t *testing.T) { actualOutput := runYtt(t, []string{"../../examples/eirini/config.yml", "../../examples/eirini/input.yml"}, "", nil, nil) - expectedFileOutput, err := ioutil.ReadFile("../../examples/eirini/config-result.yml") + expectedFileOutput, err := os.ReadFile("../../examples/eirini/config-result.yml") require.NoError(t, err) require.Equal(t, string(expectedFileOutput), actualOutput) }) t.Run("config-alt1.yml", func(t *testing.T) { actualOutput := runYtt(t, []string{"../../examples/eirini/config-alt1.yml", "../../examples/eirini/input.yml"}, "", nil, nil) - expectedFileOutput, err := ioutil.ReadFile("../../examples/eirini/config-result.yml") + expectedFileOutput, err := os.ReadFile("../../examples/eirini/config-result.yml") require.NoError(t, err) require.Equal(t, string(expectedFileOutput), actualOutput) }) @@ -416,7 +415,7 @@ func TestApplicationSpecificScenarios(t *testing.T) { "../../examples/eirini/input.yml"}, "", nil, nil) - expectedFileOutput, err := ioutil.ReadFile("../../examples/eirini/config-result.yml") + expectedFileOutput, err := os.ReadFile("../../examples/eirini/config-result.yml") require.NoError(t, err) require.Equal(t, string(expectedFileOutput), actualOutput) }) @@ -434,7 +433,7 @@ func TestRemainingExamples(t *testing.T) { dirPath := fmt.Sprintf("../../examples/%s", dir) actualOutput := runYtt(t, testInputFiles{dirPath}, "", nil, nil) - expectedOutput, err := ioutil.ReadFile(filepath.Join(dirPath, "expected.txt")) + expectedOutput, err := os.ReadFile(filepath.Join(dirPath, "expected.txt")) require.NoError(t, err) require.Equal(t, string(expectedOutput), actualOutput) diff --git a/test/filetests/filetests.go b/test/filetests/filetests.go index 9378d78c..6a2a8dca 100644 --- a/test/filetests/filetests.go +++ b/test/filetests/filetests.go @@ -10,7 +10,6 @@ package filetests import ( "fmt" "io" - "io/ioutil" "os" "path/filepath" "regexp" @@ -86,7 +85,7 @@ func (f FileTests) Run(t *testing.T) { for _, filePath := range files { t.Run(filePath, func(t *testing.T) { - contents, err := ioutil.ReadFile(filePath) + contents, err := os.ReadFile(filePath) if err != nil { t.Fatal(err) }