forked from tektoncd/pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathignore_task_error_test.go
127 lines (113 loc) · 4.19 KB
/
ignore_task_error_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//go:build e2e
// +build e2e
/*
Copyright 2023 The Tekton Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package test
import (
"context"
"fmt"
"testing"
"github.com/google/go-cmp/cmp"
v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
"github.com/tektoncd/pipeline/test/diff"
"github.com/tektoncd/pipeline/test/parse"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
knativetest "knative.dev/pkg/test"
)
func TestFailingPipelineTaskOnContinue(t *testing.T) {
ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)
defer cancel()
c, namespace := setup(ctx, t, requireAnyGate(map[string]string{"enable-api-fields": "alpha"}))
knativetest.CleanupOnInterrupt(func() { tearDown(ctx, t, c, namespace) }, t.Logf)
defer tearDown(ctx, t, c, namespace)
prName := "my-pipelinerun"
pr := parse.MustParseV1PipelineRun(t, fmt.Sprintf(`
metadata:
name: %s
namespace: %s
spec:
pipelineSpec:
tasks:
- name: failed-ignored-task
onError: continue
taskSpec:
results:
- name: result1
type: string
steps:
- name: failing-step
image: busybox
script: 'exit 1; echo -n 123 | tee $(results.result1.path)'
- name: order-dep-task
runAfter: ["failed-ignored-task"]
taskSpec:
steps:
- name: foo
image: busybox
script: 'echo hello'
- name: resource-dep-task
onError: continue
params:
- name: param1
value: $(tasks.failed-ignored-task.results.result1)
taskSpec:
params:
- name: param1
type: string
steps:
- name: foo
image: busybox
script: 'echo $(params.param1)'
`, prName, namespace))
if _, err := c.V1PipelineRunClient.Create(ctx, pr, metav1.CreateOptions{}); err != nil {
t.Fatalf("Failed to create PipelineRun: %s", err)
}
// wait for PipelineRun to finish
t.Logf("Waiting for PipelineRun in namespace %s to finish", namespace)
if err := WaitForPipelineRunState(ctx, c, prName, timeout, PipelineRunSucceed(prName), "PipelineRunSucceeded", v1Version); err != nil {
t.Errorf("Error waiting for PipelineRun to finish: %s", err)
}
// validate pipelinerun success, with right TaskRun counts
pr, err := c.V1PipelineRunClient.Get(ctx, "my-pipelinerun", metav1.GetOptions{})
if err != nil {
t.Fatalf("Couldn't get expected PipelineRun my-pipelinerun: %s", err)
}
cond := pr.Status.Conditions[0]
if cond.Status != corev1.ConditionTrue {
t.Fatalf("Expect my-pipelinerun to success but got: %s", cond)
}
expectErrMsg := "Tasks Completed: 2 (Failed: 1 (Ignored: 1), Cancelled 0), Skipped: 1"
if d := cmp.Diff(expectErrMsg, cond.Message); d != "" {
t.Errorf("Got unexpected error message %s", diff.PrintWantGot(d))
}
// validate first TaskRun to fail but ignored
failedTaskRun, err := c.V1TaskRunClient.Get(ctx, "my-pipelinerun-failed-ignored-task", metav1.GetOptions{})
if err != nil {
t.Fatalf("Couldn't get expected TaskRun my-pipelinerun-failed-ignored-task: %s", err)
}
cond = failedTaskRun.Status.Conditions[0]
if cond.Status != corev1.ConditionFalse || cond.Reason != string(v1.TaskRunReasonFailureIgnored) {
t.Errorf("Expect failed-ignored-task Task in Failed status with reason %s, but got %s status with reason: %s", v1.TaskRunReasonFailureIgnored, cond.Status, cond.Reason)
}
// validate second TaskRun succeeded
orderDepTaskRun, err := c.V1TaskRunClient.Get(ctx, "my-pipelinerun-order-dep-task", metav1.GetOptions{})
if err != nil {
t.Fatalf("Couldn't get expected TaskRun my-pipelinerun-order-dep-task: %s", err)
}
cond = orderDepTaskRun.Status.Conditions[0]
if cond.Status != corev1.ConditionTrue {
t.Errorf("Expect order-dep-task Task to success but got: %s", cond)
}
}