@@ -3076,12 +3076,13 @@ func TestReconcileWorkspaceWithVolumeClaimTemplate(t *testing.T) {
3076
3076
3077
3077
func TestFailTaskRun (t * testing.T ) {
3078
3078
testCases := []struct {
3079
- name string
3080
- taskRun * v1beta1.TaskRun
3081
- pod * corev1.Pod
3082
- reason v1beta1.TaskRunReason
3083
- message string
3084
- expectedStatus apis.Condition
3079
+ name string
3080
+ taskRun * v1beta1.TaskRun
3081
+ pod * corev1.Pod
3082
+ reason v1beta1.TaskRunReason
3083
+ message string
3084
+ expectedStatus apis.Condition
3085
+ expectedStepStates []v1beta1.StepState
3085
3086
}{{
3086
3087
name : "no-pod-scheduled" ,
3087
3088
taskRun : tb .TaskRun ("test-taskrun-run-failed" , tb .TaskRunNamespace ("foo" ), tb .TaskRunSpec (
@@ -3120,6 +3121,180 @@ func TestFailTaskRun(t *testing.T) {
3120
3121
Reason : "some reason" ,
3121
3122
Message : "some message" ,
3122
3123
},
3124
+ }, {
3125
+ name : "step-status-update-cancel" ,
3126
+ taskRun : tb .TaskRun ("test-taskrun-run-cancel" , tb .TaskRunNamespace ("foo" ), tb .TaskRunSpec (
3127
+ tb .TaskRunTaskRef (simpleTask .Name ),
3128
+ tb .TaskRunCancelled ,
3129
+ ), tb .TaskRunStatus (tb .StatusCondition (apis.Condition {
3130
+ Type : apis .ConditionSucceeded ,
3131
+ Status : corev1 .ConditionUnknown ,
3132
+ }), tb .StepState (
3133
+ tb .SetStepStateRunning (corev1.ContainerStateRunning {StartedAt : metav1.Time {Time : time .Now ()}}),
3134
+ ), tb .PodName ("foo-is-bar" ))),
3135
+ pod : & corev1.Pod {ObjectMeta : metav1.ObjectMeta {
3136
+ Namespace : "foo" ,
3137
+ Name : "foo-is-bar" ,
3138
+ }},
3139
+ reason : "TaskRunCancelled" ,
3140
+ message : "TaskRun test-taskrun-run-cancel was cancelled" ,
3141
+ expectedStatus : apis.Condition {
3142
+ Type : apis .ConditionSucceeded ,
3143
+ Status : corev1 .ConditionFalse ,
3144
+ Reason : "TaskRunCancelled" ,
3145
+ Message : "TaskRun test-taskrun-run-cancel was cancelled" ,
3146
+ },
3147
+ expectedStepStates : []v1beta1.StepState {
3148
+ {
3149
+ ContainerState : corev1.ContainerState {
3150
+ Terminated : & corev1.ContainerStateTerminated {
3151
+ ExitCode : 1 ,
3152
+ Reason : "TaskRunCancelled" ,
3153
+ },
3154
+ },
3155
+ },
3156
+ },
3157
+ }, {
3158
+ name : "step-status-update-timeout" ,
3159
+ taskRun : tb .TaskRun ("test-taskrun-run-timeout" , tb .TaskRunNamespace ("foo" ), tb .TaskRunSpec (
3160
+ tb .TaskRunTaskRef (simpleTask .Name ),
3161
+ tb .TaskRunTimeout (time .Duration (10 * time .Second )),
3162
+ ), tb .TaskRunStatus (tb .StatusCondition (apis.Condition {
3163
+ Type : apis .ConditionSucceeded ,
3164
+ Status : corev1 .ConditionUnknown ,
3165
+ }), tb .StepState (
3166
+ tb .SetStepStateRunning (corev1.ContainerStateRunning {StartedAt : metav1.Time {Time : time .Now ()}}),
3167
+ ), tb .PodName ("foo-is-bar" ))),
3168
+ pod : & corev1.Pod {ObjectMeta : metav1.ObjectMeta {
3169
+ Namespace : "foo" ,
3170
+ Name : "foo-is-bar" ,
3171
+ }},
3172
+ reason : "TaskRunTimeout" ,
3173
+ message : "TaskRun test-taskrun-run-timeout failed to finish within 10s" ,
3174
+ expectedStatus : apis.Condition {
3175
+ Type : apis .ConditionSucceeded ,
3176
+ Status : corev1 .ConditionFalse ,
3177
+ Reason : "TaskRunTimeout" ,
3178
+ Message : "TaskRun test-taskrun-run-timeout failed to finish within 10s" ,
3179
+ },
3180
+ expectedStepStates : []v1beta1.StepState {
3181
+ {
3182
+ ContainerState : corev1.ContainerState {
3183
+ Terminated : & corev1.ContainerStateTerminated {
3184
+ ExitCode : 1 ,
3185
+ Reason : "TaskRunTimeout" ,
3186
+ },
3187
+ },
3188
+ },
3189
+ },
3190
+ }, {
3191
+ name : "step-status-update-multiple-steps" ,
3192
+ taskRun : tb .TaskRun ("test-taskrun-run-timeout-multiple-steps" , tb .TaskRunNamespace ("foo" ), tb .TaskRunSpec (
3193
+ tb .TaskRunTaskRef (taskMultipleSteps .Name ),
3194
+ tb .TaskRunTimeout (time .Duration (10 * time .Second )),
3195
+ ), tb .TaskRunStatus (tb .StatusCondition (apis.Condition {
3196
+ Type : apis .ConditionSucceeded ,
3197
+ Status : corev1 .ConditionUnknown ,
3198
+ }), tb .StepState (
3199
+ tb .SetStepStateTerminated (corev1.ContainerStateTerminated {StartedAt : metav1.Time {Time : time .Now ()}, FinishedAt : metav1.Time {Time : time .Now ()}, Reason : "Completed" }),
3200
+ ), tb .StepState (
3201
+ tb .SetStepStateRunning (corev1.ContainerStateRunning {StartedAt : metav1.Time {Time : time .Now ()}}),
3202
+ ), tb .StepState (
3203
+ tb .SetStepStateRunning (corev1.ContainerStateRunning {StartedAt : metav1.Time {Time : time .Now ()}}),
3204
+ ),
3205
+ tb .PodName ("foo-is-bar" ))),
3206
+ pod : & corev1.Pod {ObjectMeta : metav1.ObjectMeta {
3207
+ Namespace : "foo" ,
3208
+ Name : "foo-is-bar" ,
3209
+ }},
3210
+ reason : "TaskRunTimeout" ,
3211
+ message : "TaskRun test-taskrun-run-timeout-multiple-steps failed to finish within 10s" ,
3212
+ expectedStatus : apis.Condition {
3213
+ Type : apis .ConditionSucceeded ,
3214
+ Status : corev1 .ConditionFalse ,
3215
+ Reason : "TaskRunTimeout" ,
3216
+ Message : "TaskRun test-taskrun-run-timeout-multiple-steps failed to finish within 10s" ,
3217
+ },
3218
+ expectedStepStates : []v1beta1.StepState {
3219
+ {
3220
+ ContainerState : corev1.ContainerState {
3221
+ Terminated : & corev1.ContainerStateTerminated {
3222
+ ExitCode : 0 ,
3223
+ Reason : "Completed" ,
3224
+ },
3225
+ },
3226
+ },
3227
+ {
3228
+ ContainerState : corev1.ContainerState {
3229
+ Terminated : & corev1.ContainerStateTerminated {
3230
+ ExitCode : 1 ,
3231
+ Reason : "TaskRunTimeout" ,
3232
+ },
3233
+ },
3234
+ },
3235
+ {
3236
+ ContainerState : corev1.ContainerState {
3237
+ Terminated : & corev1.ContainerStateTerminated {
3238
+ ExitCode : 1 ,
3239
+ Reason : "TaskRunTimeout" ,
3240
+ },
3241
+ },
3242
+ },
3243
+ },
3244
+ }, {
3245
+ name : "step-status-update-multiple-steps-waiting-state" ,
3246
+ taskRun : tb .TaskRun ("test-taskrun-run-timeout-multiple-steps-waiting" , tb .TaskRunNamespace ("foo" ), tb .TaskRunSpec (
3247
+ tb .TaskRunTaskRef (taskMultipleSteps .Name ),
3248
+ tb .TaskRunTimeout (time .Duration (10 * time .Second )),
3249
+ ), tb .TaskRunStatus (tb .StatusCondition (apis.Condition {
3250
+ Type : apis .ConditionSucceeded ,
3251
+ Status : corev1 .ConditionUnknown ,
3252
+ }), tb .StepState (
3253
+ tb .SetStepStateWaiting (corev1.ContainerStateWaiting {Reason : "PodInitializing" }),
3254
+ ), tb .StepState (
3255
+ tb .SetStepStateWaiting (corev1.ContainerStateWaiting {Reason : "PodInitializing" }),
3256
+ ), tb .StepState (
3257
+ tb .SetStepStateWaiting (corev1.ContainerStateWaiting {Reason : "PodInitializing" }),
3258
+ ),
3259
+ tb .PodName ("foo-is-bar" ))),
3260
+ pod : & corev1.Pod {ObjectMeta : metav1.ObjectMeta {
3261
+ Namespace : "foo" ,
3262
+ Name : "foo-is-bar" ,
3263
+ }},
3264
+ reason : "TaskRunTimeout" ,
3265
+ message : "TaskRun test-taskrun-run-timeout-multiple-steps-waiting failed to finish within 10s" ,
3266
+ expectedStatus : apis.Condition {
3267
+ Type : apis .ConditionSucceeded ,
3268
+ Status : corev1 .ConditionFalse ,
3269
+ Reason : "TaskRunTimeout" ,
3270
+ Message : "TaskRun test-taskrun-run-timeout-multiple-steps-waiting failed to finish within 10s" ,
3271
+ },
3272
+ expectedStepStates : []v1beta1.StepState {
3273
+ {
3274
+ ContainerState : corev1.ContainerState {
3275
+ Terminated : & corev1.ContainerStateTerminated {
3276
+ ExitCode : 1 ,
3277
+ Reason : "TaskRunTimeout" ,
3278
+ },
3279
+ },
3280
+ },
3281
+ {
3282
+ ContainerState : corev1.ContainerState {
3283
+ Terminated : & corev1.ContainerStateTerminated {
3284
+ ExitCode : 1 ,
3285
+ Reason : "TaskRunTimeout" ,
3286
+ },
3287
+ },
3288
+ },
3289
+ {
3290
+ ContainerState : corev1.ContainerState {
3291
+ Terminated : & corev1.ContainerStateTerminated {
3292
+ ExitCode : 1 ,
3293
+ Reason : "TaskRunTimeout" ,
3294
+ },
3295
+ },
3296
+ },
3297
+ },
3123
3298
}}
3124
3299
3125
3300
for _ , tc := range testCases {
@@ -3156,6 +3331,13 @@ func TestFailTaskRun(t *testing.T) {
3156
3331
if d := cmp .Diff (tc .taskRun .Status .GetCondition (apis .ConditionSucceeded ), & tc .expectedStatus , ignoreLastTransitionTime ); d != "" {
3157
3332
t .Fatalf (diff .PrintWantGot (d ))
3158
3333
}
3334
+
3335
+ if tc .expectedStepStates != nil {
3336
+ ignoreTerminatedFields := cmpopts .IgnoreFields (corev1.ContainerStateTerminated {}, "StartedAt" , "FinishedAt" )
3337
+ if c := cmp .Diff (tc .expectedStepStates , tc .taskRun .Status .Steps , ignoreTerminatedFields ); c != "" {
3338
+ t .Errorf ("test %s failed: %s" , tc .name , diff .PrintWantGot (c ))
3339
+ }
3340
+ }
3159
3341
})
3160
3342
}
3161
3343
}
0 commit comments