Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Hui Kang <[email protected]>
  • Loading branch information
Hui Kang committed Nov 19, 2021
1 parent 031aee1 commit 2fb4be4
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
55 changes: 55 additions & 0 deletions rollout/bluegreen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,61 @@ func newBlueGreenRollout(name string, replicas int, revisionHistoryLimit *int32,
return rollout
}

func TestBlueGreenComplateRolloutRestart(t *testing.T) {
f := newFixture(t)
defer f.Close()

r := newBlueGreenRollout("foo", 1, nil, "active", "preview")
r.Status.Conditions = []v1alpha1.RolloutCondition{}

completedCond := conditions.NewRolloutCondition(v1alpha1.RolloutCompleted, corev1.ConditionTrue, conditions.RolloutCompletedReason, conditions.RolloutCompletedReason)
conditions.SetRolloutCondition(&r.Status, *completedCond)

f.rolloutLister = append(f.rolloutLister, r)
f.objects = append(f.objects, r)
previewSvc := newService("preview", 80, nil, r)
activeSvc := newService("active", 80, nil, r)
f.kubeobjects = append(f.kubeobjects, previewSvc, activeSvc)
f.serviceLister = append(f.serviceLister, activeSvc, previewSvc)

rs := newReplicaSet(r, 1)
rsPodHash := rs.Labels[v1alpha1.DefaultRolloutUniqueLabelKey]
// generatedConditions := generateConditionsPatch(false, conditions.ReplicaSetUpdatedReason, rs, false, "")
generatedConditions := generateConditionsPatchWithComplete(false, conditions.ReplicaSetNotAvailableReason, rs, false, "", false)

f.expectCreateReplicaSetAction(rs)
servicePatchIndex := f.expectPatchServiceAction(previewSvc, rsPodHash)
f.expectUpdateReplicaSetAction(rs) // scale up RS
updatedRolloutIndex := f.expectUpdateRolloutStatusAction(r)
expectedPatchWithoutSubs := `{
"status":{
"blueGreen" : {
"previewSelector": "%s"
},
"conditions": %s,
"selector": "foo=bar",
"stableRS": "%s",
"phase": "Progressing",
"message": "more replicas need to be updated"
}
}`
expectedPatch := calculatePatch(r, fmt.Sprintf(expectedPatchWithoutSubs, rsPodHash, generatedConditions, rsPodHash))
patchRolloutIndex := f.expectPatchRolloutActionWithPatch(r, expectedPatch)
f.run(getKey(r, t))

f.verifyPatchedService(servicePatchIndex, rsPodHash, "")

updatedRollout := f.getUpdatedRollout(updatedRolloutIndex)
updatedProgressingCondition := conditions.GetRolloutCondition(updatedRollout.Status, v1alpha1.RolloutProgressing)
assert.NotNil(t, updatedProgressingCondition)
assert.Equal(t, conditions.NewReplicaSetReason, updatedProgressingCondition.Reason)
assert.Equal(t, corev1.ConditionTrue, updatedProgressingCondition.Status)
assert.Equal(t, fmt.Sprintf(conditions.NewReplicaSetMessage, rs.Name), updatedProgressingCondition.Message)

patch := f.getPatchedRollout(patchRolloutIndex)
assert.Equal(t, expectedPatch, patch)
}

func TestBlueGreenCreatesReplicaSet(t *testing.T) {
f := newFixture(t)
defer f.Close()
Expand Down
3 changes: 3 additions & 0 deletions rollout/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ func newProgressingCondition(reason string, resourceObj runtime.Object, optional
if reason == conditions.NewRSAvailableReason {
msg = fmt.Sprintf(conditions.ReplicaSetCompletedMessage, resource.Name)
}
if reason == conditions.ReplicaSetNotAvailableReason {
msg = conditions.NotAvailableMessage
}
case *v1alpha1.Rollout:
if reason == conditions.ReplicaSetUpdatedReason {
msg = fmt.Sprintf(conditions.RolloutProgressingMessage, resource.Name)
Expand Down

0 comments on commit 2fb4be4

Please sign in to comment.