-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prior to this, we only had examples for propagated parameters. This PR adds e2e tests for testing this feature instead of simply relying on the examples.
- Loading branch information
1 parent
5d34b0c
commit 830c735
Showing
1 changed file
with
161 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
//go:build e2e | ||
// +build e2e | ||
|
||
/* | ||
Copyright 2022 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/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" | ||
"github.com/tektoncd/pipeline/test/parse" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
knativetest "knative.dev/pkg/test" | ||
) | ||
|
||
func TestPropagatedParams(t *testing.T) { | ||
t.Parallel() | ||
type tests struct { | ||
name string | ||
pipelineName string | ||
taskName string | ||
pipelineRunFunc func(*testing.T, string, string, string) *v1beta1.PipelineRun | ||
} | ||
|
||
tds := []tests{{ | ||
name: "propagated parameters fully", | ||
pipelineName: "propagated-parameters-fully", | ||
taskName: "echo-hello", | ||
pipelineRunFunc: getPropagatedParamPipelineRun, | ||
}, { | ||
name: "propagated parameters with inner scope", | ||
pipelineName: "propagated-parameters-inner-scope", | ||
taskName: "echo-hello", | ||
pipelineRunFunc: getPropagatedParamWithScopePipelineRun, | ||
}, { | ||
name: "propagated parameters with default inner scope", | ||
pipelineName: "propagated-parameters-default-inner-scope", | ||
taskName: "echo-hello", | ||
pipelineRunFunc: getPropagatedParamWithDefaultScopePipelineRun, | ||
}} | ||
|
||
for _, td := range tds { | ||
td := td | ||
t.Run(td.name, func(t *testing.T) { | ||
t.Parallel() | ||
ctx := context.Background() | ||
ctx, cancel := context.WithCancel(ctx) | ||
defer cancel() | ||
|
||
propagatedParamFlags := requireAllGates(map[string]string{ | ||
"enable-api-fields": "alpha", | ||
}) | ||
c, namespace := setup(ctx, t, propagatedParamFlags) | ||
|
||
knativetest.CleanupOnInterrupt(func() { tearDown(ctx, t, c, namespace) }, t.Logf) | ||
defer tearDown(ctx, t, c, namespace) | ||
|
||
t.Logf("Setting up test resources for %q test in namespace %s", td.name, namespace) | ||
pipelineRun := td.pipelineRunFunc(t, namespace, td.pipelineName, td.taskName) | ||
prName := pipelineRun.Name | ||
_, err := c.PipelineRunClient.Create(ctx, pipelineRun, metav1.CreateOptions{}) | ||
if err != nil { | ||
t.Fatalf("Failed to create PipelineRun `%s`: %s", prName, err) | ||
} | ||
|
||
t.Logf("Waiting for PipelineRun %s in namespace %s to complete", prName, namespace) | ||
if err := WaitForPipelineRunState(ctx, c, prName, timeout, PipelineRunSucceed(prName), "PipelineRunSuccess"); err != nil { | ||
t.Fatalf("Error waiting for PipelineRun %s to finish: %s", prName, err) | ||
} | ||
t.Log("Checking if parameter replacements have been updated in the spec.") | ||
cl, _ := c.PipelineRunClient.Get(ctx, prName, metav1.GetOptions{}) | ||
if cl.Status.PipelineSpec.Tasks[0].TaskSpec.Steps[0].Script != "echo Hello World!" { | ||
t.Fatalf(`Expected replaced parameter value %s but found %s`, "echo Hello World!", cl.Status.PipelineSpec.Tasks[0].TaskSpec.Steps[0].Script) | ||
} | ||
t.Logf("Successfully finished test %q", td.name) | ||
}) | ||
} | ||
} | ||
|
||
func getPropagatedParamPipelineRun(t *testing.T, namespace string, pipelineName string, taskName string) *v1beta1.PipelineRun { | ||
return parse.MustParsePipelineRun(t, fmt.Sprintf(` | ||
metadata: | ||
name: %s | ||
namespace: %s | ||
spec: | ||
params: | ||
- name: HELLO | ||
value: "Hello World!" | ||
pipelineSpec: | ||
tasks: | ||
- name: %s | ||
taskSpec: | ||
steps: | ||
- name: echo | ||
image: ubuntu | ||
script: echo $(params.HELLO) | ||
`, pipelineName, namespace, taskName)) | ||
} | ||
|
||
func getPropagatedParamWithScopePipelineRun(t *testing.T, namespace string, pipelineName string, taskName string) *v1beta1.PipelineRun { | ||
return parse.MustParsePipelineRun(t, fmt.Sprintf(` | ||
metadata: | ||
name: %s | ||
namespace: %s | ||
spec: | ||
params: | ||
- name: HELLO | ||
value: "Pipeline Hello World!" | ||
pipelineSpec: | ||
tasks: | ||
- name: %s | ||
params: | ||
- name: HELLO | ||
value: "Hello World!" | ||
taskSpec: | ||
steps: | ||
- name: echo | ||
image: ubuntu | ||
script: echo $(params.HELLO) | ||
`, pipelineName, namespace, taskName)) | ||
} | ||
|
||
func getPropagatedParamWithDefaultScopePipelineRun(t *testing.T, namespace string, pipelineName string, taskName string) *v1beta1.PipelineRun { | ||
return parse.MustParsePipelineRun(t, fmt.Sprintf(` | ||
metadata: | ||
name: %s | ||
namespace: %s | ||
spec: | ||
params: | ||
- name: HELLO | ||
value: "Hello World!" | ||
pipelineSpec: | ||
tasks: | ||
- name: %s | ||
taskSpec: | ||
params: | ||
- name: HELLO | ||
default: "Default Hello World" | ||
steps: | ||
- name: echo | ||
image: ubuntu | ||
script: echo $(params.HELLO) | ||
`, pipelineName, namespace, taskName)) | ||
} |