Skip to content

Commit

Permalink
Set integration test OSType with environment variable
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Crone <[email protected]>
  • Loading branch information
chris-crone committed Sep 20, 2017
1 parent 7cbbbb9 commit f0e5b3d
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 18 deletions.
2 changes: 1 addition & 1 deletion integration-cli/cli/build/fakestorage/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func ensureHTTPServerImage(t testingT) {
}
defer os.RemoveAll(tmp)

goos := testEnv.DaemonInfo.OSType
goos := testEnv.OSType
if goos == "" {
goos = "linux"
}
Expand Down
2 changes: 1 addition & 1 deletion integration-cli/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions integration-cli/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions integration-cli/requirements_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion integration/system/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion internal/test/environment/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
21 changes: 17 additions & 4 deletions internal/test/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
type Execution struct {
client client.APIClient
DaemonInfo types.Info
OSType string
PlatformDefaults PlatformDefaults
protectedElements protectedElements
}
Expand All @@ -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",
Expand All @@ -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))
}
}

Expand Down
4 changes: 2 additions & 2 deletions internal/test/environment/protect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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...)
Expand Down

0 comments on commit f0e5b3d

Please sign in to comment.