mirror of
https://github.com/anchore/syft
synced 2024-11-10 14:24:12 +00:00
01dc78ccc3
Support Windows Directory Resolver Add function that converts windows to posix functionality Add function that converts posix to windows Add build tags to remove windows developer environment errors redact carriage return specific windows issues Signed-off-by: Christopher Phillips <christopher.phillips@anchore.com>
50 lines
1 KiB
Go
50 lines
1 KiB
Go
//go:build !windows
|
|
// +build !windows
|
|
|
|
package file
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestFindArchiveStartOffset(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
archivePrep func(tb testing.TB) string
|
|
expected uint64
|
|
}{
|
|
{
|
|
name: "standard, non-nested zip",
|
|
archivePrep: prepZipSourceFixture,
|
|
expected: 0,
|
|
},
|
|
{
|
|
name: "zip with prepended bytes",
|
|
archivePrep: prependZipSourceFixtureWithString(t, "junk at the beginning of the file..."),
|
|
expected: 36,
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
archivePath := test.archivePrep(t)
|
|
f, err := os.Open(archivePath)
|
|
if err != nil {
|
|
t.Fatalf("could not open archive %q: %+v", archivePath, err)
|
|
}
|
|
fi, err := os.Stat(f.Name())
|
|
if err != nil {
|
|
t.Fatalf("unable to stat archive: %+v", err)
|
|
}
|
|
|
|
actual, err := findArchiveStartOffset(f, fi.Size())
|
|
if err != nil {
|
|
t.Fatalf("unable to find offset: %+v", err)
|
|
}
|
|
assert.Equal(t, test.expected, actual)
|
|
})
|
|
}
|
|
}
|