mirror of
https://github.com/opencontainers/runc.git
synced 2026-04-22 23:17:17 +08:00
faaecac77d
Signed-off-by: Kenta Tada <Kenta.Tada@sony.com>
88 lines
1.6 KiB
Go
88 lines
1.6 KiB
Go
package configs
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
var (
|
|
HookNameList = []HookName{Prestart, CreateRuntime, CreateContainer, StartContainer, Poststart, Poststop}
|
|
)
|
|
|
|
func TestRemoveNamespace(t *testing.T) {
|
|
ns := Namespaces{
|
|
{Type: NEWNET},
|
|
}
|
|
if !ns.Remove(NEWNET) {
|
|
t.Fatal("NEWNET was not removed")
|
|
}
|
|
if len(ns) != 0 {
|
|
t.Fatalf("namespaces should have 0 items but reports %d", len(ns))
|
|
}
|
|
}
|
|
|
|
func TestHostRootUIDNoUSERNS(t *testing.T) {
|
|
config := &Config{
|
|
Namespaces: Namespaces{},
|
|
}
|
|
uid, err := config.HostRootUID()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if uid != 0 {
|
|
t.Fatalf("expected uid 0 with no USERNS but received %d", uid)
|
|
}
|
|
}
|
|
|
|
func TestHostRootUIDWithUSERNS(t *testing.T) {
|
|
config := &Config{
|
|
Namespaces: Namespaces{{Type: NEWUSER}},
|
|
UidMappings: []IDMap{
|
|
{
|
|
ContainerID: 0,
|
|
HostID: 1000,
|
|
Size: 1,
|
|
},
|
|
},
|
|
}
|
|
uid, err := config.HostRootUID()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if uid != 1000 {
|
|
t.Fatalf("expected uid 1000 with no USERNS but received %d", uid)
|
|
}
|
|
}
|
|
|
|
func TestHostRootGIDNoUSERNS(t *testing.T) {
|
|
config := &Config{
|
|
Namespaces: Namespaces{},
|
|
}
|
|
uid, err := config.HostRootGID()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if uid != 0 {
|
|
t.Fatalf("expected gid 0 with no USERNS but received %d", uid)
|
|
}
|
|
}
|
|
|
|
func TestHostRootGIDWithUSERNS(t *testing.T) {
|
|
config := &Config{
|
|
Namespaces: Namespaces{{Type: NEWUSER}},
|
|
GidMappings: []IDMap{
|
|
{
|
|
ContainerID: 0,
|
|
HostID: 1000,
|
|
Size: 1,
|
|
},
|
|
},
|
|
}
|
|
uid, err := config.HostRootGID()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if uid != 1000 {
|
|
t.Fatalf("expected gid 1000 with no USERNS but received %d", uid)
|
|
}
|
|
}
|