Skip to content

Commit 1359131

Browse files
author
Mrunal Patel
authored
Merge pull request #1080 from hqhq/fix_user_test
Fix TestGetAdditionalGroups on i686
2 parents 2940d2e + dc0a4cf commit 1359131

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

libcontainer/user/user_test.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"strconv"
88
"strings"
99
"testing"
10+
11+
"github.com/opencontainers/runc/libcontainer/utils"
1012
)
1113

1214
func TestUserParseLine(t *testing.T) {
@@ -382,18 +384,20 @@ this is just some garbage data
382384
}
383385

384386
func TestGetAdditionalGroups(t *testing.T) {
387+
type foo struct {
388+
groups []string
389+
expected []int
390+
hasError bool
391+
}
392+
385393
const groupContent = `
386394
root:x:0:root
387395
adm:x:43:
388396
grp:x:1234:root,adm
389397
adm:x:4343:root,adm-duplicate
390398
this is just some garbage data
391399
`
392-
tests := []struct {
393-
groups []string
394-
expected []int
395-
hasError bool
396-
}{
400+
tests := []foo{
397401
{
398402
// empty group
399403
groups: []string{},
@@ -436,12 +440,15 @@ this is just some garbage data
436440
expected: nil,
437441
hasError: true,
438442
},
439-
{
443+
}
444+
445+
if utils.GetIntSize() > 4 {
446+
tests = append(tests, foo{
440447
// groups with too large id
441448
groups: []string{strconv.Itoa(1 << 31)},
442449
expected: nil,
443450
hasError: true,
444-
},
451+
})
445452
}
446453

447454
for _, test := range tests {

libcontainer/utils/utils.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"path/filepath"
1010
"strings"
1111
"syscall"
12+
"unsafe"
1213
)
1314

1415
const (
@@ -119,3 +120,7 @@ func Annotations(labels []string) (bundle string, userAnnotations map[string]str
119120
}
120121
return
121122
}
123+
124+
func GetIntSize() int {
125+
return int(unsafe.Sizeof(1))
126+
}

0 commit comments

Comments
 (0)