@@ -94,6 +94,31 @@ func TestPromoteSkipFlagOnNoStepCanaryError(t *testing.T) {
94
94
assert .Contains (t , stderr , skipFlagWithNoStepCanaryError )
95
95
}
96
96
97
+ func TestPromoteNoStepCanary (t * testing.T ) {
98
+ ro := v1alpha1.Rollout {
99
+ ObjectMeta : metav1.ObjectMeta {
100
+ Name : "guestbook" ,
101
+ Namespace : metav1 .NamespaceDefault ,
102
+ },
103
+ Spec : v1alpha1.RolloutSpec {
104
+ Strategy : v1alpha1.RolloutStrategy {
105
+ Canary : & v1alpha1.CanaryStrategy {},
106
+ },
107
+ },
108
+ }
109
+ tf , o := options .NewFakeArgoRolloutsOptions (& ro )
110
+ defer tf .Cleanup ()
111
+ cmd := NewCmdPromote (o )
112
+ cmd .PersistentPreRunE = o .PersistentPreRunE
113
+ cmd .SetArgs ([]string {"guestbook" })
114
+ err := cmd .Execute ()
115
+ assert .NoError (t , err )
116
+ stdout := o .Out .(* bytes.Buffer ).String ()
117
+ assert .NotEmpty (t , stdout )
118
+ stderr := o .ErrOut .(* bytes.Buffer ).String ()
119
+ assert .Empty (t , stderr )
120
+ }
121
+
97
122
func TestPromoteCmdSuccesSkipAllSteps (t * testing.T ) {
98
123
ro := v1alpha1.Rollout {
99
124
ObjectMeta : metav1.ObjectMeta {
@@ -144,7 +169,7 @@ func TestPromoteCmdSuccesSkipAllSteps(t *testing.T) {
144
169
assert .Empty (t , stderr )
145
170
}
146
171
147
- func TestPromoteCmdSuccesFirstStep (t * testing.T ) {
172
+ func TestPromoteCmdSuccesFirstStepWithSkipFirstStep (t * testing.T ) {
148
173
ro := v1alpha1.Rollout {
149
174
ObjectMeta : metav1.ObjectMeta {
150
175
Name : "guestbook" ,
@@ -194,6 +219,56 @@ func TestPromoteCmdSuccesFirstStep(t *testing.T) {
194
219
assert .Empty (t , stderr )
195
220
}
196
221
222
+ func TestPromoteCmdSuccesFirstStep (t * testing.T ) {
223
+ ro := v1alpha1.Rollout {
224
+ ObjectMeta : metav1.ObjectMeta {
225
+ Name : "guestbook" ,
226
+ Namespace : metav1 .NamespaceDefault ,
227
+ },
228
+ Spec : v1alpha1.RolloutSpec {
229
+ Strategy : v1alpha1.RolloutStrategy {
230
+ Canary : & v1alpha1.CanaryStrategy {
231
+ Steps : []v1alpha1.CanaryStep {
232
+ {
233
+ SetWeight : pointer .Int32Ptr (1 ),
234
+ },
235
+ {
236
+ SetWeight : pointer .Int32Ptr (2 ),
237
+ },
238
+ },
239
+ },
240
+ },
241
+ },
242
+ }
243
+
244
+ tf , o := options .NewFakeArgoRolloutsOptions (& ro )
245
+ defer tf .Cleanup ()
246
+ fakeClient := o .RolloutsClient .(* fakeroclient.Clientset )
247
+ fakeClient .PrependReactor ("patch" , "*" , func (action kubetesting.Action ) (handled bool , ret runtime.Object , err error ) {
248
+ if patchAction , ok := action .(kubetesting.PatchAction ); ok {
249
+ patchRo := v1alpha1.Rollout {}
250
+ err := json .Unmarshal (patchAction .GetPatch (), & patchRo )
251
+ if err != nil {
252
+ panic (err )
253
+ }
254
+ ro .Status .CurrentStepIndex = patchRo .Status .CurrentStepIndex
255
+ }
256
+ return true , & ro , nil
257
+ })
258
+
259
+ cmd := NewCmdPromote (o )
260
+ cmd .PersistentPreRunE = o .PersistentPreRunE
261
+ cmd .SetArgs ([]string {"guestbook" })
262
+
263
+ err := cmd .Execute ()
264
+ assert .Nil (t , err )
265
+ assert .Equal (t , int32 (1 ), * ro .Status .CurrentStepIndex )
266
+ stdout := o .Out .(* bytes.Buffer ).String ()
267
+ stderr := o .ErrOut .(* bytes.Buffer ).String ()
268
+ assert .Equal (t , stdout , "rollout 'guestbook' promoted\n " )
269
+ assert .Empty (t , stderr )
270
+ }
271
+
197
272
func TestPromoteCmdSuccessDoNotGoPastLastStep (t * testing.T ) {
198
273
ro := v1alpha1.Rollout {
199
274
ObjectMeta : metav1.ObjectMeta {
0 commit comments