clean up after test dirs

pull/7669/head
Medya Gh 2020-04-14 19:33:26 -07:00
parent 649819b963
commit d4b48e1e05
11 changed files with 90 additions and 10 deletions

View File

@ -65,6 +65,14 @@ func TestDeleteProfile(t *testing.T) {
if err != nil {
t.Fatalf("tempdir: %v", err)
}
defer func() { //clean up tempdir
err := os.RemoveAll(td)
if err != nil {
t.Errorf("failed to clean up temp folder %q", td)
}
}()
err = copy.Copy("../../../pkg/minikube/config/testdata/delete-single", td)
if err != nil {
t.Fatalf("copy: %v", err)
@ -154,7 +162,7 @@ func TestDeleteAllProfiles(t *testing.T) {
defer func() { //clean up tempdir
err := os.RemoveAll(td)
if err != nil {
t.Errorf("failed to clean up %q temp folder after the unit test.", td)
t.Errorf("failed to clean up temp folder %q", td)
}
}()

View File

@ -27,7 +27,12 @@ func TestExtractFile(t *testing.T) {
if nil != err {
return
}
defer os.Remove(testDir)
defer func() { //clean up tempdir
err := os.RemoveAll(testDir)
if err != nil {
t.Errorf("failed to clean up temp folder %q", testDir)
}
}()
tests := []struct {
name string

View File

@ -31,12 +31,24 @@ func TestCacheBinary(t *testing.T) {
if err != nil {
t.Fatalf("error during creating tmp dir: %v", err)
}
defer func() { //clean up tempdir
err := os.RemoveAll(minikubeHome)
if err != nil {
t.Errorf("failed to clean up temp folder %q", minikubeHome)
}
}()
defer os.RemoveAll(minikubeHome)
noWritePermDir, err := ioutil.TempDir("/tmp", "")
if err != nil {
t.Fatalf("error during creating tmp dir: %v", err)
}
defer os.RemoveAll(noWritePermDir)
defer func() { //clean up tempdir
err := os.RemoveAll(noWritePermDir)
if err != nil {
t.Errorf("failed to clean up temp folder %q", noWritePermDir)
}
}()
err = os.Chmod(noWritePermDir, 0000)
if err != nil {
t.Fatalf("error (%v) during changing permissions of dir %v", err, noWritePermDir)

View File

@ -36,7 +36,12 @@ func TestExtract(t *testing.T) {
if err != nil {
t.Fatalf("Creating temp dir: %v", err)
}
defer os.RemoveAll(tempdir)
defer func() { //clean up tempdir
err := os.RemoveAll(tempdir)
if err != nil {
t.Errorf("failed to clean up temp folder %q", tempdir)
}
}()
src, err := ioutil.ReadFile("testdata/test.json")
if err != nil {

View File

@ -167,6 +167,13 @@ func TestUpdate(t *testing.T) {
if err != nil {
t.Fatalf("Error making temp directory %v", err)
}
defer func() { //clean up tempdir
err := os.RemoveAll(tmpDir)
if err != nil {
t.Errorf("failed to clean up temp folder %q", tmpDir)
}
}()
test.cfg.SetPath(filepath.Join(tmpDir, "kubeconfig"))
if len(test.existingCfg) != 0 {
if err := ioutil.WriteFile(test.cfg.filePath(), test.existingCfg, 0600); err != nil {

View File

@ -33,7 +33,12 @@ func TestReplaceWinDriveLetterToVolumeName(t *testing.T) {
if err != nil {
t.Fatalf("Error make tmp directory: %v", err)
}
defer os.RemoveAll(path)
defer func() { //clean up tempdir
err := os.RemoveAll(path)
if err != nil {
t.Errorf("failed to clean up temp folder %q", path)
}
}()
if runtime.GOOS != "windows" {
// Replace to fake func.

View File

@ -89,7 +89,13 @@ func TestCacheBinariesForBootstrapper(t *testing.T) {
if err != nil {
t.Fatalf("error during creating tmp dir: %v", err)
}
defer os.RemoveAll(minikubeHome)
defer func() { //clean up tempdir
err := os.RemoveAll(minikubeHome)
if err != nil {
t.Errorf("failed to clean up temp folder %q", minikubeHome)
}
}()
var tc = []struct {
version, clusterBootstrapper string

View File

@ -125,7 +125,12 @@ func makeTempDir() string {
func TestRunNotDriver(t *testing.T) {
tempDir := makeTempDir()
defer os.RemoveAll(tempDir)
defer func() { //clean up tempdir
err := os.RemoveAll(tempDir)
if err != nil {
t.Errorf("failed to clean up temp folder %q", tempDir)
}
}()
StartDriver()
if !localbinary.CurrentBinaryIsDockerMachine {
t.Fatal("CurrentBinaryIsDockerMachine not set. This will break driver initialization.")

View File

@ -108,6 +108,12 @@ func TestAssetsFromDir(t *testing.T) {
for _, test := range tests {
t.Run(test.description, func(t *testing.T) {
testDir, err := setupTestDir()
defer func() { //clean up tempdir
err := os.RemoveAll(testDir)
if err != nil {
t.Errorf("failed to clean up temp folder %q", testDir)
}
}()
if err != nil {
t.Errorf("got unexpected error creating test dir: %v", err)
return

View File

@ -30,10 +30,15 @@ import (
func TestGenerateCACert(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "")
defer func() { //clean up tempdir
err := os.RemoveAll(tmpDir)
if err != nil {
t.Errorf("failed to clean up temp folder %q", tmpDir)
}
}()
if err != nil {
t.Fatalf("Error generating tmpdir: %v", err)
}
defer os.RemoveAll(tmpDir)
certPath := filepath.Join(tmpDir, "cert")
keyPath := filepath.Join(tmpDir, "key")
@ -58,16 +63,26 @@ func TestGenerateCACert(t *testing.T) {
func TestGenerateSignedCert(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "")
defer func() { //clean up tempdir
err := os.RemoveAll(tmpDir)
if err != nil {
t.Errorf("failed to clean up temp folder %q", tmpDir)
}
}()
if err != nil {
t.Fatalf("Error generating tmpdir: %v", err)
}
defer os.RemoveAll(tmpDir)
signerTmpDir, err := ioutil.TempDir("", "")
defer func() { //clean up tempdir
err := os.RemoveAll(signerTmpDir)
if err != nil {
t.Errorf("failed to clean up temp folder %q", signerTmpDir)
}
}()
if err != nil {
t.Fatalf("Error generating signer tmpdir: %v", err)
}
defer os.RemoveAll(signerTmpDir)
validSignerCertPath := filepath.Join(signerTmpDir, "cert")
validSignerKeyPath := filepath.Join(signerTmpDir, "key")

View File

@ -52,6 +52,12 @@ func validateMountCmd(ctx context.Context, t *testing.T, profile string) {
}
tempDir, err := ioutil.TempDir("", "mounttest")
defer func() { //clean up tempdir
err := os.RemoveAll(tempDir)
if err != nil {
t.Errorf("failed to clean up %q temp folder.", tempDir)
}
}()
if err != nil {
t.Fatalf("Unexpected error while creating tempDir: %v", err)
}