From e89af84ffc0e7e6f96cc205d230533e9c3ed3941 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 25 Feb 2022 15:32:16 +0100 Subject: [PATCH] e2e: remove deprecated io/ioutil and use t.TempDir() Signed-off-by: Sebastiaan van Stijn --- e2e/context/context_test.go | 13 +++---------- e2e/image/build_test.go | 4 ++-- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/e2e/context/context_test.go b/e2e/context/context_test.go index 05cbca3d83..649e4f768c 100644 --- a/e2e/context/context_test.go +++ b/e2e/context/context_test.go @@ -1,7 +1,6 @@ package context import ( - "io/ioutil" "os" "testing" @@ -21,10 +20,7 @@ func TestContextList(t *testing.T) { } func TestContextImportNoTLS(t *testing.T) { - d, _ := ioutil.TempDir("", "") - defer func() { - os.RemoveAll(d) - }() + d := t.TempDir() cmd := icmd.Command("docker", "context", "import", "remote", "./testdata/test-dockerconfig.tar") cmd.Env = append(cmd.Env, "DOCKER_CONFIG="+d, @@ -38,10 +34,7 @@ func TestContextImportNoTLS(t *testing.T) { } func TestContextImportTLS(t *testing.T) { - d, _ := ioutil.TempDir("", "") - defer func() { - os.RemoveAll(d) - }() + d := t.TempDir() cmd := icmd.Command("docker", "context", "import", "test", "./testdata/test-dockerconfig-tls.tar") cmd.Env = append(cmd.Env, "DOCKER_CONFIG="+d, @@ -55,7 +48,7 @@ func TestContextImportTLS(t *testing.T) { result := icmd.RunCmd(cmd).Assert(t, icmd.Success) golden.Assert(t, result.Stdout(), "context-ls-tls.golden") - b, err := ioutil.ReadFile(d + "/contexts/tls/9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08/kubernetes/key.pem") + b, err := os.ReadFile(d + "/contexts/tls/9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08/kubernetes/key.pem") assert.NilError(t, err) assert.Equal(t, string(b), `-----BEGIN RSA PRIVATE KEY----- MIIEpAIBAAKCAQEArQk77K5sgrQYY6HiQ1y7AC+67HrRB36oEvR+Fq60RsFcc3cZ diff --git a/e2e/image/build_test.go b/e2e/image/build_test.go index 2adb1c120b..db298e40e7 100644 --- a/e2e/image/build_test.go +++ b/e2e/image/build_test.go @@ -2,7 +2,7 @@ package image import ( "fmt" - "io/ioutil" + "os" "path/filepath" "strings" "testing" @@ -141,7 +141,7 @@ func TestBuildIidFileSquash(t *testing.T) { withWorkingDir(buildDir), ) result.Assert(t, icmd.Success) - id, err := ioutil.ReadFile(iidfile) + id, err := os.ReadFile(iidfile) assert.NilError(t, err) result = icmd.RunCommand("docker", "image", "inspect", "-f", "{{.Id}}", imageTag) result.Assert(t, icmd.Success)