diff --git a/pkg/libcontainer/container_test.go b/pkg/libcontainer/container_test.go new file mode 100644 index 0000000000..d710a6a53c --- /dev/null +++ b/pkg/libcontainer/container_test.go @@ -0,0 +1,59 @@ +package libcontainer + +import ( + "encoding/json" + "os" + "testing" +) + +func TestContainerJsonFormat(t *testing.T) { + f, err := os.Open("container.json") + if err != nil { + t.Fatal("Unable to open container.json") + } + defer f.Close() + + var container *Container + if err := json.NewDecoder(f).Decode(&container); err != nil { + t.Fatal("failed to decode container config") + } + if container.Hostname != "koye" { + t.Log("hostname is not set") + t.Fail() + } + + if !container.Tty { + t.Log("tty should be set to true") + t.Fail() + } + + if !container.Namespaces.Contains("NEWNET") { + t.Log("namespaces should contain NEWNET") + t.Fail() + } + + if container.Namespaces.Contains("NEWUSER") { + t.Log("namespaces should not contain NEWUSER") + t.Fail() + } + + if !container.CapabilitiesMask.Contains("SYS_ADMIN") { + t.Log("capabilities mask should contain SYS_ADMIN") + t.Fail() + } + + if container.CapabilitiesMask.Get("SYS_ADMIN").Enabled { + t.Log("SYS_ADMIN should not be enabled in capabilities mask") + t.Fail() + } + + if !container.CapabilitiesMask.Get("MKNOD").Enabled { + t.Log("MKNOD should be enabled in capabilities mask") + t.Fail() + } + + if container.CapabilitiesMask.Contains("SYS_CHROOT") { + t.Log("capabilities mask should not contain SYS_CHROOT") + t.Fail() + } +} diff --git a/pkg/libcontainer/nsinit/exec.go b/pkg/libcontainer/nsinit/exec.go index e76e060d1c..430dd89ff3 100644 --- a/pkg/libcontainer/nsinit/exec.go +++ b/pkg/libcontainer/nsinit/exec.go @@ -57,7 +57,7 @@ func (ns *linuxNs) Exec(container *libcontainer.Container, term Terminal, args [ if err != nil { return -1, err } - ns.logger.Printf("writting pid %d to file\n", command.Process.Pid) + ns.logger.Printf("writing pid %d to file\n", command.Process.Pid) if err := ns.stateWriter.WritePid(command.Process.Pid, started); err != nil { command.Process.Kill() return -1, err diff --git a/pkg/libcontainer/nsinit/nsinit/main.go b/pkg/libcontainer/nsinit/nsinit/main.go index 37aa784981..0965c1c8ca 100644 --- a/pkg/libcontainer/nsinit/nsinit/main.go +++ b/pkg/libcontainer/nsinit/nsinit/main.go @@ -32,7 +32,7 @@ func main() { registerFlags() if flag.NArg() < 1 { - log.Fatalf("wrong number of argments %d", flag.NArg()) + log.Fatalf("wrong number of arguments %d", flag.NArg()) } container, err := loadContainer() if err != nil { @@ -73,7 +73,7 @@ func main() { l.Fatal(err) } if flag.NArg() < 2 { - l.Fatalf("wrong number of argments %d", flag.NArg()) + l.Fatalf("wrong number of arguments %d", flag.NArg()) } syncPipe, err := nsinit.NewSyncPipeFromFd(0, uintptr(pipeFd)) if err != nil {