From 858883fb8bcd15cc27bfef0c9540910af0c331cb Mon Sep 17 00:00:00 2001 From: JeromeJu Date: Tue, 30 Jan 2024 22:49:27 +0000 Subject: [PATCH] Refactor commly used vars to e2e test util --- test/propagated_params_test.go | 13 ------------- test/util.go | 20 +++++++++++++++++--- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/test/propagated_params_test.go b/test/propagated_params_test.go index 727f496b901..4e615201124 100644 --- a/test/propagated_params_test.go +++ b/test/propagated_params_test.go @@ -28,26 +28,13 @@ import ( "github.com/google/go-cmp/cmp/cmpopts" v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" "github.com/tektoncd/pipeline/test/parse" - corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" knativetest "knative.dev/pkg/test" ) var ( - ignoreTypeMeta = cmpopts.IgnoreFields(metav1.TypeMeta{}, "Kind", "APIVersion") - ignoreObjectMeta = cmpopts.IgnoreFields(metav1.ObjectMeta{}, "ResourceVersion", "UID", "CreationTimestamp", "Generation", "ManagedFields", "Labels", "Annotations", "OwnerReferences") - ignoreCondition = cmpopts.IgnoreFields(apis.Condition{}, "LastTransitionTime.Inner.Time", "Message") ignorePipelineRunStatus = cmpopts.IgnoreFields(v1.PipelineRunStatusFields{}, "StartTime", "CompletionTime", "FinallyStartTime", "ChildReferences") ignoreTaskRunStatus = cmpopts.IgnoreFields(v1.TaskRunStatusFields{}, "StartTime", "CompletionTime") - ignoreConditions = cmpopts.IgnoreFields(duckv1.Status{}, "Conditions") - ignoreContainerStates = cmpopts.IgnoreFields(corev1.ContainerState{}, "Terminated") - ignoreStepState = cmpopts.IgnoreFields(v1.StepState{}, "ImageID", "TerminationReason") - // ignoreSATaskRunSpec ignores the service account in the TaskRunSpec as it may differ across platforms - ignoreSATaskRunSpec = cmpopts.IgnoreFields(v1.TaskRunSpec{}, "ServiceAccountName") - // ignoreSAPipelineRunSpec ignores the service account in the PipelineRunSpec as it may differ across platforms - ignoreSAPipelineRunSpec = cmpopts.IgnoreFields(v1.PipelineTaskRunTemplate{}, "ServiceAccountName") ) func TestPropagatedParams(t *testing.T) { diff --git a/test/util.go b/test/util.go index 74b3c6392a8..ad274c55801 100644 --- a/test/util.go +++ b/test/util.go @@ -1,5 +1,5 @@ -//go:build conformance || e2e || examples -// +build conformance e2e examples +//go:build conformance || e2e || examples || featureflags +// +build conformance e2e examples featureflags /* Copyright 2023 The Tekton Authors @@ -28,7 +28,9 @@ import ( "sync" "testing" + "github.com/google/go-cmp/cmp/cmpopts" "github.com/tektoncd/pipeline/pkg/apis/config" + v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" "github.com/tektoncd/pipeline/pkg/names" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" @@ -46,7 +48,19 @@ import ( "sigs.k8s.io/yaml" ) -var initMetrics sync.Once +var ( + initMetrics sync.Once + ignoreTypeMeta = cmpopts.IgnoreFields(metav1.TypeMeta{}, "Kind", "APIVersion") + ignoreObjectMeta = cmpopts.IgnoreFields(metav1.ObjectMeta{}, "ResourceVersion", "UID", "CreationTimestamp", "Generation", "ManagedFields", "Labels", "Annotations", "OwnerReferences") + ignoreCondition = cmpopts.IgnoreFields(apis.Condition{}, "LastTransitionTime.Inner.Time", "Message") + ignoreConditions = cmpopts.IgnoreFields(duckv1.Status{}, "Conditions") + ignoreStepState = cmpopts.IgnoreFields(v1.StepState{}, "ImageID", "TerminationReason") + ignoreContainerStates = cmpopts.IgnoreFields(corev1.ContainerState{}, "Terminated") + // ignoreSATaskRunSpec ignores the service account in the TaskRunSpec as it may differ across platforms + ignoreSATaskRunSpec = cmpopts.IgnoreFields(v1.TaskRunSpec{}, "ServiceAccountName") + // ignoreSAPipelineRunSpec ignores the service account in the PipelineRunSpec as it may differ across platforms + ignoreSAPipelineRunSpec = cmpopts.IgnoreFields(v1.PipelineTaskRunTemplate{}, "ServiceAccountName") +) func setup(ctx context.Context, t *testing.T, fn ...func(context.Context, *testing.T, *clients, string)) (*clients, string) { t.Helper()