cleanup TempDir properly
a TempDir is like /tmp/minipath255070191/.minikube Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>pull/8490/head
parent
804e772efd
commit
24c9ce079d
|
@ -115,7 +115,7 @@ func hideEnv(t *testing.T) func(t *testing.T) {
|
|||
func TestPreRunDirectories(t *testing.T) {
|
||||
// Make sure we create the required directories.
|
||||
tempDir := tests.MakeTempDir()
|
||||
defer os.RemoveAll(tempDir)
|
||||
defer tests.RemoveTempDir(tempDir)
|
||||
|
||||
runCommand(RootCmd.PersistentPreRun)
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ import (
|
|||
|
||||
func Test_createDiskImage(t *testing.T) {
|
||||
tmpdir := tests.MakeTempDir()
|
||||
defer os.RemoveAll(tmpdir)
|
||||
defer tests.RemoveTempDir(tmpdir)
|
||||
|
||||
sshPath := filepath.Join(tmpdir, "ssh")
|
||||
if err := ioutil.WriteFile(sshPath, []byte("mysshkey"), 0644); err != nil {
|
||||
|
|
|
@ -51,7 +51,7 @@ var validLeases = []byte(`{
|
|||
|
||||
func Test_getIpAddressFromFile(t *testing.T) {
|
||||
tmpdir := tests.MakeTempDir()
|
||||
defer os.RemoveAll(tmpdir)
|
||||
defer tests.RemoveTempDir(tmpdir)
|
||||
|
||||
dhcpFile := filepath.Join(tmpdir, "dhcp")
|
||||
if err := ioutil.WriteFile(dhcpFile, validLeases, 0644); err != nil {
|
||||
|
|
|
@ -30,7 +30,7 @@ import (
|
|||
|
||||
func TestSetupCerts(t *testing.T) {
|
||||
tempDir := tests.MakeTempDir()
|
||||
defer os.RemoveAll(tempDir)
|
||||
defer tests.RemoveTempDir(tempDir)
|
||||
|
||||
k8s := config.KubernetesConfig{
|
||||
APIServerName: constants.APIServerName,
|
||||
|
|
|
@ -43,7 +43,7 @@ func TestMaybePrintUpdateTextFromGithub(t *testing.T) {
|
|||
|
||||
func TestShouldCheckURL(t *testing.T) {
|
||||
tempDir := tests.MakeTempDir()
|
||||
defer os.RemoveAll(tempDir)
|
||||
defer tests.RemoveTempDir(tempDir)
|
||||
|
||||
lastUpdateCheckFilePath := filepath.Join(tempDir, "last_update_check")
|
||||
|
||||
|
@ -152,7 +152,7 @@ func TestGetLatestVersionFromURLMalformed(t *testing.T) {
|
|||
|
||||
func TestMaybePrintUpdateText(t *testing.T) {
|
||||
tempDir := tests.MakeTempDir()
|
||||
defer os.RemoveAll(tempDir)
|
||||
defer tests.RemoveTempDir(tempDir)
|
||||
outputBuffer := tests.NewFakeFile()
|
||||
out.SetErrFile(outputBuffer)
|
||||
|
||||
|
|
|
@ -45,6 +45,13 @@ func MakeTempDir() string {
|
|||
return localpath.MiniPath()
|
||||
}
|
||||
|
||||
func RemoveTempDir(tempdir string) {
|
||||
if filepath.Base(tempdir) == ".minikube" {
|
||||
tempdir = filepath.Dir(tempdir)
|
||||
}
|
||||
os.RemoveAll(tempdir)
|
||||
}
|
||||
|
||||
// FakeFile satisfies fdWriter
|
||||
type FakeFile struct {
|
||||
b bytes.Buffer
|
||||
|
|
Loading…
Reference in New Issue