mirror of
https://github.com/opencontainers/runc.git
synced 2025-09-26 19:41:35 +08:00

gofumpt (mvdan.cc/gofumpt) is a fork of gofmt with stricter rules. Brought to you by git ls-files \*.go | grep -v ^vendor/ | xargs gofumpt -s -w Looking at the diff, all these changes make sense. Also, replace gofmt with gofumpt in golangci.yml. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
86 lines
1.6 KiB
Go
86 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)
|
|
}
|
|
}
|