Merge pull request #1080 from hqhq/fix_user_test

Fix TestGetAdditionalGroups on i686
This commit is contained in:
Mrunal Patel 2016-09-27 10:18:27 -07:00 committed by GitHub
commit 1359131f4a
2 changed files with 19 additions and 7 deletions

View File

@ -7,6 +7,8 @@ import (
"strconv" "strconv"
"strings" "strings"
"testing" "testing"
"github.com/opencontainers/runc/libcontainer/utils"
) )
func TestUserParseLine(t *testing.T) { func TestUserParseLine(t *testing.T) {
@ -382,6 +384,12 @@ this is just some garbage data
} }
func TestGetAdditionalGroups(t *testing.T) { func TestGetAdditionalGroups(t *testing.T) {
type foo struct {
groups []string
expected []int
hasError bool
}
const groupContent = ` const groupContent = `
root:x:0:root root:x:0:root
adm:x:43: adm:x:43:
@ -389,11 +397,7 @@ grp:x:1234:root,adm
adm:x:4343:root,adm-duplicate adm:x:4343:root,adm-duplicate
this is just some garbage data this is just some garbage data
` `
tests := []struct { tests := []foo{
groups []string
expected []int
hasError bool
}{
{ {
// empty group // empty group
groups: []string{}, groups: []string{},
@ -436,12 +440,15 @@ this is just some garbage data
expected: nil, expected: nil,
hasError: true, hasError: true,
}, },
{ }
if utils.GetIntSize() > 4 {
tests = append(tests, foo{
// groups with too large id // groups with too large id
groups: []string{strconv.Itoa(1 << 31)}, groups: []string{strconv.Itoa(1 << 31)},
expected: nil, expected: nil,
hasError: true, hasError: true,
}, })
} }
for _, test := range tests { for _, test := range tests {

View File

@ -9,6 +9,7 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"syscall" "syscall"
"unsafe"
) )
const ( const (
@ -119,3 +120,7 @@ func Annotations(labels []string) (bundle string, userAnnotations map[string]str
} }
return return
} }
func GetIntSize() int {
return int(unsafe.Sizeof(1))
}