From 976fce123a2c5338444778273b22c44c85e3a2a1 Mon Sep 17 00:00:00 2001 From: Max Lampert Date: Mon, 28 Aug 2023 04:05:02 +0200 Subject: [PATCH] Remove deprecated io/ioutil --- builder/azure/arm/builder_acc_test.go | 3 +-- builder/azure/arm/config.go | 6 +++--- builder/azure/arm/config_test.go | 5 ++--- builder/azure/arm/inspector.go | 5 ++--- builder/azure/chroot/packerui_test.go | 4 ++-- builder/azure/chroot/step_attach_disk_test.go | 4 ++-- builder/azure/chroot/step_mount_device_test.go | 3 +-- builder/azure/common/client/config_retriever.go | 4 ++-- builder/azure/dtl/inspector.go | 8 +++----- 9 files changed, 18 insertions(+), 24 deletions(-) diff --git a/builder/azure/arm/builder_acc_test.go b/builder/azure/arm/builder_acc_test.go index 29d0dfde..6b942513 100644 --- a/builder/azure/arm/builder_acc_test.go +++ b/builder/azure/arm/builder_acc_test.go @@ -31,7 +31,6 @@ import ( "context" _ "embed" "fmt" - "io/ioutil" "os" "os/exec" "testing" @@ -304,7 +303,7 @@ func TestBuilderAcc_Blob_Linux(t *testing.T) { func TestBuilderUserData_Linux(t *testing.T) { t.Parallel() - tmpfile, err := ioutil.TempFile("", "userdata") + tmpfile, err := os.CreateTemp("", "userdata") if err != nil { t.Fatalf("failed creating tempfile: %s", err) } diff --git a/builder/azure/arm/config.go b/builder/azure/arm/config.go index 1bcafdb0..d3009cc4 100644 --- a/builder/azure/arm/config.go +++ b/builder/azure/arm/config.go @@ -14,9 +14,9 @@ import ( "encoding/base64" "encoding/json" "fmt" - "io/ioutil" "math/big" "net" + "os" "regexp" "strings" "time" @@ -952,7 +952,7 @@ func setCustomDataFile(c *Config) error { return nil } - b, err := ioutil.ReadFile(c.CustomDataFile) + b, err := os.ReadFile(c.CustomDataFile) if err != nil { return err } @@ -975,7 +975,7 @@ func setUserDataFile(c *Config) error { return nil } - b, err := ioutil.ReadFile(c.UserDataFile) + b, err := os.ReadFile(c.UserDataFile) if err != nil { return err } diff --git a/builder/azure/arm/config_test.go b/builder/azure/arm/config_test.go index 1d58a1c5..99c7fd30 100644 --- a/builder/azure/arm/config_test.go +++ b/builder/azure/arm/config_test.go @@ -5,7 +5,6 @@ package arm import ( "fmt" - "io/ioutil" "os" "strings" "testing" @@ -2496,7 +2495,7 @@ func TestConfigShouldRejectMalformedUserAssignedManagedIdentities(t *testing.T) } func TestConfigShouldRejectUserDataAndUserDataFile(t *testing.T) { - tmpfile, err := ioutil.TempFile("", "userdata") + tmpfile, err := os.CreateTemp("", "userdata") if err != nil { t.Fatalf("failed creating tempfile: %s", err) } @@ -2527,7 +2526,7 @@ func TestConfigShouldRejectUserDataAndUserDataFile(t *testing.T) { } func TestConfigShouldRejectCustomDataAndCustomDataFile(t *testing.T) { - tmpfile, err := ioutil.TempFile("", "customdata") + tmpfile, err := os.CreateTemp("", "customdata") if err != nil { t.Fatalf("failed creating tempfile: %s", err) } diff --git a/builder/azure/arm/inspector.go b/builder/azure/arm/inspector.go index 44736e3c..7bac9576 100644 --- a/builder/azure/arm/inspector.go +++ b/builder/azure/arm/inspector.go @@ -5,7 +5,6 @@ package arm import ( "bytes" - "io/ioutil" "log" "net/http" @@ -32,12 +31,12 @@ func handleBody(body io.ReadCloser, maxlen int64) (io.ReadCloser, string) { defer body.Close() - b, err := ioutil.ReadAll(body) + b, err := io.ReadAll(body) if err != nil { return nil, "" } - return ioutil.NopCloser(bytes.NewReader(b)), chop(b, maxlen) + return io.NopCloser(bytes.NewReader(b)), chop(b, maxlen) } // WithInspection/ByInspection functions are used to Log requests and responses from Azure diff --git a/builder/azure/chroot/packerui_test.go b/builder/azure/chroot/packerui_test.go index 31137c6d..3e4c15ad 100644 --- a/builder/azure/chroot/packerui_test.go +++ b/builder/azure/chroot/packerui_test.go @@ -4,7 +4,7 @@ package chroot import ( - "io/ioutil" + "io" "strings" packersdk "github.com/hashicorp/packer-plugin-sdk/packer" @@ -15,7 +15,7 @@ func testUI() (packersdk.Ui, func() string) { errorBuffer := &strings.Builder{} ui := &packersdk.BasicUi{ Reader: strings.NewReader(""), - Writer: ioutil.Discard, + Writer: io.Discard, ErrorWriter: errorBuffer, } return ui, errorBuffer.String diff --git a/builder/azure/chroot/step_attach_disk_test.go b/builder/azure/chroot/step_attach_disk_test.go index 74522966..841c50ab 100644 --- a/builder/azure/chroot/step_attach_disk_test.go +++ b/builder/azure/chroot/step_attach_disk_test.go @@ -6,7 +6,7 @@ package chroot import ( "context" "errors" - "io/ioutil" + "io" "reflect" "strings" "testing" @@ -55,7 +55,7 @@ func TestStepAttachDisk_Run(t *testing.T) { errorBuffer := &strings.Builder{} ui := &packersdk.BasicUi{ Reader: strings.NewReader(""), - Writer: ioutil.Discard, + Writer: io.Discard, ErrorWriter: errorBuffer, } diff --git a/builder/azure/chroot/step_mount_device_test.go b/builder/azure/chroot/step_mount_device_test.go index 96ec1b10..54d08d63 100644 --- a/builder/azure/chroot/step_mount_device_test.go +++ b/builder/azure/chroot/step_mount_device_test.go @@ -6,7 +6,6 @@ package chroot import ( "context" "fmt" - "io/ioutil" "os" "runtime" "testing" @@ -23,7 +22,7 @@ func TestStepMountDevice_Run(t *testing.T) { default: t.Skip("Unsupported operating system") } - mountPath, err := ioutil.TempDir("", "stepmountdevicetest") + mountPath, err := os.MkdirTemp("", "stepmountdevicetest") if err != nil { t.Errorf("Unable to create a temporary directory: %q", err) } diff --git a/builder/azure/common/client/config_retriever.go b/builder/azure/common/client/config_retriever.go index b3ebfd2a..0c021299 100644 --- a/builder/azure/common/client/config_retriever.go +++ b/builder/azure/common/client/config_retriever.go @@ -5,7 +5,7 @@ package client import ( "encoding/json" - "io/ioutil" + "io" "net/http" ) @@ -29,7 +29,7 @@ func _getSubscriptionFromIMDS() (string, error) { } defer resp.Body.Close() - resp_body, _ := ioutil.ReadAll(resp.Body) + resp_body, _ := io.ReadAll(resp.Body) result := map[string]string{} err = json.Unmarshal(resp_body, &result) if err != nil { diff --git a/builder/azure/dtl/inspector.go b/builder/azure/dtl/inspector.go index 71f3ab2c..0ca7279e 100644 --- a/builder/azure/dtl/inspector.go +++ b/builder/azure/dtl/inspector.go @@ -5,12 +5,10 @@ package dtl import ( "bytes" - "io/ioutil" + "io" "log" "net/http" - "io" - "github.com/Azure/go-autorest/autorest" "github.com/Azure/go-autorest/autorest/azure" "github.com/hashicorp/go-azure-sdk/sdk/client" @@ -32,12 +30,12 @@ func handleBody(body io.ReadCloser, maxlen int64) (io.ReadCloser, string) { defer body.Close() - b, err := ioutil.ReadAll(body) + b, err := io.ReadAll(body) if err != nil { return nil, "" } - return ioutil.NopCloser(bytes.NewReader(b)), chop(b, maxlen) + return io.NopCloser(bytes.NewReader(b)), chop(b, maxlen) } func withInspection(maxlen int64) autorest.PrepareDecorator {