Skip to content

Commit

Permalink
Fix unit test for Trigger status conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
creydr committed Sep 26, 2023
1 parent e4fefda commit 9c74693
Showing 1 changed file with 45 additions and 10 deletions.
55 changes: 45 additions & 10 deletions pkg/apis/eventing/v1/trigger_lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ func TestTriggerInitializeConditions(t *testing.T) {
}, {
Type: TriggerConditionDependency,
Status: corev1.ConditionUnknown,
}, {
Type: TriggerConditionOIDCServiceAccountResolved,
Status: corev1.ConditionUnknown,
}, {
Type: TriggerConditionReady,
Status: corev1.ConditionUnknown,
Expand Down Expand Up @@ -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,
},
},
},
},
Expand All @@ -222,6 +227,9 @@ func TestTriggerInitializeConditions(t *testing.T) {
}, {
Type: TriggerConditionDependency,
Status: corev1.ConditionUnknown,
}, {
Type: TriggerConditionOIDCServiceAccountResolved,
Status: corev1.ConditionUnknown,
}, {
Type: TriggerConditionReady,
Status: corev1.ConditionUnknown,
Expand Down Expand Up @@ -257,6 +265,7 @@ func TestTriggerConditionStatus(t *testing.T) {
subscriberResolvedStatus bool
dlsResolvedStatus bool
dependencyAnnotationExists bool
oidcServiceAccountStatus bool
dependencyStatus corev1.ConditionStatus
wantConditionStatus corev1.ConditionStatus
}{{
Expand All @@ -267,6 +276,7 @@ func TestTriggerConditionStatus(t *testing.T) {
subscriptionCondition: TestHelper.ReadySubscriptionCondition(),
subscriberResolvedStatus: true,
dlsResolvedStatus: true,
oidcServiceAccountStatus: true,
dependencyAnnotationExists: false,
wantConditionStatus: corev1.ConditionTrue,
}, {
Expand All @@ -277,6 +287,7 @@ func TestTriggerConditionStatus(t *testing.T) {
subscriptionCondition: TestHelper.ReadySubscriptionCondition(),
subscriberResolvedStatus: true,
dlsResolvedStatus: true,
oidcServiceAccountStatus: true,
dependencyAnnotationExists: false,
wantConditionStatus: corev1.ConditionUnknown,
}, {
Expand All @@ -286,6 +297,7 @@ func TestTriggerConditionStatus(t *testing.T) {
markVirtualServiceExists: true,
subscriptionCondition: TestHelper.ReadySubscriptionCondition(),
subscriberResolvedStatus: true,
oidcServiceAccountStatus: true,
dependencyAnnotationExists: false,
wantConditionStatus: corev1.ConditionFalse,
}, {
Expand All @@ -295,6 +307,7 @@ func TestTriggerConditionStatus(t *testing.T) {
markVirtualServiceExists: true,
subscriptionCondition: TestHelper.FalseSubscriptionCondition(),
subscriberResolvedStatus: true,
oidcServiceAccountStatus: true,
dependencyAnnotationExists: false,
wantConditionStatus: corev1.ConditionFalse,
}, {
Expand All @@ -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,
Expand All @@ -316,6 +330,7 @@ func TestTriggerConditionStatus(t *testing.T) {
subscriberResolvedStatus: true,
dependencyAnnotationExists: true,
dlsResolvedStatus: true,
oidcServiceAccountStatus: true,
dependencyStatus: corev1.ConditionUnknown,
wantConditionStatus: corev1.ConditionUnknown,
}, {
Expand All @@ -326,6 +341,7 @@ func TestTriggerConditionStatus(t *testing.T) {
subscriptionCondition: TestHelper.ReadySubscriptionCondition(),
subscriberResolvedStatus: true,
dependencyAnnotationExists: true,
oidcServiceAccountStatus: true,
dependencyStatus: corev1.ConditionFalse,
wantConditionStatus: corev1.ConditionFalse,
}, {
Expand All @@ -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,
Expand All @@ -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{}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9c74693

Please sign in to comment.