mirror of
https://github.com/anchore/syft.git
synced 2025-11-18 00:43:20 +01:00
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>
58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
//go:build !windows
|
|
// +build !windows
|
|
|
|
package source
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func Test_fileMetadataFromPath(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
path string
|
|
withMIMEType bool
|
|
expectedType string
|
|
expectedMIMEType string
|
|
}{
|
|
{
|
|
path: "test-fixtures/symlinks-simple/readme",
|
|
withMIMEType: true,
|
|
expectedType: "RegularFile",
|
|
expectedMIMEType: "text/plain",
|
|
},
|
|
{
|
|
path: "test-fixtures/symlinks-simple/link_to_new_readme",
|
|
withMIMEType: true,
|
|
expectedType: "SymbolicLink",
|
|
expectedMIMEType: "text/plain",
|
|
},
|
|
{
|
|
path: "test-fixtures/symlinks-simple/readme",
|
|
withMIMEType: false,
|
|
expectedType: "RegularFile",
|
|
expectedMIMEType: "",
|
|
},
|
|
{
|
|
path: "test-fixtures/symlinks-simple/link_to_new_readme",
|
|
withMIMEType: false,
|
|
expectedType: "SymbolicLink",
|
|
expectedMIMEType: "",
|
|
},
|
|
}
|
|
for _, test := range tests {
|
|
t.Run(test.path, func(t *testing.T) {
|
|
info, err := os.Lstat(test.path)
|
|
require.NoError(t, err)
|
|
|
|
actual := fileMetadataFromPath(test.path, info, test.withMIMEType)
|
|
assert.Equal(t, test.expectedMIMEType, actual.MIMEType)
|
|
assert.Equal(t, test.expectedType, string(actual.Type))
|
|
})
|
|
}
|
|
}
|