update zip util tests

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
Alex Goodman 2021-06-04 10:33:25 -04:00
parent bf1bf057ab
commit 6a398f9771
No known key found for this signature in database
GPG key ID: 5CB45AE22BAB7EA7
3 changed files with 9 additions and 9 deletions

View file

@ -23,7 +23,7 @@ func NewZipFileManifest(archivePath string) (ZipFileManifest, error) {
defer func() {
err = zipReader.Close()
if err != nil {
log.Errorf("unable to close zip archive (%s): %+v", archivePath, err)
log.Warnf("unable to close zip archive (%s): %+v", archivePath, err)
}
}()

View file

@ -135,7 +135,7 @@ func TestContentsFromZip(t *testing.T) {
},
{
name: "zip with prepended bytes",
archivePrep: prepZipSourceFixtureWithPrependedBytes(t, "junk at the beginning of the file..."),
archivePrep: prependZipSourceFixtureWithString(t, "junk at the beginning of the file..."),
},
}
@ -159,7 +159,7 @@ func TestContentsFromZip(t *testing.T) {
}
}
func prepZipSourceFixtureWithPrependedBytes(tb testing.TB, value string) func(tb testing.TB) string {
func prependZipSourceFixtureWithString(tb testing.TB, value string) func(tb testing.TB) string {
if len(value) == 0 {
tb.Fatalf("no bytes given to prefix")
}
@ -167,13 +167,13 @@ func prepZipSourceFixtureWithPrependedBytes(tb testing.TB, value string) func(tb
archivePath := prepZipSourceFixture(t)
// create a temp file
tmpFile, err := ioutil.TempFile("", "syft-ziputil-archive-TEST-")
tmpFile, err := ioutil.TempFile("", "syft-ziputil-prependZipSourceFixtureWithString-")
if err != nil {
t.Fatalf("unable to create tempfile: %+v", err)
}
defer tmpFile.Close()
// write junk to the temp file
// write value to the temp file
if _, err := tmpFile.WriteString(value); err != nil {
t.Fatalf("unable to write to tempfile: %+v", err)
}
@ -193,11 +193,11 @@ func prepZipSourceFixtureWithPrependedBytes(tb testing.TB, value string) func(tb
// remove the original archive and replace it with the temp file
if err := os.Remove(archivePath); err != nil {
t.Fatalf("unable to remove original source archive")
t.Fatalf("unable to remove original source archive (%q): %+v", archivePath, err)
}
if err := os.Rename(tmpFile.Name(), archivePath); err != nil {
t.Fatalf("unable to move new archive to old path")
t.Fatalf("unable to move new archive to old path (%q): %+v", tmpFile.Name(), err)
}
return archivePath
@ -206,7 +206,7 @@ func prepZipSourceFixtureWithPrependedBytes(tb testing.TB, value string) func(tb
func prepZipSourceFixture(t testing.TB) string {
t.Helper()
archivePrefix, err := ioutil.TempFile("", "syft-ziputil-archive-TEST-")
archivePrefix, err := ioutil.TempFile("", "syft-ziputil-prepZipSourceFixture-")
if err != nil {
t.Fatalf("unable to create tempfile: %+v", err)
}

View file

@ -20,7 +20,7 @@ func TestFindArchiveStartOffset(t *testing.T) {
},
{
name: "zip with prepended bytes",
archivePrep: prepZipSourceFixtureWithPrependedBytes(t, "junk at the beginning of the file..."),
archivePrep: prependZipSourceFixtureWithString(t, "junk at the beginning of the file..."),
expected: 36,
},
}