■ ■ ■ ■ ■ ■
internal/file/zip_file_traversal_test.go
| skipped 8 lines |
9 | 9 | | "errors" |
10 | 10 | | "fmt" |
11 | 11 | | "io" |
12 | | - | "io/ioutil" |
13 | 12 | | "os" |
14 | 13 | | "path" |
15 | 14 | | "path/filepath" |
| skipped 33 lines |
49 | 48 | | sourceDirPath := path.Join(goldenRootDir, "zip-source") |
50 | 49 | | archiveFilePath := setupZipFileTest(t, sourceDirPath, false) |
51 | 50 | | |
52 | | - | unzipDestinationDir, err := ioutil.TempDir("", "syft-ziputil-contents-TEST-") |
53 | | - | t.Cleanup(assertNoError(t, func() error { |
54 | | - | return os.RemoveAll(unzipDestinationDir) |
55 | | - | })) |
56 | | - | if err != nil { |
57 | | - | t.Fatalf("unable to create tempdir: %+v", err) |
58 | | - | } |
| 51 | + | unzipDestinationDir := t.TempDir() |
59 | 52 | | |
60 | 53 | | t.Logf("content path: %s", unzipDestinationDir) |
61 | 54 | | |
| skipped 108 lines |
170 | 163 | | archivePath := prepZipSourceFixture(t) |
171 | 164 | | |
172 | 165 | | // create a temp file |
173 | | - | tmpFile, err := ioutil.TempFile("", "syft-ziputil-prependZipSourceFixtureWithString-") |
| 166 | + | tmpFile, err := os.CreateTemp(tb.TempDir(), "syft-ziputil-prependZipSourceFixtureWithString-") |
174 | 167 | | if err != nil { |
175 | 168 | | t.Fatalf("unable to create tempfile: %+v", err) |
176 | 169 | | } |
| skipped 32 lines |
209 | 202 | | |
210 | 203 | | func prepZipSourceFixture(t testing.TB) string { |
211 | 204 | | t.Helper() |
212 | | - | archivePrefix, err := ioutil.TempFile("", "syft-ziputil-prepZipSourceFixture-") |
213 | | - | if err != nil { |
214 | | - | t.Fatalf("unable to create tempfile: %+v", err) |
215 | | - | } |
216 | | - | |
217 | | - | t.Cleanup(func() { |
218 | | - | assert.NoError(t, os.Remove(archivePrefix.Name())) |
219 | | - | }) |
| 205 | + | archivePrefix := path.Join(t.TempDir(), "syft-ziputil-prepZipSourceFixture-") |
220 | 206 | | |
221 | 207 | | // the zip utility will add ".zip" to the end of the given name |
222 | | - | archivePath := archivePrefix.Name() + ".zip" |
223 | | - | |
224 | | - | t.Cleanup(func() { |
225 | | - | assert.NoError(t, os.Remove(archivePath)) |
226 | | - | }) |
| 208 | + | archivePath := archivePrefix + ".zip" |
227 | 209 | | |
228 | 210 | | t.Logf("archive path: %s", archivePath) |
229 | 211 | | |
230 | | - | createZipArchive(t, "zip-source", archivePrefix.Name(), false) |
| 212 | + | createZipArchive(t, "zip-source", archivePrefix, false) |
231 | 213 | | |
232 | 214 | | return archivePath |
233 | 215 | | } |
| skipped 101 lines |