Skip to content

Commit

Permalink
Remove deprecated io/ioutil
Browse files Browse the repository at this point in the history
  • Loading branch information
maxilampert authored and nywilken committed Oct 2, 2023
1 parent c472969 commit 976fce1
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 24 deletions.
3 changes: 1 addition & 2 deletions builder/azure/arm/builder_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"context"
_ "embed"
"fmt"
"io/ioutil"
"os"
"os/exec"
"testing"
Expand Down Expand Up @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions builder/azure/arm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"io/ioutil"
"math/big"
"net"
"os"
"regexp"
"strings"
"time"
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
5 changes: 2 additions & 3 deletions builder/azure/arm/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package arm

import (
"fmt"
"io/ioutil"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
5 changes: 2 additions & 3 deletions builder/azure/arm/inspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package arm

import (
"bytes"
"io/ioutil"
"log"
"net/http"

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions builder/azure/chroot/packerui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package chroot

import (
"io/ioutil"
"io"
"strings"

packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions builder/azure/chroot/step_attach_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package chroot
import (
"context"
"errors"
"io/ioutil"
"io"
"reflect"
"strings"
"testing"
Expand Down Expand Up @@ -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,
}

Expand Down
3 changes: 1 addition & 2 deletions builder/azure/chroot/step_mount_device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package chroot
import (
"context"
"fmt"
"io/ioutil"
"os"
"runtime"
"testing"
Expand All @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions builder/azure/common/client/config_retriever.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package client

import (
"encoding/json"
"io/ioutil"
"io"
"net/http"
)

Expand All @@ -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 {
Expand Down
8 changes: 3 additions & 5 deletions builder/azure/dtl/inspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down

0 comments on commit 976fce1

Please sign in to comment.