From 8f4ccf03c7d6797ca80e4209dca116c8326e00e3 Mon Sep 17 00:00:00 2001 From: Grace Gao <52978759+grac3gao@users.noreply.github.com> Date: Mon, 13 Jul 2020 18:04:18 -0700 Subject: [PATCH] Update some UTs (#1442) * update UT * update UT * update UT --- .../v1/cloudstoragesource_validation_test.go | 30 +++++++++--- .../cloudauditlogssource_validation_test.go | 43 +++++++++++------ .../cloudbuildsource_validation_test.go | 36 ++++++++++----- .../cloudpubsubsource_validation_test.go | 33 +++++++++---- .../cloudschedulersource_validation_test.go | 32 ++++++++++--- .../cloudstoragesource_validation_test.go | 32 ++++++++++--- .../cloudauditlogssource_validation_test.go | 46 +++++++++++++------ .../cloudbuildsource_validation_test.go | 30 ++++++++---- .../cloudpubsubsource_validation_test.go | 39 +++++++++++----- .../cloudschedulersource_validation_test.go | 32 ++++++++++--- .../cloudstoragesource_validation_test.go | 32 ++++++++++--- 11 files changed, 287 insertions(+), 98 deletions(-) diff --git a/pkg/apis/events/v1/cloudstoragesource_validation_test.go b/pkg/apis/events/v1/cloudstoragesource_validation_test.go index ad09c110c0..7f523c5a0f 100644 --- a/pkg/apis/events/v1/cloudstoragesource_validation_test.go +++ b/pkg/apis/events/v1/cloudstoragesource_validation_test.go @@ -70,6 +70,25 @@ var ( }, } + storageSourceSpecWithKSA = CloudStorageSourceSpec{ + Bucket: "my-test-bucket", + PubSubSpec: gcpduckv1.PubSubSpec{ + SourceSpec: duckv1.SourceSpec{ + Sink: duckv1.Destination{ + Ref: &duckv1.KReference{ + APIVersion: "foo", + Kind: "bar", + Namespace: "baz", + Name: "qux", + }, + }, + }, + IdentitySpec: gcpduckv1.IdentitySpec{ + ServiceAccountName: "old-service-account", + }, + }, + } + // Bucket, Sink, Secret, Event Type and Project and ObjectNamePrefix storageSourceSpec = CloudStorageSourceSpec{ Bucket: "my-test-bucket", @@ -435,17 +454,16 @@ func TestCheckImmutableFields(t *testing.T) { allowed: false, }, "ServiceAccountName changed": { - orig: &storageSourceSpec, + orig: &storageSourceSpecWithKSA, updated: CloudStorageSourceSpec{ - Bucket: storageSourceSpec.Bucket, - EventTypes: storageSourceSpec.EventTypes, - ObjectNamePrefix: storageSourceSpec.ObjectNamePrefix, + Bucket: storageSourceSpecWithKSA.Bucket, + EventTypes: storageSourceSpecWithKSA.EventTypes, + ObjectNamePrefix: storageSourceSpecWithKSA.ObjectNamePrefix, PubSubSpec: gcpduckv1.PubSubSpec{ IdentitySpec: gcpduckv1.IdentitySpec{ ServiceAccountName: "new-service-account", }, - SourceSpec: storageSourceSpec.SourceSpec, - Secret: storageSourceSpec.Secret, + SourceSpec: storageSourceSpecWithKSA.SourceSpec, }, }, allowed: false, diff --git a/pkg/apis/events/v1alpha1/cloudauditlogssource_validation_test.go b/pkg/apis/events/v1alpha1/cloudauditlogssource_validation_test.go index 3c0901ee9a..4dd822e533 100644 --- a/pkg/apis/events/v1alpha1/cloudauditlogssource_validation_test.go +++ b/pkg/apis/events/v1alpha1/cloudauditlogssource_validation_test.go @@ -20,10 +20,9 @@ import ( "context" "testing" - gcpauthtesthelper "github.com/google/knative-gcp/pkg/apis/configs/gcpauth/testhelper" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + gcpauthtesthelper "github.com/google/knative-gcp/pkg/apis/configs/gcpauth/testhelper" "github.com/google/knative-gcp/pkg/apis/duck" duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" metadatatesting "github.com/google/knative-gcp/pkg/gclient/metadata/testing" @@ -57,6 +56,29 @@ var ( Project: "my-eventing-project", }, } + + auditLogsSourceSpecWithKSA = CloudAuditLogsSourceSpec{ + ServiceName: "foo", + MethodName: "bar", + ResourceName: "baz", + PubSubSpec: duckv1alpha1.PubSubSpec{ + SourceSpec: duckv1.SourceSpec{ + Sink: duckv1.Destination{ + Ref: &duckv1.KReference{ + APIVersion: "foo", + Kind: "bar", + Namespace: "baz", + Name: "qux", + }, + }, + }, + IdentitySpec: duckv1alpha1.IdentitySpec{ + ServiceAccountName: "old-service-account", + }, + Project: "my-eventing-project", + }, + } + validServiceAccountName = "test" invalidServiceAccountName = "@test" ) @@ -220,25 +242,20 @@ func TestCloudAuditLogsSourceCheckImmutableFields(t *testing.T) { allowed: false, }, "ServiceAccount changed": { - orig: &auditLogsSourceSpec, + orig: &auditLogsSourceSpecWithKSA, updated: CloudAuditLogsSourceSpec{ PubSubSpec: duckv1alpha1.PubSubSpec{ IdentitySpec: duckv1alpha1.IdentitySpec{ ServiceAccountName: "new-service-account", }, - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: auditLogsSourceSpec.PubSubSpec.Secret.Name, - }, - Key: auditLogsSourceSpec.PubSubSpec.Secret.Key, - }, SourceSpec: duckv1.SourceSpec{ - Sink: auditLogsSourceSpec.PubSubSpec.Sink, + Sink: auditLogsSourceSpecWithKSA.PubSubSpec.Sink, }, + Project: auditLogsSourceSpecWithKSA.Project, }, - MethodName: auditLogsSourceSpec.MethodName, - ResourceName: auditLogsSourceSpec.ResourceName, - ServiceName: auditLogsSourceSpec.ServiceName, + MethodName: auditLogsSourceSpecWithKSA.MethodName, + ResourceName: auditLogsSourceSpecWithKSA.ResourceName, + ServiceName: auditLogsSourceSpecWithKSA.ServiceName, }, allowed: false, }, diff --git a/pkg/apis/events/v1alpha1/cloudbuildsource_validation_test.go b/pkg/apis/events/v1alpha1/cloudbuildsource_validation_test.go index 2741d43364..a4e3382dd9 100644 --- a/pkg/apis/events/v1alpha1/cloudbuildsource_validation_test.go +++ b/pkg/apis/events/v1alpha1/cloudbuildsource_validation_test.go @@ -20,10 +20,10 @@ import ( "context" "testing" - gcpauthtesthelper "github.com/google/knative-gcp/pkg/apis/configs/gcpauth/testhelper" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + gcpauthtesthelper "github.com/google/knative-gcp/pkg/apis/configs/gcpauth/testhelper" + "github.com/google/knative-gcp/pkg/apis/duck" duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" metadatatesting "github.com/google/knative-gcp/pkg/gclient/metadata/testing" @@ -58,6 +58,25 @@ var ( }, Topic: ptr.String(topic), } + + buildSourceSpecWithKSA = CloudBuildSourceSpec{ + PubSubSpec: duckv1alpha1.PubSubSpec{ + SourceSpec: duckv1.SourceSpec{ + Sink: duckv1.Destination{ + Ref: &duckv1.KReference{ + APIVersion: "foo", + Kind: "bar", + Namespace: "baz", + Name: "qux", + }, + }, + }, + IdentitySpec: duckv1alpha1.IdentitySpec{ + ServiceAccountName: "old-service-account", + }, + Project: "my-eventing-project", + }, + } ) func TestCloudBuildSourceCheckValidationFields(t *testing.T) { @@ -283,23 +302,18 @@ func TestCloudBuildSourceCheckImmutableFields(t *testing.T) { allowed: false, }, "ServiceAccount changed": { - orig: &buildSourceSpec, + orig: &buildSourceSpecWithKSA, updated: CloudBuildSourceSpec{ PubSubSpec: duckv1alpha1.PubSubSpec{ IdentitySpec: duckv1alpha1.IdentitySpec{ ServiceAccountName: "new-service-account", }, - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: buildSourceSpec.Secret.Name, - }, - Key: buildSourceSpec.Secret.Key, - }, SourceSpec: duckv1.SourceSpec{ - Sink: buildSourceSpec.Sink, + Sink: buildSourceSpecWithKSA.Sink, }, + Project: buildSourceSpecWithKSA.Project, }, - Topic: buildSourceSpec.Topic, + Topic: buildSourceSpecWithKSA.Topic, }, allowed: false, }, diff --git a/pkg/apis/events/v1alpha1/cloudpubsubsource_validation_test.go b/pkg/apis/events/v1alpha1/cloudpubsubsource_validation_test.go index 13519e15dc..0fad41e6bf 100644 --- a/pkg/apis/events/v1alpha1/cloudpubsubsource_validation_test.go +++ b/pkg/apis/events/v1alpha1/cloudpubsubsource_validation_test.go @@ -55,6 +55,26 @@ var ( }, Topic: "pubsub-topic", } + + pubSubSourceSpecWithKSA = CloudPubSubSourceSpec{ + PubSubSpec: duckv1alpha1.PubSubSpec{ + IdentitySpec: duckv1alpha1.IdentitySpec{ + ServiceAccountName: "old-service-account", + }, + SourceSpec: duckv1.SourceSpec{ + Sink: duckv1.Destination{ + Ref: &duckv1.KReference{ + APIVersion: "foo", + Kind: "bar", + Namespace: "baz", + Name: "qux", + }, + }, + }, + Project: "my-eventing-project", + }, + Topic: "pubsub-topic", + } ) func TestCloudPubSubSourceCheckValidationFields(t *testing.T) { @@ -309,23 +329,18 @@ func TestCloudPubSubSourceCheckImmutableFields(t *testing.T) { allowed: false, }, "ServiceAccount changed": { - orig: &pubSubSourceSpec, + orig: &pubSubSourceSpecWithKSA, updated: CloudPubSubSourceSpec{ PubSubSpec: duckv1alpha1.PubSubSpec{ IdentitySpec: duckv1alpha1.IdentitySpec{ ServiceAccountName: "new-service-account", }, - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: pubSubSourceSpec.Secret.Name, - }, - Key: pubSubSourceSpec.Secret.Key, - }, SourceSpec: duckv1.SourceSpec{ - Sink: pubSubSourceSpec.Sink, + Sink: pubSubSourceSpecWithKSA.Sink, }, + Project: pubSubSourceSpecWithKSA.Project, }, - Topic: pubSubSourceSpec.Topic, + Topic: pubSubSourceSpecWithKSA.Topic, }, allowed: false, }, diff --git a/pkg/apis/events/v1alpha1/cloudschedulersource_validation_test.go b/pkg/apis/events/v1alpha1/cloudschedulersource_validation_test.go index ab10f113b3..cb59b3602a 100644 --- a/pkg/apis/events/v1alpha1/cloudschedulersource_validation_test.go +++ b/pkg/apis/events/v1alpha1/cloudschedulersource_validation_test.go @@ -75,6 +75,27 @@ var ( }, }, } + + schedulerWithKSA = CloudSchedulerSourceSpec{ + Location: "mylocation", + Schedule: "* * * * *", + Data: "mydata", + PubSubSpec: duckv1alpha1.PubSubSpec{ + SourceSpec: duckv1.SourceSpec{ + Sink: duckv1.Destination{ + Ref: &duckv1.KReference{ + APIVersion: "foo", + Kind: "bar", + Namespace: "baz", + Name: "qux", + }, + }, + }, + IdentitySpec: duckv1alpha1.IdentitySpec{ + ServiceAccountName: "old-service-account", + }, + }, + } ) func TestCloudSchedulerSourceValidationFields(t *testing.T) { @@ -436,17 +457,16 @@ func TestCloudSchedulerSourceSpecCheckImmutableFields(t *testing.T) { allowed: false, }, "ServiceAccount changed changed": { - orig: &schedulerWithSecret, + orig: &schedulerWithKSA, updated: CloudSchedulerSourceSpec{ - Location: schedulerWithSecret.Location, - Schedule: schedulerWithSecret.Schedule, - Data: schedulerWithSecret.Data, + Location: schedulerWithKSA.Location, + Schedule: schedulerWithKSA.Schedule, + Data: schedulerWithKSA.Data, PubSubSpec: duckv1alpha1.PubSubSpec{ IdentitySpec: duckv1alpha1.IdentitySpec{ ServiceAccountName: "new-service-account", }, - SourceSpec: schedulerWithSecret.SourceSpec, - Secret: schedulerWithSecret.Secret, + SourceSpec: schedulerWithKSA.SourceSpec, }, }, allowed: false, diff --git a/pkg/apis/events/v1alpha1/cloudstoragesource_validation_test.go b/pkg/apis/events/v1alpha1/cloudstoragesource_validation_test.go index 741bb5de69..e6b8b33555 100644 --- a/pkg/apis/events/v1alpha1/cloudstoragesource_validation_test.go +++ b/pkg/apis/events/v1alpha1/cloudstoragesource_validation_test.go @@ -74,6 +74,25 @@ var ( }, } + storageSourceSpecWithKSA = CloudStorageSourceSpec{ + Bucket: "my-test-bucket", + PubSubSpec: duckv1alpha1.PubSubSpec{ + SourceSpec: duckv1.SourceSpec{ + Sink: duckv1.Destination{ + Ref: &duckv1.KReference{ + APIVersion: "foo", + Kind: "bar", + Namespace: "baz", + Name: "qux", + }, + }, + }, + IdentitySpec: duckv1alpha1.IdentitySpec{ + ServiceAccountName: "old-service-account", + }, + }, + } + // Bucket, Sink, Secret, Event Type and Project, ObjectNamePrefix and PayloadFormat storageSourceSpec = CloudStorageSourceSpec{ Bucket: "my-test-bucket", @@ -465,18 +484,17 @@ func TestCheckImmutableFields(t *testing.T) { allowed: false, }, "ServiceAccountName changed": { - orig: &storageSourceSpec, + orig: &storageSourceSpecWithKSA, updated: CloudStorageSourceSpec{ - Bucket: storageSourceSpec.Bucket, - EventTypes: storageSourceSpec.EventTypes, - ObjectNamePrefix: storageSourceSpec.ObjectNamePrefix, - PayloadFormat: storageSourceSpec.PayloadFormat, + Bucket: storageSourceSpecWithKSA.Bucket, + EventTypes: storageSourceSpecWithKSA.EventTypes, + ObjectNamePrefix: storageSourceSpecWithKSA.ObjectNamePrefix, + PayloadFormat: storageSourceSpecWithKSA.PayloadFormat, PubSubSpec: duckv1alpha1.PubSubSpec{ IdentitySpec: duckv1alpha1.IdentitySpec{ ServiceAccountName: "new-service-account", }, - SourceSpec: storageSourceSpec.SourceSpec, - Secret: storageSourceSpec.Secret, + SourceSpec: storageSourceSpecWithKSA.SourceSpec, }, }, allowed: false, diff --git a/pkg/apis/events/v1beta1/cloudauditlogssource_validation_test.go b/pkg/apis/events/v1beta1/cloudauditlogssource_validation_test.go index dc194c134a..3c941d51c6 100644 --- a/pkg/apis/events/v1beta1/cloudauditlogssource_validation_test.go +++ b/pkg/apis/events/v1beta1/cloudauditlogssource_validation_test.go @@ -20,10 +20,11 @@ import ( "context" "testing" - gcpauthtesthelper "github.com/google/knative-gcp/pkg/apis/configs/gcpauth/testhelper" - duckv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" corev1 "k8s.io/api/core/v1" duckv1 "knative.dev/pkg/apis/duck/v1" + + gcpauthtesthelper "github.com/google/knative-gcp/pkg/apis/configs/gcpauth/testhelper" + duckv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" ) var ( @@ -51,6 +52,30 @@ var ( Project: "my-eventing-project", }, } + + auditLogsSourceSpecWithKSA = CloudAuditLogsSourceSpec{ + ServiceName: "foo", + MethodName: "bar", + ResourceName: "baz", + PubSubSpec: duckv1beta1.PubSubSpec{ + + SourceSpec: duckv1.SourceSpec{ + Sink: duckv1.Destination{ + Ref: &duckv1.KReference{ + APIVersion: "foo", + Kind: "bar", + Namespace: "baz", + Name: "qux", + }, + }, + }, + IdentitySpec: duckv1beta1.IdentitySpec{ + ServiceAccountName: "old-service-account", + }, + Project: "my-eventing-project", + }, + } + validServiceAccountName = "test" invalidServiceAccountName = "@test" ) @@ -203,25 +228,20 @@ func TestCloudAuditLogsSourceCheckImmutableFields(t *testing.T) { allowed: false, }, "ServiceAccount changed": { - orig: &auditLogsSourceSpec, + orig: &auditLogsSourceSpecWithKSA, updated: CloudAuditLogsSourceSpec{ PubSubSpec: duckv1beta1.PubSubSpec{ IdentitySpec: duckv1beta1.IdentitySpec{ ServiceAccountName: "new-service-account", }, - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: auditLogsSourceSpec.PubSubSpec.Secret.Name, - }, - Key: auditLogsSourceSpec.PubSubSpec.Secret.Key, - }, SourceSpec: duckv1.SourceSpec{ - Sink: auditLogsSourceSpec.PubSubSpec.Sink, + Sink: auditLogsSourceSpecWithKSA.PubSubSpec.Sink, }, + Project: auditLogsSourceSpecWithKSA.Project, }, - MethodName: auditLogsSourceSpec.MethodName, - ResourceName: auditLogsSourceSpec.ResourceName, - ServiceName: auditLogsSourceSpec.ServiceName, + MethodName: auditLogsSourceSpecWithKSA.MethodName, + ResourceName: auditLogsSourceSpecWithKSA.ResourceName, + ServiceName: auditLogsSourceSpecWithKSA.ServiceName, }, allowed: false, }, diff --git a/pkg/apis/events/v1beta1/cloudbuildsource_validation_test.go b/pkg/apis/events/v1beta1/cloudbuildsource_validation_test.go index 8c03499dc7..ea56fb1ab7 100644 --- a/pkg/apis/events/v1beta1/cloudbuildsource_validation_test.go +++ b/pkg/apis/events/v1beta1/cloudbuildsource_validation_test.go @@ -54,6 +54,25 @@ var ( Project: "my-eventing-project", }, } + + buildSourceSpecWithKSA = CloudBuildSourceSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ + SourceSpec: duckv1.SourceSpec{ + Sink: duckv1.Destination{ + Ref: &duckv1.KReference{ + APIVersion: "foo", + Kind: "bar", + Namespace: "baz", + Name: "qux", + }, + }, + }, + IdentitySpec: duckv1beta1.IdentitySpec{ + ServiceAccountName: "old-service-account", + }, + Project: "my-eventing-project", + }, + } ) func TestCloudBuildSourceCheckValidationFields(t *testing.T) { @@ -260,21 +279,16 @@ func TestCloudBuildSourceCheckImmutableFields(t *testing.T) { allowed: false, }, "ServiceAccount changed": { - orig: &buildSourceSpec, + orig: &buildSourceSpecWithKSA, updated: CloudBuildSourceSpec{ PubSubSpec: duckv1beta1.PubSubSpec{ IdentitySpec: duckv1beta1.IdentitySpec{ ServiceAccountName: "new-service-account", }, - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: buildSourceSpec.Secret.Name, - }, - Key: buildSourceSpec.Secret.Key, - }, SourceSpec: duckv1.SourceSpec{ - Sink: buildSourceSpec.Sink, + Sink: buildSourceSpecWithKSA.Sink, }, + Project: buildSourceSpecWithKSA.Project, }, }, allowed: false, diff --git a/pkg/apis/events/v1beta1/cloudpubsubsource_validation_test.go b/pkg/apis/events/v1beta1/cloudpubsubsource_validation_test.go index d4d3cd9e47..21fde89c2a 100644 --- a/pkg/apis/events/v1beta1/cloudpubsubsource_validation_test.go +++ b/pkg/apis/events/v1beta1/cloudpubsubsource_validation_test.go @@ -20,13 +20,13 @@ import ( "context" "testing" - gcpauthtesthelper "github.com/google/knative-gcp/pkg/apis/configs/gcpauth/testhelper" - - duckv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" corev1 "k8s.io/api/core/v1" "knative.dev/pkg/apis" duckv1 "knative.dev/pkg/apis/duck/v1" "knative.dev/pkg/ptr" + + gcpauthtesthelper "github.com/google/knative-gcp/pkg/apis/configs/gcpauth/testhelper" + duckv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" ) var ( @@ -52,6 +52,26 @@ var ( }, Topic: "pubsub-topic", } + + pubSubSourceSpecWithKSA = CloudPubSubSourceSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ + IdentitySpec: duckv1beta1.IdentitySpec{ + ServiceAccountName: "old-service-account", + }, + SourceSpec: duckv1.SourceSpec{ + Sink: duckv1.Destination{ + Ref: &duckv1.KReference{ + APIVersion: "foo", + Kind: "bar", + Namespace: "baz", + Name: "qux", + }, + }, + }, + Project: "my-eventing-project", + }, + Topic: "pubsub-topic", + } ) func TestCloudPubSubSourceCheckValidationFields(t *testing.T) { @@ -290,23 +310,18 @@ func TestCloudPubSubSourceCheckImmutableFields(t *testing.T) { allowed: false, }, "ServiceAccount changed": { - orig: &pubSubSourceSpec, + orig: &pubSubSourceSpecWithKSA, updated: CloudPubSubSourceSpec{ PubSubSpec: duckv1beta1.PubSubSpec{ IdentitySpec: duckv1beta1.IdentitySpec{ ServiceAccountName: "new-service-account", }, - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: pubSubSourceSpec.Secret.Name, - }, - Key: pubSubSourceSpec.Secret.Key, - }, SourceSpec: duckv1.SourceSpec{ - Sink: pubSubSourceSpec.Sink, + Sink: pubSubSourceSpecWithKSA.Sink, }, + Project: pubSubSourceSpecWithKSA.Project, }, - Topic: pubSubSourceSpec.Topic, + Topic: pubSubSourceSpecWithKSA.Topic, }, allowed: false, }, diff --git a/pkg/apis/events/v1beta1/cloudschedulersource_validation_test.go b/pkg/apis/events/v1beta1/cloudschedulersource_validation_test.go index ede9e10409..c412dc1870 100644 --- a/pkg/apis/events/v1beta1/cloudschedulersource_validation_test.go +++ b/pkg/apis/events/v1beta1/cloudschedulersource_validation_test.go @@ -71,6 +71,27 @@ var ( }, }, } + + schedulerWithKSA = CloudSchedulerSourceSpec{ + Location: "mylocation", + Schedule: "* * * * *", + Data: "mydata", + PubSubSpec: duckv1beta1.PubSubSpec{ + SourceSpec: duckv1.SourceSpec{ + Sink: duckv1.Destination{ + Ref: &duckv1.KReference{ + APIVersion: "foo", + Kind: "bar", + Namespace: "baz", + Name: "qux", + }, + }, + }, + IdentitySpec: duckv1beta1.IdentitySpec{ + ServiceAccountName: "old-service-account", + }, + }, + } ) func TestCloudSchedulerSourceValidationFields(t *testing.T) { @@ -421,17 +442,16 @@ func TestCloudSchedulerSourceSpecCheckImmutableFields(t *testing.T) { allowed: false, }, "ServiceAccount changed changed": { - orig: &schedulerWithSecret, + orig: &schedulerWithKSA, updated: CloudSchedulerSourceSpec{ - Location: schedulerWithSecret.Location, - Schedule: schedulerWithSecret.Schedule, - Data: schedulerWithSecret.Data, + Location: schedulerWithKSA.Location, + Schedule: schedulerWithKSA.Schedule, + Data: schedulerWithKSA.Data, PubSubSpec: duckv1beta1.PubSubSpec{ IdentitySpec: duckv1beta1.IdentitySpec{ ServiceAccountName: "new-service-account", }, - SourceSpec: schedulerWithSecret.SourceSpec, - Secret: schedulerWithSecret.Secret, + SourceSpec: schedulerWithKSA.SourceSpec, }, }, allowed: false, diff --git a/pkg/apis/events/v1beta1/cloudstoragesource_validation_test.go b/pkg/apis/events/v1beta1/cloudstoragesource_validation_test.go index 305746ca9e..75080e4bd2 100644 --- a/pkg/apis/events/v1beta1/cloudstoragesource_validation_test.go +++ b/pkg/apis/events/v1beta1/cloudstoragesource_validation_test.go @@ -71,6 +71,25 @@ var ( }, } + storageSourceSpecWithKSA = CloudStorageSourceSpec{ + Bucket: "my-test-bucket", + PubSubSpec: duckv1beta1.PubSubSpec{ + SourceSpec: duckv1.SourceSpec{ + Sink: duckv1.Destination{ + Ref: &duckv1.KReference{ + APIVersion: "foo", + Kind: "bar", + Namespace: "baz", + Name: "qux", + }, + }, + }, + IdentitySpec: duckv1beta1.IdentitySpec{ + ServiceAccountName: "old-service-account", + }, + }, + } + // Bucket, Sink, Secret, Event Type and Project, ObjectNamePrefix and PayloadFormat storageSourceSpec = CloudStorageSourceSpec{ Bucket: "my-test-bucket", @@ -451,18 +470,17 @@ func TestCheckImmutableFields(t *testing.T) { allowed: false, }, "ServiceAccountName changed": { - orig: &storageSourceSpec, + orig: &storageSourceSpecWithKSA, updated: CloudStorageSourceSpec{ - Bucket: storageSourceSpec.Bucket, - EventTypes: storageSourceSpec.EventTypes, - ObjectNamePrefix: storageSourceSpec.ObjectNamePrefix, - PayloadFormat: storageSourceSpec.PayloadFormat, + Bucket: storageSourceSpecWithKSA.Bucket, + EventTypes: storageSourceSpecWithKSA.EventTypes, + ObjectNamePrefix: storageSourceSpecWithKSA.ObjectNamePrefix, + PayloadFormat: storageSourceSpecWithKSA.PayloadFormat, PubSubSpec: duckv1beta1.PubSubSpec{ IdentitySpec: duckv1beta1.IdentitySpec{ ServiceAccountName: "new-service-account", }, - SourceSpec: storageSourceSpec.SourceSpec, - Secret: storageSourceSpec.Secret, + SourceSpec: storageSourceSpecWithKSA.SourceSpec, }, }, allowed: false,