From f0e5b3d7d89c0c87d001faa18bc60fd1b4531901 Mon Sep 17 00:00:00 2001 From: Christopher Crone Date: Wed, 20 Sep 2017 14:47:49 +0200 Subject: [PATCH] Set integration test OSType with environment variable Signed-off-by: Christopher Crone --- .../cli/build/fakestorage/fixtures.go | 2 +- integration-cli/cli/cli.go | 2 +- integration-cli/environment/environment.go | 4 ++-- integration-cli/requirements_test.go | 12 +++++------ integration/system/version_test.go | 2 +- internal/test/environment/clean.go | 2 +- internal/test/environment/environment.go | 21 +++++++++++++++---- internal/test/environment/protect.go | 4 ++-- 8 files changed, 31 insertions(+), 18 deletions(-) diff --git a/integration-cli/cli/build/fakestorage/fixtures.go b/integration-cli/cli/build/fakestorage/fixtures.go index b76a7d9207..2eb72847f4 100644 --- a/integration-cli/cli/build/fakestorage/fixtures.go +++ b/integration-cli/cli/build/fakestorage/fixtures.go @@ -30,7 +30,7 @@ func ensureHTTPServerImage(t testingT) { } defer os.RemoveAll(tmp) - goos := testEnv.DaemonInfo.OSType + goos := testEnv.OSType if goos == "" { goos = "linux" } diff --git a/integration-cli/cli/cli.go b/integration-cli/cli/cli.go index b8230b2da4..813c3ad437 100644 --- a/integration-cli/cli/cli.go +++ b/integration-cli/cli/cli.go @@ -115,7 +115,7 @@ func Docker(cmd icmd.Cmd, cmdOperators ...CmdOperator) *icmd.Result { // validateArgs is a checker to ensure tests are not running commands which are // not supported on platforms. Specifically on Windows this is 'busybox top'. func validateArgs(args ...string) error { - if testEnv.DaemonInfo.OSType != "windows" { + if testEnv.OSType != "windows" { return nil } foundBusybox := -1 diff --git a/integration-cli/environment/environment.go b/integration-cli/environment/environment.go index 4e04ba76f3..0decc06983 100644 --- a/integration-cli/environment/environment.go +++ b/integration-cli/environment/environment.go @@ -67,9 +67,9 @@ func (e *Execution) ExperimentalDaemon() bool { // decisions on how to configure themselves according to the platform // of the daemon. This is initialized in docker_utils by sending // a version call to the daemon and examining the response header. -// Deprecated: use Execution.DaemonInfo.OSType +// Deprecated: use Execution.OSType func (e *Execution) DaemonPlatform() string { - return e.DaemonInfo.OSType + return e.OSType } // MinimalBaseImage is the image used for minimal builds (it depends on the platform) diff --git a/integration-cli/requirements_test.go b/integration-cli/requirements_test.go index 411248195b..28c70c70ce 100644 --- a/integration-cli/requirements_test.go +++ b/integration-cli/requirements_test.go @@ -21,12 +21,12 @@ func ArchitectureIsNot(arch string) bool { } func DaemonIsWindows() bool { - return testEnv.DaemonInfo.OSType == "windows" + return testEnv.OSType == "windows" } func DaemonIsWindowsAtLeastBuild(buildNumber int) func() bool { return func() bool { - if testEnv.DaemonInfo.OSType != "windows" { + if testEnv.OSType != "windows" { return false } version := testEnv.DaemonInfo.KernelVersion @@ -36,7 +36,7 @@ func DaemonIsWindowsAtLeastBuild(buildNumber int) func() bool { } func DaemonIsLinux() bool { - return testEnv.DaemonInfo.OSType == "linux" + return testEnv.OSType == "linux" } func OnlyDefaultNetworks() bool { @@ -178,21 +178,21 @@ func UserNamespaceInKernel() bool { } func IsPausable() bool { - if testEnv.DaemonInfo.OSType == "windows" { + if testEnv.OSType == "windows" { return testEnv.DaemonInfo.Isolation == "hyperv" } return true } func NotPausable() bool { - if testEnv.DaemonInfo.OSType == "windows" { + if testEnv.OSType == "windows" { return testEnv.DaemonInfo.Isolation == "process" } return false } func IsolationIs(expectedIsolation string) bool { - return testEnv.DaemonInfo.OSType == "windows" && string(testEnv.DaemonInfo.Isolation) == expectedIsolation + return testEnv.OSType == "windows" && string(testEnv.DaemonInfo.Isolation) == expectedIsolation } func IsolationIsHyperv() bool { diff --git a/integration/system/version_test.go b/integration/system/version_test.go index ac47891e9b..110bd9f56f 100644 --- a/integration/system/version_test.go +++ b/integration/system/version_test.go @@ -20,5 +20,5 @@ func TestVersion(t *testing.T) { assert.NotNil(t, version.Version) assert.NotNil(t, version.MinAPIVersion) assert.Equal(t, testEnv.DaemonInfo.ExperimentalBuild, version.Experimental) - assert.Equal(t, testEnv.DaemonInfo.OSType, version.Os) + assert.Equal(t, testEnv.OSType, version.Os) } diff --git a/internal/test/environment/clean.go b/internal/test/environment/clean.go index 702d10711b..1bdd21080a 100644 --- a/internal/test/environment/clean.go +++ b/internal/test/environment/clean.go @@ -28,7 +28,7 @@ type logT interface { func (e *Execution) Clean(t testingT) { client := e.APIClient() - platform := e.DaemonInfo.OSType + platform := e.OSType if (platform != "windows") || (platform == "windows" && e.DaemonInfo.Isolation == "hyperv") { unpauseAllContainers(t, client) } diff --git a/internal/test/environment/environment.go b/internal/test/environment/environment.go index afe8929350..eba92b2b31 100644 --- a/internal/test/environment/environment.go +++ b/internal/test/environment/environment.go @@ -17,6 +17,7 @@ import ( type Execution struct { client client.APIClient DaemonInfo types.Info + OSType string PlatformDefaults PlatformDefaults protectedElements protectedElements } @@ -40,19 +41,31 @@ func New() (*Execution, error) { return nil, errors.Wrapf(err, "failed to get info from daemon") } + osType := getOSType(info) + return &Execution{ client: client, DaemonInfo: info, - PlatformDefaults: getPlatformDefaults(info), + OSType: osType, + PlatformDefaults: getPlatformDefaults(info, osType), protectedElements: newProtectedElements(), }, nil } -func getPlatformDefaults(info types.Info) PlatformDefaults { +func getOSType(info types.Info) string { + // Docker EE does not set the OSType so allow the user to override this value. + userOsType := os.Getenv("TEST_OSTYPE") + if userOsType != "" { + return userOsType + } + return info.OSType +} + +func getPlatformDefaults(info types.Info, osType string) PlatformDefaults { volumesPath := filepath.Join(info.DockerRootDir, "volumes") containersPath := filepath.Join(info.DockerRootDir, "containers") - switch info.OSType { + switch osType { case "linux": return PlatformDefaults{ BaseImage: "scratch", @@ -71,7 +84,7 @@ func getPlatformDefaults(info types.Info) PlatformDefaults { ContainerStoragePath: filepath.FromSlash(containersPath), } default: - panic(fmt.Sprintf("unknown info.OSType for daemon: %s", info.OSType)) + panic(fmt.Sprintf("unknown OSType for daemon: %s", osType)) } } diff --git a/internal/test/environment/protect.go b/internal/test/environment/protect.go index 2e882c8470..3c74fcf1bb 100644 --- a/internal/test/environment/protect.go +++ b/internal/test/environment/protect.go @@ -35,7 +35,7 @@ func ProtectAll(t testingT, testEnv *Execution) { ProtectImages(t, testEnv) ProtectNetworks(t, testEnv) ProtectVolumes(t, testEnv) - if testEnv.DaemonInfo.OSType == "linux" { + if testEnv.OSType == "linux" { ProtectPlugins(t, testEnv) } } @@ -81,7 +81,7 @@ func (e *Execution) ProtectImage(t testingT, images ...string) { func ProtectImages(t testingT, testEnv *Execution) { images := getExistingImages(t, testEnv) - if testEnv.DaemonInfo.OSType == "linux" { + if testEnv.OSType == "linux" { images = append(images, ensureFrozenImagesLinux(t, testEnv)...) } testEnv.ProtectImage(t, images...)