github.com/zhuohuang-hust/src-cbuild@v0.0.0-20230105071821-c7aab3e7c840/mergeCode/runc/libcontainer/specconv/spec_linux_test.go (about) 1 // +build linux 2 3 package specconv 4 5 import ( 6 "testing" 7 8 "github.com/opencontainers/runtime-spec/specs-go" 9 ) 10 11 func TestLinuxCgroupsPathSpecified(t *testing.T) { 12 cgroupsPath := "/user/cgroups/path/id" 13 14 spec := &specs.Spec{} 15 spec.Linux = &specs.Linux{ 16 CgroupsPath: &cgroupsPath, 17 } 18 19 cgroup, err := createCgroupConfig("ContainerID", false, spec) 20 if err != nil { 21 t.Errorf("Couldn't create Cgroup config: %v", err) 22 } 23 24 if cgroup.Path != cgroupsPath { 25 t.Errorf("Wrong cgroupsPath, expected '%s' got '%s'", cgroupsPath, cgroup.Path) 26 } 27 } 28 29 func TestLinuxCgroupsPathNotSpecified(t *testing.T) { 30 spec := &specs.Spec{} 31 32 cgroup, err := createCgroupConfig("ContainerID", false, spec) 33 if err != nil { 34 t.Errorf("Couldn't create Cgroup config: %v", err) 35 } 36 37 if cgroup.Path != "" { 38 t.Errorf("Wrong cgroupsPath, expected it to be empty string, got '%s'", cgroup.Path) 39 } 40 } 41 42 func TestDupNamespaces(t *testing.T) { 43 spec := &specs.Spec{ 44 Linux: &specs.Linux{ 45 Namespaces: []specs.Namespace{ 46 { 47 Type: "pid", 48 }, 49 { 50 Type: "pid", 51 Path: "/proc/1/ns/pid", 52 }, 53 }, 54 }, 55 } 56 57 _, err := CreateLibcontainerConfig(&CreateOpts{ 58 Spec: spec, 59 }) 60 61 if err == nil { 62 t.Errorf("Duplicated namespaces should be forbidden") 63 } 64 }