2014-04-25 00:17:45 +00:00
|
|
|
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 {
|
2014-04-25 06:02:30 +00:00
|
|
|
t.Fatal("failed to decode container config")
|
2014-04-25 00:17:45 +00:00
|
|
|
}
|
|
|
|
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") {
|
2014-04-25 06:02:30 +00:00
|
|
|
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")
|
2014-04-25 00:17:45 +00:00
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
|
|
|
|
if container.CapabilitiesMask.Contains("SYS_CHROOT") {
|
2014-04-25 06:02:30 +00:00
|
|
|
t.Log("capabilities mask should not contain SYS_CHROOT")
|
2014-04-25 00:17:45 +00:00
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|