mirror of
https://github.com/containers/podman.git
synced 2025-10-18 03:33:32 +08:00
utils: add test for the new function
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
@ -7,6 +7,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/containers/storage/pkg/idtools"
|
||||
stypes "github.com/containers/storage/types"
|
||||
ruser "github.com/moby/sys/user"
|
||||
"github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@ -588,3 +589,36 @@ func TestConvertTimeout(t *testing.T) {
|
||||
timeout = ConvertTimeout(-100)
|
||||
assert.Equal(t, uint(math.MaxUint32), timeout)
|
||||
}
|
||||
|
||||
func TestGetRootlessKeepIDMapping(t *testing.T) {
|
||||
tests := []struct {
|
||||
uid, gid int
|
||||
uids, gids []idtools.IDMap
|
||||
expectedOptions *stypes.IDMappingOptions
|
||||
expectedUID, expectedGID int
|
||||
expectedError error
|
||||
}{
|
||||
{
|
||||
uid: 1000,
|
||||
gid: 1000,
|
||||
uids: []idtools.IDMap{},
|
||||
gids: []idtools.IDMap{},
|
||||
expectedOptions: &stypes.IDMappingOptions{
|
||||
HostUIDMapping: false,
|
||||
HostGIDMapping: false,
|
||||
UIDMap: []idtools.IDMap{{ContainerID: 1000, HostID: 0, Size: 1}},
|
||||
GIDMap: []idtools.IDMap{{ContainerID: 1000, HostID: 0, Size: 1}},
|
||||
},
|
||||
expectedUID: 1000,
|
||||
expectedGID: 1000,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
options, uid, gid, err := getRootlessKeepIDMapping(test.uid, test.gid, test.uids, test.gids)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, test.expectedOptions, options)
|
||||
assert.Equal(t, test.expectedUID, uid)
|
||||
assert.Equal(t, test.expectedGID, gid)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user