Browse code

api: fix serialization test for deploymentconfigs

Michail Kargakis authored on 2016/06/03 20:42:28
Showing 2 changed files
... ...
@@ -257,6 +257,18 @@ func fuzzInternalObject(t *testing.T, forVersion unversioned.GroupVersion, item
257 257
 		func(j *deploy.DeploymentConfig, c fuzz.Continue) {
258 258
 			c.FuzzNoCustom(j)
259 259
 			j.Spec.Triggers = []deploy.DeploymentTriggerPolicy{{Type: deploy.DeploymentTriggerOnConfigChange}}
260
+			if j.Spec.Template != nil && len(j.Spec.Template.Spec.Containers) == 1 {
261
+				containerName := j.Spec.Template.Spec.Containers[0].Name
262
+				if p := j.Spec.Strategy.RecreateParams; p != nil {
263
+					defaultHookContainerName(p.Pre, containerName)
264
+					defaultHookContainerName(p.Mid, containerName)
265
+					defaultHookContainerName(p.Post, containerName)
266
+				}
267
+				if p := j.Spec.Strategy.RollingParams; p != nil {
268
+					defaultHookContainerName(p.Pre, containerName)
269
+					defaultHookContainerName(p.Post, containerName)
270
+				}
271
+			}
260 272
 		},
261 273
 		func(j *deploy.DeploymentStrategy, c fuzz.Continue) {
262 274
 			c.FuzzNoCustom(j)
... ...
@@ -271,9 +283,6 @@ func fuzzInternalObject(t *testing.T, forVersion unversioned.GroupVersion, item
271 271
 					s := int64(120)
272 272
 					params.TimeoutSeconds = &s
273 273
 				}
274
-				defaultLifecycleHook(params.Pre)
275
-				defaultLifecycleHook(params.Mid)
276
-				defaultLifecycleHook(params.Post)
277 274
 				j.RecreateParams = params
278 275
 			case deploy.DeploymentStrategyTypeRolling:
279 276
 				params := &deploy.RollingDeploymentStrategyParams{}
... ...
@@ -306,8 +315,6 @@ func fuzzInternalObject(t *testing.T, forVersion unversioned.GroupVersion, item
306 306
 						},
307 307
 					}
308 308
 				}
309
-				defaultLifecycleHook(params.Pre)
310
-				defaultLifecycleHook(params.Post)
311 309
 				if c.RandBool() {
312 310
 					params.MaxUnavailable = intstr.FromInt(int(c.RandUint64()))
313 311
 					params.MaxSurge = intstr.FromInt(int(c.RandUint64()))
... ...
@@ -417,13 +424,18 @@ func fuzzInternalObject(t *testing.T, forVersion unversioned.GroupVersion, item
417 417
 	return item
418 418
 }
419 419
 
420
-func defaultLifecycleHook(hook *deploy.LifecycleHook) {
420
+func defaultHookContainerName(hook *deploy.LifecycleHook, containerName string) {
421 421
 	if hook == nil {
422 422
 		return
423 423
 	}
424 424
 	for i := range hook.TagImages {
425 425
 		if len(hook.TagImages[i].ContainerName) == 0 {
426
-			hook.TagImages[i].ContainerName = "test"
426
+			hook.TagImages[i].ContainerName = containerName
427
+		}
428
+	}
429
+	if hook.ExecNewPod != nil {
430
+		if len(hook.ExecNewPod.ContainerName) == 0 {
431
+			hook.ExecNewPod.ContainerName = containerName
427 432
 		}
428 433
 	}
429 434
 }
... ...
@@ -7,6 +7,7 @@ import (
7 7
 	deployapi "github.com/openshift/origin/pkg/deploy/api"
8 8
 )
9 9
 
10
+// Keep this in sync with pkg/api/serialization_test.go#defaultHookContainerName
10 11
 func defaultHookContainerName(hook *LifecycleHook, containerName string) {
11 12
 	if hook == nil {
12 13
 		return