Skip to content

Commit

Permalink
fix: test error
Browse files Browse the repository at this point in the history
Signed-off-by: hari rongali <[email protected]>
  • Loading branch information
harikrongali committed May 13, 2021
1 parent 1862eff commit 6e1c915
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/kubectl-argo-rollouts/cmd/promote/promote.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func getPatches(rollout *v1alpha1.Rollout, skipCurrentStep, skipAllStep, full bo
}
unifiedPatch = []byte(unpauseAndClearPauseConditionsPatch)

if rollout.Spec.Strategy.Canary != nil {
if rollout.Spec.Strategy.Canary != nil && !rollout.Status.ControllerPause {
_, index := replicasetutil.GetCurrentCanaryStep(rollout)
// At this point, the controller knows that the rollout is a canary with steps and GetCurrentCanaryStep returns 0 if
// the index is not set in the rollout
Expand Down
50 changes: 50 additions & 0 deletions pkg/kubectl-argo-rollouts/cmd/promote/promote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,56 @@ func TestPromoteCmdSuccesSkipAllSteps(t *testing.T) {
assert.Empty(t, stderr)
}

func TestPromoteCmdSuccesFirstStepWithDefaultPromote(t *testing.T) {
ro := v1alpha1.Rollout{
ObjectMeta: metav1.ObjectMeta{
Name: "guestbook",
Namespace: metav1.NamespaceDefault,
},
Spec: v1alpha1.RolloutSpec{
Strategy: v1alpha1.RolloutStrategy{
Canary: &v1alpha1.CanaryStrategy{
Steps: []v1alpha1.CanaryStep{
{
SetWeight: pointer.Int32Ptr(1),
},
{
SetWeight: pointer.Int32Ptr(2),
},
},
},
},
},
}

tf, o := options.NewFakeArgoRolloutsOptions(&ro)
defer tf.Cleanup()
fakeClient := o.RolloutsClient.(*fakeroclient.Clientset)
fakeClient.PrependReactor("patch", "*", func(action kubetesting.Action) (handled bool, ret runtime.Object, err error) {
if patchAction, ok := action.(kubetesting.PatchAction); ok {
patchRo := v1alpha1.Rollout{}
err := json.Unmarshal(patchAction.GetPatch(), &patchRo)
if err != nil {
panic(err)
}
ro.Status.CurrentStepIndex = patchRo.Status.CurrentStepIndex
}
return true, &ro, nil
})

cmd := NewCmdPromote(o)
cmd.PersistentPreRunE = o.PersistentPreRunE
cmd.SetArgs([]string{"guestbook"})

err := cmd.Execute()
assert.Nil(t, err)
assert.Equal(t, int32(1), *ro.Status.CurrentStepIndex)
stdout := o.Out.(*bytes.Buffer).String()
stderr := o.ErrOut.(*bytes.Buffer).String()
assert.Equal(t, stdout, "rollout 'guestbook' promoted\n")
assert.Empty(t, stderr)
}

func TestPromoteCmdSuccesFirstStep(t *testing.T) {
ro := v1alpha1.Rollout{
ObjectMeta: metav1.ObjectMeta{
Expand Down

0 comments on commit 6e1c915

Please sign in to comment.