diff options
author | John Howard <jhoward@microsoft.com> | 2015-09-18 18:21:57 -0700 |
---|---|---|
committer | John Howard <jhoward@microsoft.com> | 2015-10-29 16:18:52 -0700 |
commit | 15e35c447058851850155f90292e51decb482956 (patch) | |
tree | 0ac7d7cf20002b256362f1e276b08985c2d23365 /runconfig/config_test.go | |
parent | 2eaa25d3554dbe9f6d5c4f66a97c8eb83a463880 (diff) | |
download | docker-15e35c447058851850155f90292e51decb482956.tar.gz |
Windows: Adds support for Hyper-V Containers
Signed-off-by: John Howard <jhoward@microsoft.com>
Diffstat (limited to 'runconfig/config_test.go')
-rw-r--r-- | runconfig/config_test.go | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/runconfig/config_test.go b/runconfig/config_test.go index b4890aeb0c..b721cf1086 100644 --- a/runconfig/config_test.go +++ b/runconfig/config_test.go @@ -2,9 +2,11 @@ package runconfig import ( "bytes" + "encoding/json" "fmt" "io/ioutil" "runtime" + "strings" "testing" "github.com/docker/docker/pkg/stringutils" @@ -60,3 +62,58 @@ func TestDecodeContainerConfig(t *testing.T) { } } } + +// TestDecodeContainerConfigIsolation validates the isolation level passed +// to the daemon in the hostConfig structure. Note this is platform specific +// as to what level of container isolation is supported. +func TestDecodeContainerConfigIsolation(t *testing.T) { + + // An invalid isolation level + if _, _, err := callDecodeContainerConfigIsolation("invalid"); err != nil { + if !strings.Contains(err.Error(), `invalid --isolation: "invalid"`) { + t.Fatal(err) + } + } + + // Blank isolation level (== default) + if _, _, err := callDecodeContainerConfigIsolation(""); err != nil { + t.Fatal("Blank isolation should have succeeded") + } + + // Default isolation level + if _, _, err := callDecodeContainerConfigIsolation("default"); err != nil { + t.Fatal("default isolation should have succeeded") + } + + // Hyper-V Containers isolation level (Valid on Windows only) + if runtime.GOOS == "windows" { + if _, _, err := callDecodeContainerConfigIsolation("hyperv"); err != nil { + t.Fatal("hyperv isolation should have succeeded") + } + } else { + if _, _, err := callDecodeContainerConfigIsolation("hyperv"); err != nil { + if !strings.Contains(err.Error(), `invalid --isolation: "hyperv"`) { + t.Fatal(err) + } + } + } +} + +// callDecodeContainerConfigIsolation is a utility function to call +// DecodeContainerConfig for validating isolation levels +func callDecodeContainerConfigIsolation(isolation string) (*Config, *HostConfig, error) { + var ( + b []byte + err error + ) + w := ContainerConfigWrapper{ + Config: &Config{}, + HostConfig: &HostConfig{ + NetworkMode: "none", + Isolation: IsolationLevel(isolation)}, + } + if b, err = json.Marshal(w); err != nil { + return nil, nil, fmt.Errorf("Error on marshal %s", err.Error()) + } + return DecodeContainerConfig(bytes.NewReader(b)) +} |