mirror of
https://github.com/anchore/syft.git
synced 2026-11-26 13:44:11 +01:00
fix: build the out-of-range FileMode test cases at run time (#5512)
Test_safeFileModeConvert declared two cases as int(math.MaxInt32) + 1 and int(math.MinInt32) - 1. Those are constants that do not fit in an int where int is 32 bits wide, so the package did not compile on 386. On such a platform no int value lies outside the int32 range, so the two cases cannot be built there. They now come from int64 variables, appended only where int is wider than int32, which keeps both cases on 64-bit. Signed-off-by: Juan Manuel Méndez Rey <juan.mendezr@proton.me>
This commit is contained in:
@@ -554,12 +554,14 @@ func Test_deduplicateErrors(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_safeFileModeConvert(t *testing.T) {
|
||||
tests := []struct {
|
||||
type testCase struct {
|
||||
name string
|
||||
val int
|
||||
want fs.FileMode
|
||||
wantErr bool
|
||||
}{
|
||||
}
|
||||
|
||||
tests := []testCase{
|
||||
{
|
||||
// fs.go ModePerm 511 = FileMode = 0777 // Unix permission bits :192
|
||||
name: "valid perm",
|
||||
@@ -573,18 +575,29 @@ func Test_safeFileModeConvert(t *testing.T) {
|
||||
want: os.FileMode(0o1000000777), // 134218239
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
}
|
||||
|
||||
// Where int is 32 bits wide, no int value lies outside the int32 range, so
|
||||
// these two cases cannot be built at all. The bounds come from int64
|
||||
// variables rather than constants, because a constant that does not fit in
|
||||
// an int is a compile error on those platforms, not a skipped test.
|
||||
if math.MaxInt > math.MaxInt32 {
|
||||
maxInt32 := int64(math.MaxInt32)
|
||||
minInt32 := int64(math.MinInt32)
|
||||
tests = append(tests,
|
||||
testCase{
|
||||
name: "outside int32 high",
|
||||
val: int(math.MaxInt32) + 1,
|
||||
val: int(maxInt32 + 1),
|
||||
want: 0,
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
testCase{
|
||||
name: "outside int32 low",
|
||||
val: int(math.MinInt32) - 1,
|
||||
val: int(minInt32 - 1),
|
||||
want: 0,
|
||||
wantErr: true,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
||||
Reference in New Issue
Block a user