2014-04-25 08:17:45 +08: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-05-06 03:34:21 +08:00
|
|
|
t.Fatalf("failed to decode container config: %s", err)
|
2014-04-25 08:17:45 +08: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()
|
|
|
|
}
|
|
|
|
|
2014-05-06 03:34:21 +08:00
|
|
|
if !container.Namespaces["NEWNET"] {
|
2014-04-25 08:17:45 +08:00
|
|
|
t.Log("namespaces should contain NEWNET")
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
|
2014-05-06 03:34:21 +08:00
|
|
|
if container.Namespaces["NEWUSER"] {
|
2014-04-25 08:17:45 +08:00
|
|
|
t.Log("namespaces should not contain NEWUSER")
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
|
2014-05-06 03:34:21 +08:00
|
|
|
if _, exists := container.CapabilitiesMask["SYS_ADMIN"]; !exists {
|
2014-04-25 14:02:30 +08:00
|
|
|
t.Log("capabilities mask should contain SYS_ADMIN")
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
|
2014-05-06 03:34:21 +08:00
|
|
|
if container.CapabilitiesMask["SYS_ADMIN"] {
|
2014-04-25 14:02:30 +08:00
|
|
|
t.Log("SYS_ADMIN should not be enabled in capabilities mask")
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
|
2014-05-06 03:34:21 +08:00
|
|
|
if !container.CapabilitiesMask["MKNOD"] {
|
2014-04-25 14:02:30 +08:00
|
|
|
t.Log("MKNOD should be enabled in capabilities mask")
|
2014-04-25 08:17:45 +08:00
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
|
2014-05-06 03:34:21 +08:00
|
|
|
if container.CapabilitiesMask["SYS_CHROOT"] {
|
2014-04-25 14:02:30 +08:00
|
|
|
t.Log("capabilities mask should not contain SYS_CHROOT")
|
2014-04-25 08:17:45 +08:00
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|