-
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 f0481d3
Showing
1 changed file
with
367 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,367 @@ | ||
//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/google/go-cmp/cmp" | ||
"github.com/google/go-cmp/cmp/cmpopts" | ||
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" | ||
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" | ||
"github.com/tektoncd/pipeline/test/parse" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"knative.dev/pkg/apis" | ||
duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1" | ||
knativetest "knative.dev/pkg/test" | ||
) | ||
|
||
var ( | ||
ignoreTypeMeta = cmpopts.IgnoreFields(metav1.TypeMeta{}, "Kind", "APIVersion") | ||
ignoreObjectMeta = cmpopts.IgnoreFields(metav1.ObjectMeta{}, "ResourceVersion", "UID", "CreationTimestamp", "Generation", "ManagedFields", "Labels") | ||
ignoreCondition = cmpopts.IgnoreFields(apis.Condition{}, "LastTransitionTime.Inner.Time", "Message") | ||
ignoreRunStatus = cmpopts.IgnoreFields(v1alpha1.RunStatusFields{}, "StartTime", "CompletionTime") | ||
ignorePipelineRunStatus = cmpopts.IgnoreFields(v1beta1.PipelineRunStatusFields{}, "StartTime", "CompletionTime", "FinallyStartTime") | ||
ignoreTaskRunStatus = cmpopts.IgnoreFields(v1beta1.TaskRunStatusFields{}, "StartTime", "CompletionTime") | ||
ignoreConditions = cmpopts.IgnoreFields(duckv1beta1.Status{}, "Conditions") | ||
ignoreContainerStates = cmpopts.IgnoreFields(corev1.ContainerState{}, "Terminated") | ||
ignoreStepState = cmpopts.IgnoreFields(v1beta1.StepState{}, "ImageID") | ||
) | ||
|
||
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, *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, expectedResolvedPipelineRun := 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) | ||
} | ||
cl, _ := c.PipelineRunClient.Get(ctx, prName, metav1.GetOptions{}) | ||
if d := cmp.Diff(expectedResolvedPipelineRun, cl, | ||
ignoreTypeMeta, | ||
ignoreObjectMeta, | ||
ignoreCondition, | ||
ignoreRunStatus, | ||
ignorePipelineRunStatus, | ||
ignoreTaskRunStatus, | ||
ignoreConditions, | ||
ignoreContainerStates, | ||
ignoreStepState, | ||
); d != "" { | ||
t.Fatalf(`The resolved spec does not match the expected spec: %v`, d) | ||
} | ||
t.Logf("Successfully finished test %q", td.name) | ||
}) | ||
} | ||
} | ||
|
||
func getPropagatedParamPipelineRun(t *testing.T, namespace string, pipelineName string, taskName string) (*v1beta1.PipelineRun, *v1beta1.PipelineRun) { | ||
pipelineRun := 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) | ||
finally: | ||
- name: %s-finally | ||
taskSpec: | ||
steps: | ||
- name: echo | ||
image: ubuntu | ||
script: echo $(params.HELLO) | ||
`, pipelineName, namespace, taskName, taskName)) | ||
expectedPipelineRun := parse.MustParsePipelineRun(t, fmt.Sprintf(` | ||
metadata: | ||
name: %s | ||
namespace: %s | ||
spec: | ||
serviceAccountName: default | ||
timeout: 1h | ||
params: | ||
- name: HELLO | ||
value: "Hello World!" | ||
pipelineSpec: | ||
tasks: | ||
- name: %s | ||
taskSpec: | ||
steps: | ||
- name: echo | ||
image: ubuntu | ||
script: echo $(params.HELLO) | ||
finally: | ||
- name: %s-finally | ||
taskSpec: | ||
steps: | ||
- name: echo | ||
image: ubuntu | ||
script: echo $(params.HELLO) | ||
status: | ||
taskRuns: | ||
%s-%s: | ||
pipelineTaskName: %s | ||
status: | ||
podName: %s-%s-pod | ||
steps: | ||
- name: echo | ||
container: step-echo | ||
taskSpec: | ||
steps: | ||
- name: echo | ||
image: ubuntu | ||
script: echo Hello World! | ||
%s-%s-finally: | ||
pipelineTaskName: %s-finally | ||
status: | ||
podName: %s-%s-finally-pod | ||
steps: | ||
- name: echo | ||
container: step-echo | ||
taskSpec: | ||
steps: | ||
- name: echo | ||
image: ubuntu | ||
script: echo Hello World! | ||
pipelineSpec: | ||
tasks: | ||
- name: %s | ||
taskSpec: | ||
steps: | ||
- name: echo | ||
image: ubuntu | ||
script: echo Hello World! | ||
finally: | ||
- name: %s-finally | ||
taskSpec: | ||
steps: | ||
- name: echo | ||
image: ubuntu | ||
script: echo Hello World! | ||
`, pipelineName, namespace, taskName, taskName, pipelineName, taskName, taskName, pipelineName, taskName, pipelineName, taskName, taskName, pipelineName, taskName, taskName, taskName)) | ||
return pipelineRun, expectedPipelineRun | ||
} | ||
|
||
func getPropagatedParamWithScopePipelineRun(t *testing.T, namespace string, pipelineName string, taskName string) (*v1beta1.PipelineRun, *v1beta1.PipelineRun) { | ||
pipelineRun := 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)) | ||
expectedPipelineRun := parse.MustParsePipelineRun(t, fmt.Sprintf(` | ||
metadata: | ||
name: %s | ||
namespace: %s | ||
spec: | ||
timeout: 1h | ||
serviceAccountName: default | ||
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) | ||
status: | ||
taskRuns: | ||
%s-%s: | ||
pipelineTaskName: %s | ||
status: | ||
podName: %s-%s-pod | ||
steps: | ||
- name: echo | ||
container: step-echo | ||
taskSpec: | ||
steps: | ||
- name: echo | ||
image: ubuntu | ||
script: echo Hello World! | ||
pipelineSpec: | ||
tasks: | ||
- name: %s | ||
params: | ||
- name: HELLO | ||
value: "Hello World!" | ||
taskSpec: | ||
steps: | ||
- name: echo | ||
image: ubuntu | ||
script: echo Hello World! | ||
`, pipelineName, namespace, taskName, pipelineName, taskName, taskName, pipelineName, taskName, taskName)) | ||
|
||
return pipelineRun, expectedPipelineRun | ||
} | ||
|
||
func getPropagatedParamWithDefaultScopePipelineRun(t *testing.T, namespace string, pipelineName string, taskName string) (*v1beta1.PipelineRun, *v1beta1.PipelineRun) { | ||
pipelineRun := 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 | ||
type: string | ||
default: "Default Hello World" | ||
steps: | ||
- name: echo | ||
image: ubuntu | ||
script: echo $(params.HELLO) | ||
`, pipelineName, namespace, taskName)) | ||
expectedPipelineRun := parse.MustParsePipelineRun(t, fmt.Sprintf(` | ||
metadata: | ||
name: %s | ||
namespace: %s | ||
spec: | ||
serviceAccountName: default | ||
timeout: 1h | ||
params: | ||
- name: HELLO | ||
value: "Hello World!" | ||
pipelineSpec: | ||
tasks: | ||
- name: %s | ||
taskSpec: | ||
params: | ||
- name: HELLO | ||
type: string | ||
default: "Default Hello World" | ||
steps: | ||
- name: echo | ||
image: ubuntu | ||
script: echo $(params.HELLO) | ||
status: | ||
taskRuns: | ||
%s-%s: | ||
pipelineTaskName: %s | ||
status: | ||
podName: %s-%s-pod | ||
steps: | ||
- name: echo | ||
container: step-echo | ||
taskSpec: | ||
params: | ||
- name: HELLO | ||
type: string | ||
default: "Default Hello World" | ||
steps: | ||
- name: echo | ||
image: ubuntu | ||
script: echo Hello World! | ||
pipelineSpec: | ||
tasks: | ||
- name: %s | ||
taskSpec: | ||
params: | ||
- name: HELLO | ||
type: string | ||
default: "Default Hello World" | ||
steps: | ||
- name: echo | ||
image: ubuntu | ||
script: echo Hello World! | ||
`, pipelineName, namespace, taskName, pipelineName, taskName, taskName, pipelineName, taskName, taskName)) | ||
return pipelineRun, expectedPipelineRun | ||
} |