From 9c74693b5fb8ecea9319d7f5d73dce3dccb8e0a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20St=C3=A4bler?= Date: Tue, 26 Sep 2023 19:08:09 +0200 Subject: [PATCH] Fix unit test for Trigger status conditions --- .../eventing/v1/trigger_lifecycle_test.go | 55 +++++++++++++++---- 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/pkg/apis/eventing/v1/trigger_lifecycle_test.go b/pkg/apis/eventing/v1/trigger_lifecycle_test.go index f859c1c4a9b..baae05bf2c6 100644 --- a/pkg/apis/eventing/v1/trigger_lifecycle_test.go +++ b/pkg/apis/eventing/v1/trigger_lifecycle_test.go @@ -153,6 +153,9 @@ func TestTriggerInitializeConditions(t *testing.T) { }, { Type: TriggerConditionDependency, Status: corev1.ConditionUnknown, + }, { + Type: TriggerConditionOIDCServiceAccountResolved, + Status: corev1.ConditionUnknown, }, { Type: TriggerConditionReady, Status: corev1.ConditionUnknown, @@ -187,17 +190,19 @@ func TestTriggerInitializeConditions(t *testing.T) { }, { Type: TriggerConditionDependency, Status: corev1.ConditionUnknown, + }, { + Type: TriggerConditionOIDCServiceAccountResolved, + Status: corev1.ConditionUnknown, + }, { + Type: TriggerConditionReady, + Status: corev1.ConditionUnknown, + }, { + Type: TriggerConditionSubscriberResolved, + Status: corev1.ConditionUnknown, + }, { + Type: TriggerConditionSubscribed, + Status: corev1.ConditionUnknown, }, - { - Type: TriggerConditionReady, - Status: corev1.ConditionUnknown, - }, { - Type: TriggerConditionSubscriberResolved, - Status: corev1.ConditionUnknown, - }, { - Type: TriggerConditionSubscribed, - Status: corev1.ConditionUnknown, - }, }, }, }, @@ -222,6 +227,9 @@ func TestTriggerInitializeConditions(t *testing.T) { }, { Type: TriggerConditionDependency, Status: corev1.ConditionUnknown, + }, { + Type: TriggerConditionOIDCServiceAccountResolved, + Status: corev1.ConditionUnknown, }, { Type: TriggerConditionReady, Status: corev1.ConditionUnknown, @@ -257,6 +265,7 @@ func TestTriggerConditionStatus(t *testing.T) { subscriberResolvedStatus bool dlsResolvedStatus bool dependencyAnnotationExists bool + oidcServiceAccountStatus bool dependencyStatus corev1.ConditionStatus wantConditionStatus corev1.ConditionStatus }{{ @@ -267,6 +276,7 @@ func TestTriggerConditionStatus(t *testing.T) { subscriptionCondition: TestHelper.ReadySubscriptionCondition(), subscriberResolvedStatus: true, dlsResolvedStatus: true, + oidcServiceAccountStatus: true, dependencyAnnotationExists: false, wantConditionStatus: corev1.ConditionTrue, }, { @@ -277,6 +287,7 @@ func TestTriggerConditionStatus(t *testing.T) { subscriptionCondition: TestHelper.ReadySubscriptionCondition(), subscriberResolvedStatus: true, dlsResolvedStatus: true, + oidcServiceAccountStatus: true, dependencyAnnotationExists: false, wantConditionStatus: corev1.ConditionUnknown, }, { @@ -286,6 +297,7 @@ func TestTriggerConditionStatus(t *testing.T) { markVirtualServiceExists: true, subscriptionCondition: TestHelper.ReadySubscriptionCondition(), subscriberResolvedStatus: true, + oidcServiceAccountStatus: true, dependencyAnnotationExists: false, wantConditionStatus: corev1.ConditionFalse, }, { @@ -295,6 +307,7 @@ func TestTriggerConditionStatus(t *testing.T) { markVirtualServiceExists: true, subscriptionCondition: TestHelper.FalseSubscriptionCondition(), subscriberResolvedStatus: true, + oidcServiceAccountStatus: true, dependencyAnnotationExists: false, wantConditionStatus: corev1.ConditionFalse, }, { @@ -304,6 +317,7 @@ func TestTriggerConditionStatus(t *testing.T) { markVirtualServiceExists: true, subscriptionCondition: TestHelper.ReadySubscriptionCondition(), subscriberResolvedStatus: false, + oidcServiceAccountStatus: true, dependencyAnnotationExists: true, dependencyStatus: corev1.ConditionTrue, wantConditionStatus: corev1.ConditionFalse, @@ -316,6 +330,7 @@ func TestTriggerConditionStatus(t *testing.T) { subscriberResolvedStatus: true, dependencyAnnotationExists: true, dlsResolvedStatus: true, + oidcServiceAccountStatus: true, dependencyStatus: corev1.ConditionUnknown, wantConditionStatus: corev1.ConditionUnknown, }, { @@ -326,6 +341,7 @@ func TestTriggerConditionStatus(t *testing.T) { subscriptionCondition: TestHelper.ReadySubscriptionCondition(), subscriberResolvedStatus: true, dependencyAnnotationExists: true, + oidcServiceAccountStatus: true, dependencyStatus: corev1.ConditionFalse, wantConditionStatus: corev1.ConditionFalse, }, { @@ -335,6 +351,7 @@ func TestTriggerConditionStatus(t *testing.T) { markVirtualServiceExists: false, subscriptionCondition: TestHelper.FalseSubscriptionCondition(), subscriberResolvedStatus: false, + oidcServiceAccountStatus: false, dependencyAnnotationExists: true, dependencyStatus: corev1.ConditionFalse, wantConditionStatus: corev1.ConditionFalse, @@ -346,9 +363,22 @@ func TestTriggerConditionStatus(t *testing.T) { subscriptionCondition: TestHelper.ReadySubscriptionCondition(), subscriberResolvedStatus: true, dependencyAnnotationExists: true, + oidcServiceAccountStatus: true, dlsResolvedStatus: false, wantConditionStatus: corev1.ConditionFalse, + }, { + name: "oidc status false", + brokerStatus: TestHelper.ReadyBrokerStatus(), + markKubernetesServiceExists: true, + markVirtualServiceExists: true, + subscriptionCondition: TestHelper.ReadySubscriptionCondition(), + subscriberResolvedStatus: true, + dlsResolvedStatus: true, + oidcServiceAccountStatus: false, + dependencyAnnotationExists: false, + wantConditionStatus: corev1.ConditionFalse, }} + for _, test := range tests { t.Run(test.name, func(t *testing.T) { ts := &TriggerStatus{} @@ -379,6 +409,11 @@ func TestTriggerConditionStatus(t *testing.T) { ts.MarkDependencyFailed("The status of dependency is false", "The status of dependency is unknown: nil") } } + if test.oidcServiceAccountStatus { + ts.MarkOIDCServiceAccountResolvedSucceeded() + } else { + ts.MarkOIDCServiceAccountResolvedFailed("Unable to ...", "") + } got := ts.GetTopLevelCondition().Status if test.wantConditionStatus != got { t.Errorf("unexpected readiness: want %v, got %v", test.wantConditionStatus, got)