Refactor function

pull/6/head
Janet Kuo 2017-09-22 01:06:59 -07:00
parent 241f4fbc98
commit 3a0dabcaea
2 changed files with 11 additions and 15 deletions

View File

@ -173,7 +173,7 @@ func TestPausedDeployment(t *testing.T) {
} }
// Resume the deployment // Resume the deployment
tester.deployment, err = tester.updateDeployment(resumeFn()) tester.deployment, err = tester.updateDeployment(resumeFn)
if err != nil { if err != nil {
t.Fatalf("failed to resume deployment %s: %v", tester.deployment.Name, err) t.Fatalf("failed to resume deployment %s: %v", tester.deployment.Name, err)
} }
@ -200,7 +200,7 @@ func TestPausedDeployment(t *testing.T) {
// Pause the deployment. // Pause the deployment.
// The paused deployment shouldn't trigger a new rollout. // The paused deployment shouldn't trigger a new rollout.
tester.deployment, err = tester.updateDeployment(pauseFn()) tester.deployment, err = tester.updateDeployment(pauseFn)
if err != nil { if err != nil {
t.Fatalf("failed to pause deployment %s: %v", tester.deployment.Name, err) t.Fatalf("failed to pause deployment %s: %v", tester.deployment.Name, err)
} }
@ -283,7 +283,7 @@ func TestScalePausedDeployment(t *testing.T) {
} }
// Pause the deployment. // Pause the deployment.
tester.deployment, err = tester.updateDeployment(pauseFn()) tester.deployment, err = tester.updateDeployment(pauseFn)
if err != nil { if err != nil {
t.Fatalf("failed to pause deployment %s: %v", tester.deployment.Name, err) t.Fatalf("failed to pause deployment %s: %v", tester.deployment.Name, err)
} }

View File

@ -45,6 +45,14 @@ const (
fakeImage = "fakeimage" fakeImage = "fakeimage"
) )
var pauseFn = func(update *v1beta1.Deployment) {
update.Spec.Paused = true
}
var resumeFn = func(update *v1beta1.Deployment) {
update.Spec.Paused = false
}
type deploymentTester struct { type deploymentTester struct {
t *testing.T t *testing.T
c clientset.Interface c clientset.Interface
@ -252,15 +260,3 @@ func (d *deploymentTester) expectNewReplicaSet() (*v1beta1.ReplicaSet, error) {
func (d *deploymentTester) updateReplicaSet(name string, applyUpdate testutil.UpdateReplicaSetFunc) (*v1beta1.ReplicaSet, error) { func (d *deploymentTester) updateReplicaSet(name string, applyUpdate testutil.UpdateReplicaSetFunc) (*v1beta1.ReplicaSet, error) {
return testutil.UpdateReplicaSetWithRetries(d.c, d.deployment.Namespace, name, applyUpdate, d.t.Logf) return testutil.UpdateReplicaSetWithRetries(d.c, d.deployment.Namespace, name, applyUpdate, d.t.Logf)
} }
func pauseFn() func(update *v1beta1.Deployment) {
return func(update *v1beta1.Deployment) {
update.Spec.Paused = true
}
}
func resumeFn() func(update *v1beta1.Deployment) {
return func(update *v1beta1.Deployment) {
update.Spec.Paused = false
}
}