Skip to content

Commit

Permalink
Merge pull request #1223 from umagnus/replace-deprecated-ioutil
Browse files Browse the repository at this point in the history
cleanup: replace deprecated ioutil method
  • Loading branch information
k8s-ci-robot authored Apr 20, 2023
2 parents df33325 + 79f5958 commit 2a556fb
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 15 deletions.
5 changes: 2 additions & 3 deletions pkg/azurefile/azure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package azurefile
import (
"context"
"fmt"
"io/ioutil"
"os"
"reflect"
"runtime"
Expand Down Expand Up @@ -151,7 +150,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 @@ -364,7 +363,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/azurefile/azurefile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"encoding/base64"
"fmt"
"io/ioutil"
"net/url"
"os"
"path/filepath"
Expand Down Expand Up @@ -544,7 +543,7 @@ func TestGetSnapshot(t *testing.T) {

func TestIsCorruptedDir(t *testing.T) {
skipIfTestingOnWindows(t)
existingMountPath, err := ioutil.TempDir(os.TempDir(), "csi-mount-test")
existingMountPath, err := os.MkdirTemp(os.TempDir(), "csi-mount-test")
if err != nil {
t.Fatalf("failed to create tmp dir: %v", err)
}
Expand Down Expand Up @@ -912,7 +911,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 @@ -937,7 +936,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
3 changes: 1 addition & 2 deletions pkg/azurefile/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package azurefile

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -524,7 +523,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
3 changes: 1 addition & 2 deletions test/utils/credentials/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package credentials
import (
"fmt"
"html/template"
"io/ioutil"
"log"
"os"

Expand Down Expand Up @@ -168,7 +167,7 @@ func DeleteAzureCredentialFile() error {
// getCredentialsFromAzureCredentials parses the azure credentials toml (AZURE_CREDENTIALS)
// in Prow and returns the credential information usable to Azure File 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 %v", 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 @@ -83,7 +82,7 @@ func TestCreateAzureCredentialFileOnAzurePublicCloud(t *testing.T) {
}

func withAzureCredentials(t *testing.T, isAzureChinaCloud bool) {
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 @@ -117,7 +116,7 @@ func withAzureCredentials(t *testing.T, isAzureChinaCloud bool) {
assert.Equal(t, "test-resource-group", creds.ResourceGroup)
assert.Equal(t, "test-location", creds.Location)

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

const expectedAzureCredentialFileContent = `
Expand Down Expand Up @@ -171,7 +170,7 @@ func withEnvironmentVariables(t *testing.T, isAzureChinaCloud bool) {
assert.Equal(t, "test-resource-group", creds.ResourceGroup)
assert.Equal(t, "test-location", creds.Location)

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

const expectedAzureCredentialFileContent = `
Expand Down

0 comments on commit 2a556fb

Please sign in to comment.