container_test.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package libcontainer
  2. import (
  3. "encoding/json"
  4. "os"
  5. "testing"
  6. )
  7. func TestContainerJsonFormat(t *testing.T) {
  8. f, err := os.Open("container.json")
  9. if err != nil {
  10. t.Fatal("Unable to open container.json")
  11. }
  12. defer f.Close()
  13. var container *Container
  14. if err := json.NewDecoder(f).Decode(&container); err != nil {
  15. t.Fatalf("failed to decode container config: %s", err)
  16. }
  17. if container.Hostname != "koye" {
  18. t.Log("hostname is not set")
  19. t.Fail()
  20. }
  21. if !container.Tty {
  22. t.Log("tty should be set to true")
  23. t.Fail()
  24. }
  25. if !container.Namespaces["NEWNET"] {
  26. t.Log("namespaces should contain NEWNET")
  27. t.Fail()
  28. }
  29. if container.Namespaces["NEWUSER"] {
  30. t.Log("namespaces should not contain NEWUSER")
  31. t.Fail()
  32. }
  33. if _, exists := container.CapabilitiesMask["SYS_ADMIN"]; !exists {
  34. t.Log("capabilities mask should contain SYS_ADMIN")
  35. t.Fail()
  36. }
  37. if container.CapabilitiesMask["SYS_ADMIN"] {
  38. t.Log("SYS_ADMIN should not be enabled in capabilities mask")
  39. t.Fail()
  40. }
  41. if !container.CapabilitiesMask["MKNOD"] {
  42. t.Log("MKNOD should be enabled in capabilities mask")
  43. t.Fail()
  44. }
  45. if container.CapabilitiesMask["SYS_CHROOT"] {
  46. t.Log("capabilities mask should not contain SYS_CHROOT")
  47. t.Fail()
  48. }
  49. }