Skip to content

Commit

Permalink
Refactor commly used vars to e2e test util
Browse files Browse the repository at this point in the history
  • Loading branch information
JeromeJu authored and tekton-robot committed Feb 9, 2024
1 parent 7ae602c commit 858883f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
13 changes: 0 additions & 13 deletions test/propagated_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
20 changes: 17 additions & 3 deletions test/util.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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()
Expand Down

0 comments on commit 858883f

Please sign in to comment.