cli/pkg/cmd/attestation/artifact/artifact_windows_test.go
Meredith Lancaster 97c10f4c04 move artifact package over
Signed-off-by: Meredith Lancaster <malancas@github.com>
2024-03-01 16:16:20 -07:00

59 lines
1.3 KiB
Go

//go:build windows
// +build windows
package artifact
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestNormalizeReference(t *testing.T) {
testCases := []struct {
name string
reference string
pathSeparator rune
expectedResult string
expectedType artifactType
expectedError bool
}{
{
name: "windows file reference without scheme",
reference: `c:\path\to\file`,
pathSeparator: '\\',
expectedResult: `c:\path\to\file`,
expectedType: fileArtifactType,
expectedError: false,
},
{
name: "windows path",
reference: "file:///C:/path/to/file",
pathSeparator: '\\',
expectedResult: `C:\path\to\file`,
expectedType: fileArtifactType,
expectedError: false,
},
{
name: "windows path with backslashes",
reference: "file:///C:\\path\\to\\file",
pathSeparator: '\\',
expectedResult: `C:\path\to\file`,
expectedType: fileArtifactType,
expectedError: false,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
result, artifactType, err := normalizeReference(tc.reference, tc.pathSeparator)
if tc.expectedError {
assert.Error(t, err)
} else {
assert.NoError(t, err)
assert.Equal(t, tc.expectedResult, result)
assert.Equal(t, tc.expectedType, artifactType)
}
})
}
}