Browse code

Set integration test OSType with environment variable

Signed-off-by: Christopher Crone <christopher.crone@docker.com>

Christopher Crone authored on 2017/09/20 21:47:49
Showing 8 changed files
... ...
@@ -30,7 +30,7 @@ func ensureHTTPServerImage(t testingT) {
30 30
 	}
31 31
 	defer os.RemoveAll(tmp)
32 32
 
33
-	goos := testEnv.DaemonInfo.OSType
33
+	goos := testEnv.OSType
34 34
 	if goos == "" {
35 35
 		goos = "linux"
36 36
 	}
... ...
@@ -115,7 +115,7 @@ func Docker(cmd icmd.Cmd, cmdOperators ...CmdOperator) *icmd.Result {
115 115
 // validateArgs is a checker to ensure tests are not running commands which are
116 116
 // not supported on platforms. Specifically on Windows this is 'busybox top'.
117 117
 func validateArgs(args ...string) error {
118
-	if testEnv.DaemonInfo.OSType != "windows" {
118
+	if testEnv.OSType != "windows" {
119 119
 		return nil
120 120
 	}
121 121
 	foundBusybox := -1
... ...
@@ -67,9 +67,9 @@ func (e *Execution) ExperimentalDaemon() bool {
67 67
 // decisions on how to configure themselves according to the platform
68 68
 // of the daemon. This is initialized in docker_utils by sending
69 69
 // a version call to the daemon and examining the response header.
70
-// Deprecated: use Execution.DaemonInfo.OSType
70
+// Deprecated: use Execution.OSType
71 71
 func (e *Execution) DaemonPlatform() string {
72
-	return e.DaemonInfo.OSType
72
+	return e.OSType
73 73
 }
74 74
 
75 75
 // MinimalBaseImage is the image used for minimal builds (it depends on the platform)
... ...
@@ -21,12 +21,12 @@ func ArchitectureIsNot(arch string) bool {
21 21
 }
22 22
 
23 23
 func DaemonIsWindows() bool {
24
-	return testEnv.DaemonInfo.OSType == "windows"
24
+	return testEnv.OSType == "windows"
25 25
 }
26 26
 
27 27
 func DaemonIsWindowsAtLeastBuild(buildNumber int) func() bool {
28 28
 	return func() bool {
29
-		if testEnv.DaemonInfo.OSType != "windows" {
29
+		if testEnv.OSType != "windows" {
30 30
 			return false
31 31
 		}
32 32
 		version := testEnv.DaemonInfo.KernelVersion
... ...
@@ -36,7 +36,7 @@ func DaemonIsWindowsAtLeastBuild(buildNumber int) func() bool {
36 36
 }
37 37
 
38 38
 func DaemonIsLinux() bool {
39
-	return testEnv.DaemonInfo.OSType == "linux"
39
+	return testEnv.OSType == "linux"
40 40
 }
41 41
 
42 42
 func OnlyDefaultNetworks() bool {
... ...
@@ -178,21 +178,21 @@ func UserNamespaceInKernel() bool {
178 178
 }
179 179
 
180 180
 func IsPausable() bool {
181
-	if testEnv.DaemonInfo.OSType == "windows" {
181
+	if testEnv.OSType == "windows" {
182 182
 		return testEnv.DaemonInfo.Isolation == "hyperv"
183 183
 	}
184 184
 	return true
185 185
 }
186 186
 
187 187
 func NotPausable() bool {
188
-	if testEnv.DaemonInfo.OSType == "windows" {
188
+	if testEnv.OSType == "windows" {
189 189
 		return testEnv.DaemonInfo.Isolation == "process"
190 190
 	}
191 191
 	return false
192 192
 }
193 193
 
194 194
 func IsolationIs(expectedIsolation string) bool {
195
-	return testEnv.DaemonInfo.OSType == "windows" && string(testEnv.DaemonInfo.Isolation) == expectedIsolation
195
+	return testEnv.OSType == "windows" && string(testEnv.DaemonInfo.Isolation) == expectedIsolation
196 196
 }
197 197
 
198 198
 func IsolationIsHyperv() bool {
... ...
@@ -20,5 +20,5 @@ func TestVersion(t *testing.T) {
20 20
 	assert.NotNil(t, version.Version)
21 21
 	assert.NotNil(t, version.MinAPIVersion)
22 22
 	assert.Equal(t, testEnv.DaemonInfo.ExperimentalBuild, version.Experimental)
23
-	assert.Equal(t, testEnv.DaemonInfo.OSType, version.Os)
23
+	assert.Equal(t, testEnv.OSType, version.Os)
24 24
 }
... ...
@@ -28,7 +28,7 @@ type logT interface {
28 28
 func (e *Execution) Clean(t testingT) {
29 29
 	client := e.APIClient()
30 30
 
31
-	platform := e.DaemonInfo.OSType
31
+	platform := e.OSType
32 32
 	if (platform != "windows") || (platform == "windows" && e.DaemonInfo.Isolation == "hyperv") {
33 33
 		unpauseAllContainers(t, client)
34 34
 	}
... ...
@@ -17,6 +17,7 @@ import (
17 17
 type Execution struct {
18 18
 	client            client.APIClient
19 19
 	DaemonInfo        types.Info
20
+	OSType            string
20 21
 	PlatformDefaults  PlatformDefaults
21 22
 	protectedElements protectedElements
22 23
 }
... ...
@@ -40,19 +41,31 @@ func New() (*Execution, error) {
40 40
 		return nil, errors.Wrapf(err, "failed to get info from daemon")
41 41
 	}
42 42
 
43
+	osType := getOSType(info)
44
+
43 45
 	return &Execution{
44 46
 		client:            client,
45 47
 		DaemonInfo:        info,
46
-		PlatformDefaults:  getPlatformDefaults(info),
48
+		OSType:            osType,
49
+		PlatformDefaults:  getPlatformDefaults(info, osType),
47 50
 		protectedElements: newProtectedElements(),
48 51
 	}, nil
49 52
 }
50 53
 
51
-func getPlatformDefaults(info types.Info) PlatformDefaults {
54
+func getOSType(info types.Info) string {
55
+	// Docker EE does not set the OSType so allow the user to override this value.
56
+	userOsType := os.Getenv("TEST_OSTYPE")
57
+	if userOsType != "" {
58
+		return userOsType
59
+	}
60
+	return info.OSType
61
+}
62
+
63
+func getPlatformDefaults(info types.Info, osType string) PlatformDefaults {
52 64
 	volumesPath := filepath.Join(info.DockerRootDir, "volumes")
53 65
 	containersPath := filepath.Join(info.DockerRootDir, "containers")
54 66
 
55
-	switch info.OSType {
67
+	switch osType {
56 68
 	case "linux":
57 69
 		return PlatformDefaults{
58 70
 			BaseImage:            "scratch",
... ...
@@ -71,7 +84,7 @@ func getPlatformDefaults(info types.Info) PlatformDefaults {
71 71
 			ContainerStoragePath: filepath.FromSlash(containersPath),
72 72
 		}
73 73
 	default:
74
-		panic(fmt.Sprintf("unknown info.OSType for daemon: %s", info.OSType))
74
+		panic(fmt.Sprintf("unknown OSType for daemon: %s", osType))
75 75
 	}
76 76
 }
77 77
 
... ...
@@ -35,7 +35,7 @@ func ProtectAll(t testingT, testEnv *Execution) {
35 35
 	ProtectImages(t, testEnv)
36 36
 	ProtectNetworks(t, testEnv)
37 37
 	ProtectVolumes(t, testEnv)
38
-	if testEnv.DaemonInfo.OSType == "linux" {
38
+	if testEnv.OSType == "linux" {
39 39
 		ProtectPlugins(t, testEnv)
40 40
 	}
41 41
 }
... ...
@@ -81,7 +81,7 @@ func (e *Execution) ProtectImage(t testingT, images ...string) {
81 81
 func ProtectImages(t testingT, testEnv *Execution) {
82 82
 	images := getExistingImages(t, testEnv)
83 83
 
84
-	if testEnv.DaemonInfo.OSType == "linux" {
84
+	if testEnv.OSType == "linux" {
85 85
 		images = append(images, ensureFrozenImagesLinux(t, testEnv)...)
86 86
 	}
87 87
 	testEnv.ProtectImage(t, images...)