2016-07-15 15:02:40 +08:00
|
|
|
// +build linux
|
2016-02-18 00:33:46 +08:00
|
|
|
|
2016-03-25 23:44:09 +08:00
|
|
|
package specconv
|
2016-02-18 00:33:46 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2016-04-13 04:35:51 +08:00
|
|
|
"github.com/opencontainers/runtime-spec/specs-go"
|
2016-02-18 00:33:46 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestLinuxCgroupsPathSpecified(t *testing.T) {
|
|
|
|
cgroupsPath := "/user/cgroups/path/id"
|
|
|
|
|
2016-03-11 06:18:39 +08:00
|
|
|
spec := &specs.Spec{}
|
2016-09-12 07:30:17 +08:00
|
|
|
spec.Linux = &specs.Linux{
|
|
|
|
CgroupsPath: &cgroupsPath,
|
|
|
|
}
|
2016-02-18 00:33:46 +08:00
|
|
|
|
2016-03-22 03:53:46 +08:00
|
|
|
cgroup, err := createCgroupConfig("ContainerID", false, spec)
|
2016-02-18 00:33:46 +08:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Couldn't create Cgroup config: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if cgroup.Path != cgroupsPath {
|
|
|
|
t.Errorf("Wrong cgroupsPath, expected '%s' got '%s'", cgroupsPath, cgroup.Path)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLinuxCgroupsPathNotSpecified(t *testing.T) {
|
2016-03-11 06:18:39 +08:00
|
|
|
spec := &specs.Spec{}
|
2016-02-18 00:33:46 +08:00
|
|
|
|
2016-03-22 03:53:46 +08:00
|
|
|
cgroup, err := createCgroupConfig("ContainerID", false, spec)
|
2016-02-18 00:33:46 +08:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Couldn't create Cgroup config: %v", err)
|
|
|
|
}
|
|
|
|
|
2016-08-30 14:12:15 +08:00
|
|
|
if cgroup.Path != "" {
|
|
|
|
t.Errorf("Wrong cgroupsPath, expected it to be empty string, got '%s'", cgroup.Path)
|
2016-02-18 00:33:46 +08:00
|
|
|
}
|
|
|
|
}
|
2016-10-27 00:42:22 +08:00
|
|
|
|
|
|
|
func TestDupNamespaces(t *testing.T) {
|
|
|
|
spec := &specs.Spec{
|
|
|
|
Linux: &specs.Linux{
|
2016-12-17 13:01:53 +08:00
|
|
|
Namespaces: []specs.LinuxNamespace{
|
2016-10-27 00:42:22 +08:00
|
|
|
{
|
|
|
|
Type: "pid",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: "pid",
|
|
|
|
Path: "/proc/1/ns/pid",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := CreateLibcontainerConfig(&CreateOpts{
|
|
|
|
Spec: spec,
|
|
|
|
})
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
t.Errorf("Duplicated namespaces should be forbidden")
|
|
|
|
}
|
|
|
|
}
|