Skip to content

Commit

Permalink
replace deprecated ioutil method
Browse files Browse the repository at this point in the history
  • Loading branch information
umagnus committed Apr 20, 2023
1 parent 9a04374 commit 19175ea
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 16 deletions.
5 changes: 2 additions & 3 deletions pkg/blob/azure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package blob
import (
"context"
"fmt"
"io/ioutil"
"os"
"reflect"
"strings"
Expand Down Expand Up @@ -147,7 +146,7 @@ users:
}
}()

if err := ioutil.WriteFile(fakeKubeConfig, []byte(fakeContent), 0666); err != nil {
if err := os.WriteFile(fakeKubeConfig, []byte(fakeContent), 0666); err != nil {
t.Error(err)
}
}
Expand Down Expand Up @@ -423,7 +422,7 @@ users:
}
}()

if err := ioutil.WriteFile(validKubeConfig, []byte(fakeContent), 0666); err != nil {
if err := os.WriteFile(validKubeConfig, []byte(fakeContent), 0666); err != nil {
t.Error(err)
}

Expand Down
7 changes: 3 additions & 4 deletions pkg/blob/blob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"os"
"reflect"
"sort"
Expand Down Expand Up @@ -113,7 +112,7 @@ func TestRun(t *testing.T) {
{
name: "Successful run",
testFunc: func(t *testing.T) {
if err := ioutil.WriteFile(fakeCredFile, []byte(fakeCredContent), 0666); err != nil {
if err := os.WriteFile(fakeCredFile, []byte(fakeCredContent), 0666); err != nil {
t.Error(err)
}

Expand All @@ -138,7 +137,7 @@ func TestRun(t *testing.T) {
{
name: "Successful run with node ID missing",
testFunc: func(t *testing.T) {
if err := ioutil.WriteFile(fakeCredFile, []byte(fakeCredContent), 0666); err != nil {
if err := os.WriteFile(fakeCredFile, []byte(fakeCredContent), 0666); err != nil {
t.Error(err)
}

Expand Down Expand Up @@ -423,7 +422,7 @@ func TestIsSASToken(t *testing.T) {
}

func TestIsCorruptedDir(t *testing.T) {
existingMountPath, err := ioutil.TempDir(os.TempDir(), "blob-csi-mount-test")
existingMountPath, err := os.MkdirTemp(os.TempDir(), "blob-csi-mount-test")
if err != nil {
t.Fatalf("failed to create tmp dir: %v", err)
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/blob/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package blob
import (
"fmt"
"io/fs"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -563,7 +562,7 @@ func (d *Driver) ensureMountPoint(target string, perm os.FileMode) (bool, error)

if !notMnt {
// testing original mount point, make sure the mount link is valid
_, err := ioutil.ReadDir(target)
_, err := os.ReadDir(target)
if err == nil {
klog.V(2).Infof("already mounted to target %s", target)
return !notMnt, nil
Expand Down
5 changes: 2 additions & 3 deletions test/utils/credentials/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"encoding/json"
"fmt"
"html/template"
"io/ioutil"
"log"
"os"

Expand Down Expand Up @@ -140,7 +139,7 @@ func DeleteAzureCredentialFile() error {
// ParseAzureCredentialFile parses the temporary Azure credential file and returns the credentials
func ParseAzureCredentialFile() (*Credentials, error) {
cred := &Credentials{}
data, err := ioutil.ReadFile(TempAzureCredentialFilePath)
data, err := os.ReadFile(TempAzureCredentialFilePath)
if err != nil {
return nil, err
}
Expand All @@ -156,7 +155,7 @@ func ParseAzureCredentialFile() (*Credentials, error) {
// getCredentialsFromAzureCredentials parses the azure credentials toml (AZURE_CREDENTIALS)
// in Prow and returns the credential information usable to Azure Blob Storage CSI driver
func getCredentialsFromAzureCredentials(azureCredentialsPath string) (*FromProw, error) {
content, err := ioutil.ReadFile(azureCredentialsPath)
content, err := os.ReadFile(azureCredentialsPath)
log.Printf("Reading credentials file %v", azureCredentialsPath)
if err != nil {
return nil, fmt.Errorf("error reading credentials file %v %w", azureCredentialsPath, err)
Expand Down
7 changes: 3 additions & 4 deletions test/utils/credentials/credentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package credentials

import (
"bytes"
"io/ioutil"
"os"
"testing"
"text/template"
Expand Down Expand Up @@ -80,7 +79,7 @@ func TestCreateAzureCredentialFileOnAzureStackCloud(t *testing.T) {
}

func withAzureCredentials(t *testing.T) {
tempFile, err := ioutil.TempFile("", "azure.toml")
tempFile, err := os.CreateTemp("", "azure.toml")
assert.NoError(t, err)
defer func() {
err := os.Remove(tempFile.Name())
Expand Down Expand Up @@ -109,7 +108,7 @@ func withAzureCredentials(t *testing.T) {
assert.Equal(t, testResourceGroup, creds.ResourceGroup)
assert.Equal(t, testLocation, creds.Location)

azureCredentialFileContent, err := ioutil.ReadFile(TempAzureCredentialFilePath)
azureCredentialFileContent, err := os.ReadFile(TempAzureCredentialFilePath)
assert.NoError(t, err)

const expectedAzureCredentialFileContent = `
Expand Down Expand Up @@ -163,7 +162,7 @@ func withEnvironmentVariables(t *testing.T) {
assert.Equal(t, testResourceGroup, creds.ResourceGroup)
assert.Equal(t, testLocation, creds.Location)

azureCredentialFileContent, err := ioutil.ReadFile(TempAzureCredentialFilePath)
azureCredentialFileContent, err := os.ReadFile(TempAzureCredentialFilePath)
assert.NoError(t, err)

const expectedAzureCredentialFileContent = `
Expand Down

0 comments on commit 19175ea

Please sign in to comment.