e2e: remove deprecated io/ioutil and use t.TempDir()

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-02-25 15:32:16 +01:00
parent 39ace68061
commit e89af84ffc
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
2 changed files with 5 additions and 12 deletions

View File

@ -1,7 +1,6 @@
package context package context
import ( import (
"io/ioutil"
"os" "os"
"testing" "testing"
@ -21,10 +20,7 @@ func TestContextList(t *testing.T) {
} }
func TestContextImportNoTLS(t *testing.T) { func TestContextImportNoTLS(t *testing.T) {
d, _ := ioutil.TempDir("", "") d := t.TempDir()
defer func() {
os.RemoveAll(d)
}()
cmd := icmd.Command("docker", "context", "import", "remote", "./testdata/test-dockerconfig.tar") cmd := icmd.Command("docker", "context", "import", "remote", "./testdata/test-dockerconfig.tar")
cmd.Env = append(cmd.Env, cmd.Env = append(cmd.Env,
"DOCKER_CONFIG="+d, "DOCKER_CONFIG="+d,
@ -38,10 +34,7 @@ func TestContextImportNoTLS(t *testing.T) {
} }
func TestContextImportTLS(t *testing.T) { func TestContextImportTLS(t *testing.T) {
d, _ := ioutil.TempDir("", "") d := t.TempDir()
defer func() {
os.RemoveAll(d)
}()
cmd := icmd.Command("docker", "context", "import", "test", "./testdata/test-dockerconfig-tls.tar") cmd := icmd.Command("docker", "context", "import", "test", "./testdata/test-dockerconfig-tls.tar")
cmd.Env = append(cmd.Env, cmd.Env = append(cmd.Env,
"DOCKER_CONFIG="+d, "DOCKER_CONFIG="+d,
@ -55,7 +48,7 @@ func TestContextImportTLS(t *testing.T) {
result := icmd.RunCmd(cmd).Assert(t, icmd.Success) result := icmd.RunCmd(cmd).Assert(t, icmd.Success)
golden.Assert(t, result.Stdout(), "context-ls-tls.golden") 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.NilError(t, err)
assert.Equal(t, string(b), `-----BEGIN RSA PRIVATE KEY----- assert.Equal(t, string(b), `-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEArQk77K5sgrQYY6HiQ1y7AC+67HrRB36oEvR+Fq60RsFcc3cZ MIIEpAIBAAKCAQEArQk77K5sgrQYY6HiQ1y7AC+67HrRB36oEvR+Fq60RsFcc3cZ

View File

@ -2,7 +2,7 @@ package image
import ( import (
"fmt" "fmt"
"io/ioutil" "os"
"path/filepath" "path/filepath"
"strings" "strings"
"testing" "testing"
@ -141,7 +141,7 @@ func TestBuildIidFileSquash(t *testing.T) {
withWorkingDir(buildDir), withWorkingDir(buildDir),
) )
result.Assert(t, icmd.Success) result.Assert(t, icmd.Success)
id, err := ioutil.ReadFile(iidfile) id, err := os.ReadFile(iidfile)
assert.NilError(t, err) assert.NilError(t, err)
result = icmd.RunCommand("docker", "image", "inspect", "-f", "{{.Id}}", imageTag) result = icmd.RunCommand("docker", "image", "inspect", "-f", "{{.Id}}", imageTag)
result.Assert(t, icmd.Success) result.Assert(t, icmd.Success)