From 99b487739ef64ef243329b10ff029037fad52b99 Mon Sep 17 00:00:00 2001 From: Alan Ip Date: Wed, 11 Jan 2023 14:05:09 +0000 Subject: [PATCH] Remove zip files that were generated as a result of a test. --- internal/provider/zip_archiver_test.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/internal/provider/zip_archiver_test.go b/internal/provider/zip_archiver_test.go index 2c5b0133..440ee115 100644 --- a/internal/provider/zip_archiver_test.go +++ b/internal/provider/zip_archiver_test.go @@ -14,6 +14,7 @@ import ( func TestZipArchiver_Content(t *testing.T) { zipfilepath := "archive-content.zip" archiver := NewZipArchiver(zipfilepath) + defer os.Remove(zipfilepath) if err := archiver.ArchiveContent([]byte("This is some content"), "content.txt"); err != nil { t.Fatalf("unexpected error: %s", err) } @@ -26,6 +27,7 @@ func TestZipArchiver_Content(t *testing.T) { func TestZipArchiver_File(t *testing.T) { zipfilepath := "archive-file.zip" archiver := NewZipArchiver(zipfilepath) + defer os.Remove(zipfilepath) if err := archiver.ArchiveFile("./test-fixtures/test-file.txt"); err != nil { t.Fatalf("unexpected error: %s", err) } @@ -48,13 +50,16 @@ func TestZipArchiver_FileMode(t *testing.T) { stringArray := [5]string{"0444", "0644", "0666", "0744", "0777"} for _, element := range stringArray { - archiver := NewZipArchiver(zipFilePath) - archiver.SetOutputFileMode(element) - if err := archiver.ArchiveFile(toZipPath); err != nil { - t.Fatalf("unexpected error: %s", err) - } + func() { + archiver := NewZipArchiver(zipFilePath) + defer os.Remove(zipFilePath) + archiver.SetOutputFileMode(element) + if err := archiver.ArchiveFile(toZipPath); err != nil { + t.Fatalf("unexpected error: %s", err) + } - ensureFileMode(t, zipFilePath, element) + ensureFileMode(t, zipFilePath, element) + }() } } @@ -72,6 +77,7 @@ func TestZipArchiver_FileModified(t *testing.T) { } zip() + defer os.Remove(zipFilePath) expectedContents, err := ioutil.ReadFile(zipFilePath) if err != nil { @@ -99,6 +105,7 @@ func TestZipArchiver_FileModified(t *testing.T) { func TestZipArchiver_Dir(t *testing.T) { zipfilepath := "archive-dir.zip" archiver := NewZipArchiver(zipfilepath) + defer os.Remove(zipfilepath) if err := archiver.ArchiveDir("./test-fixtures/test-dir", []string{""}); err != nil { t.Fatalf("unexpected error: %s", err) } @@ -113,6 +120,7 @@ func TestZipArchiver_Dir(t *testing.T) { func TestZipArchiver_Dir_Exclude(t *testing.T) { zipfilepath := "archive-dir.zip" archiver := NewZipArchiver(zipfilepath) + defer os.Remove(zipfilepath) if err := archiver.ArchiveDir("./test-fixtures/test-dir", []string{"file2.txt"}); err != nil { t.Fatalf("unexpected error: %s", err) } @@ -126,6 +134,7 @@ func TestZipArchiver_Dir_Exclude(t *testing.T) { func TestZipArchiver_Dir_Exclude_With_Directory(t *testing.T) { zipfilepath := "archive-dir.zip" archiver := NewZipArchiver(zipfilepath) + defer os.Remove(zipfilepath) if err := archiver.ArchiveDir("./test-fixtures/", []string{"test-dir", "test-dir2/file2.txt"}); err != nil { t.Fatalf("unexpected error: %s", err) } @@ -146,6 +155,7 @@ func TestZipArchiver_Multiple(t *testing.T) { } archiver := NewZipArchiver(zipfilepath) + defer os.Remove(zipfilepath) if err := archiver.ArchiveMultiple(content); err != nil { t.Fatalf("unexpected error: %s", err) }