Skip to content

Commit 99b4877

Browse files
committed
Remove zip files that were generated as a result of a test.
1 parent 086feef commit 99b4877

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

internal/provider/zip_archiver_test.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
func TestZipArchiver_Content(t *testing.T) {
1515
zipfilepath := "archive-content.zip"
1616
archiver := NewZipArchiver(zipfilepath)
17+
defer os.Remove(zipfilepath)
1718
if err := archiver.ArchiveContent([]byte("This is some content"), "content.txt"); err != nil {
1819
t.Fatalf("unexpected error: %s", err)
1920
}
@@ -26,6 +27,7 @@ func TestZipArchiver_Content(t *testing.T) {
2627
func TestZipArchiver_File(t *testing.T) {
2728
zipfilepath := "archive-file.zip"
2829
archiver := NewZipArchiver(zipfilepath)
30+
defer os.Remove(zipfilepath)
2931
if err := archiver.ArchiveFile("./test-fixtures/test-file.txt"); err != nil {
3032
t.Fatalf("unexpected error: %s", err)
3133
}
@@ -48,13 +50,16 @@ func TestZipArchiver_FileMode(t *testing.T) {
4850

4951
stringArray := [5]string{"0444", "0644", "0666", "0744", "0777"}
5052
for _, element := range stringArray {
51-
archiver := NewZipArchiver(zipFilePath)
52-
archiver.SetOutputFileMode(element)
53-
if err := archiver.ArchiveFile(toZipPath); err != nil {
54-
t.Fatalf("unexpected error: %s", err)
55-
}
53+
func() {
54+
archiver := NewZipArchiver(zipFilePath)
55+
defer os.Remove(zipFilePath)
56+
archiver.SetOutputFileMode(element)
57+
if err := archiver.ArchiveFile(toZipPath); err != nil {
58+
t.Fatalf("unexpected error: %s", err)
59+
}
5660

57-
ensureFileMode(t, zipFilePath, element)
61+
ensureFileMode(t, zipFilePath, element)
62+
}()
5863
}
5964
}
6065

@@ -72,6 +77,7 @@ func TestZipArchiver_FileModified(t *testing.T) {
7277
}
7378

7479
zip()
80+
defer os.Remove(zipFilePath)
7581

7682
expectedContents, err := ioutil.ReadFile(zipFilePath)
7783
if err != nil {
@@ -99,6 +105,7 @@ func TestZipArchiver_FileModified(t *testing.T) {
99105
func TestZipArchiver_Dir(t *testing.T) {
100106
zipfilepath := "archive-dir.zip"
101107
archiver := NewZipArchiver(zipfilepath)
108+
defer os.Remove(zipfilepath)
102109
if err := archiver.ArchiveDir("./test-fixtures/test-dir", []string{""}); err != nil {
103110
t.Fatalf("unexpected error: %s", err)
104111
}
@@ -113,6 +120,7 @@ func TestZipArchiver_Dir(t *testing.T) {
113120
func TestZipArchiver_Dir_Exclude(t *testing.T) {
114121
zipfilepath := "archive-dir.zip"
115122
archiver := NewZipArchiver(zipfilepath)
123+
defer os.Remove(zipfilepath)
116124
if err := archiver.ArchiveDir("./test-fixtures/test-dir", []string{"file2.txt"}); err != nil {
117125
t.Fatalf("unexpected error: %s", err)
118126
}
@@ -126,6 +134,7 @@ func TestZipArchiver_Dir_Exclude(t *testing.T) {
126134
func TestZipArchiver_Dir_Exclude_With_Directory(t *testing.T) {
127135
zipfilepath := "archive-dir.zip"
128136
archiver := NewZipArchiver(zipfilepath)
137+
defer os.Remove(zipfilepath)
129138
if err := archiver.ArchiveDir("./test-fixtures/", []string{"test-dir", "test-dir2/file2.txt"}); err != nil {
130139
t.Fatalf("unexpected error: %s", err)
131140
}
@@ -146,6 +155,7 @@ func TestZipArchiver_Multiple(t *testing.T) {
146155
}
147156

148157
archiver := NewZipArchiver(zipfilepath)
158+
defer os.Remove(zipfilepath)
149159
if err := archiver.ArchiveMultiple(content); err != nil {
150160
t.Fatalf("unexpected error: %s", err)
151161
}

0 commit comments

Comments
 (0)