Skip to content

Commit b56477c

Browse files
vdemeestertekton-robot
authored andcommitted
tests: fix pinp tests
Prior to this, they may affect the other tests (mainly examples one). Signed-off-by: Vincent Demeester <[email protected]>
1 parent bd9274d commit b56477c

File tree

2 files changed

+28
-45
lines changed

2 files changed

+28
-45
lines changed

test/pipelinerun_pinp_test.go

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,19 @@ import (
2929
th "github.com/tektoncd/pipeline/pkg/reconciler/testing"
3030
corev1 "k8s.io/api/core/v1"
3131
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
32+
knativetest "knative.dev/pkg/test"
3233
)
3334

34-
func TestPipelineRun_OneChildPipelineRunFromPipelineSpec(t *testing.T) {
35-
ctx, cancel, c, namespace := setupPinP(t)
35+
func TestPipelineRun_PinP_OneChildPipelineRunFromPipelineSpec(t *testing.T) {
36+
t.Parallel()
37+
ctx := t.Context()
38+
ctx, cancel := context.WithCancel(ctx)
3639
defer cancel()
37-
defer tearDownOptDump(ctx, t, c, namespace, true)
40+
c, namespace := setup(ctx, t, requireAnyGate(map[string]string{
41+
"enable-api-fields": "alpha",
42+
}))
43+
knativetest.CleanupOnInterrupt(func() { tearDown(ctx, t, c, namespace) }, t.Logf)
44+
defer tearDown(ctx, t, c, namespace)
3845

3946
// GIVEN
4047
t.Logf("Setting up test resources for one child PipelineRun from PipelineSpec in namespace %q", namespace)
@@ -100,10 +107,16 @@ func assertPinP(
100107
checkAnnotationPropagationToChildPipelineRun(ctx, t, c, namespace, directParentPrName, actualCpr)
101108
}
102109

103-
func TestPipelineRun_TwoChildPipelineRunsMixedTasks(t *testing.T) {
104-
ctx, cancel, c, namespace := setupPinP(t)
110+
func TestPipelineRun_PinP_TwoChildPipelineRunsMixedTasks(t *testing.T) {
111+
t.Parallel()
112+
ctx := t.Context()
113+
ctx, cancel := context.WithCancel(ctx)
105114
defer cancel()
106-
defer tearDownOptDump(ctx, t, c, namespace, true)
115+
c, namespace := setup(ctx, t, requireAnyGate(map[string]string{
116+
"enable-api-fields": "alpha",
117+
}))
118+
knativetest.CleanupOnInterrupt(func() { tearDown(ctx, t, c, namespace) }, t.Logf)
119+
defer tearDown(ctx, t, c, namespace)
107120

108121
// GIVEN
109122
t.Logf("Setting up test resources for two child PipelineRuns (mixed tasks) in namespace %q", namespace)
@@ -124,10 +137,16 @@ func TestPipelineRun_TwoChildPipelineRunsMixedTasks(t *testing.T) {
124137
assertEvents(ctx, t, expectedEventsAmount, expectedKinds, c, namespace)
125138
}
126139

127-
func TestPipelineRun_TwoLevelDeepNestedChildPipelineRuns(t *testing.T) {
128-
ctx, cancel, c, namespace := setupPinP(t)
140+
func TestPipelineRun_PinP_TwoLevelDeepNestedChildPipelineRuns(t *testing.T) {
141+
t.Parallel()
142+
ctx := t.Context()
143+
ctx, cancel := context.WithCancel(ctx)
129144
defer cancel()
130-
defer tearDownOptDump(ctx, t, c, namespace, true)
145+
c, namespace := setup(ctx, t, requireAnyGate(map[string]string{
146+
"enable-api-fields": "alpha",
147+
}))
148+
knativetest.CleanupOnInterrupt(func() { tearDown(ctx, t, c, namespace) }, t.Logf)
149+
defer tearDown(ctx, t, c, namespace)
131150

132151
// GIVEN
133152
t.Logf("Setting up test resources for two level deep nested child PipelineRuns in namespace %q", namespace)

test/util.go

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -95,31 +95,6 @@ func setup(ctx context.Context, t *testing.T, fn ...func(context.Context, *testi
9595
return c, namespace
9696
}
9797

98-
func setupPinP(t *testing.T) (context.Context, context.CancelFunc, *clients, string) {
99-
t.Helper()
100-
101-
t.Parallel()
102-
ctx := t.Context()
103-
ctx, cancel := context.WithCancel(ctx)
104-
c, namespace := setup(ctx, t)
105-
106-
knativetest.CleanupOnInterrupt(func() { tearDown(ctx, t, c, namespace) }, t.Logf)
107-
108-
t.Log("Activating alpha feature flags")
109-
configMapData := map[string]string{"enable-api-fields": "alpha"}
110-
if err := updateConfigMap(
111-
ctx,
112-
c.KubeClient,
113-
system.Namespace(),
114-
config.GetFeatureFlagsConfigName(),
115-
configMapData,
116-
); err != nil {
117-
t.Fatal(err)
118-
}
119-
120-
return ctx, cancel, c, namespace
121-
}
122-
12398
func header(t *testing.T, text string) {
12499
t.Helper()
125100
left := "### "
@@ -166,17 +141,6 @@ func tearDown(ctx context.Context, t *testing.T, cs *clients, namespace string)
166141
}
167142
}
168143

169-
// tearDownNoDump prevents dumping Task/Pipeline/PipelineRun/TaskRun yamls to the terminal
170-
// when a test fails. Useful for investigating issues from terminal logs without the
171-
// need to scroll over all the deployed resource yamls.
172-
func tearDownOptDump(ctx context.Context, t *testing.T, c *clients, namespace string, dump bool) {
173-
t.Helper()
174-
if !dump {
175-
c.KubeClient = nil
176-
}
177-
tearDown(ctx, t, c, namespace)
178-
}
179-
180144
func initializeLogsAndMetrics(t *testing.T) {
181145
t.Helper()
182146
initMetrics.Do(func() {

0 commit comments

Comments
 (0)