Skip to content

Commit fe72c3c

Browse files
committed
fix: add more unit tests to test out remove steps from the sequence
Signed-off-by: Leo Li <[email protected]>
1 parent 78a8b0a commit fe72c3c

File tree

1 file changed

+295
-1
lines changed

1 file changed

+295
-1
lines changed

pkg/reconciler/sequence/sequence_test.go

+295-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"fmt"
2222
"testing"
2323

24-
eventingv1alpha1 "knative.dev/eventing/pkg/apis/eventing/v1alpha1"
2524
"knative.dev/eventing/pkg/apis/feature"
2625

2726
corev1 "k8s.io/api/core/v1"
@@ -30,6 +29,7 @@ import (
3029
"k8s.io/apimachinery/pkg/runtime"
3130
"k8s.io/apimachinery/pkg/types"
3231
clientgotesting "k8s.io/client-go/testing"
32+
eventingv1alpha1 "knative.dev/eventing/pkg/apis/eventing/v1alpha1"
3333

3434
v1 "knative.dev/eventing/pkg/apis/flows/v1"
3535
messagingv1 "knative.dev/eventing/pkg/apis/messaging/v1"
@@ -2262,6 +2262,300 @@ func TestAllCases(t *testing.T) {
22622262
})),
22632263
}},
22642264
},
2265+
{
2266+
Name: "sequenceupdate-remove-step with 3 steps with AuthZ enabled, and sequence doesn't have event policy",
2267+
Key: pKey,
2268+
Objects: []runtime.Object{
2269+
NewSequence(sequenceName, testNS,
2270+
WithInitSequenceConditions,
2271+
WithSequenceChannelTemplateSpec(imc),
2272+
WithSequenceSteps([]v1.SequenceStep{
2273+
{Destination: createDestination(0)},
2274+
{Destination: createDestination(1)}})),
2275+
createChannel(sequenceName, 0),
2276+
createChannel(sequenceName, 1),
2277+
createChannel(sequenceName, 2),
2278+
resources.NewSubscription(0, NewSequence(sequenceName, testNS,
2279+
WithSequenceChannelTemplateSpec(imc),
2280+
WithSequenceSteps([]v1.SequenceStep{
2281+
{Destination: createDestination(0)},
2282+
{Destination: createDestination(1)},
2283+
{Destination: createDestination(2)},
2284+
}))),
2285+
resources.NewSubscription(1, NewSequence(sequenceName, testNS,
2286+
WithSequenceChannelTemplateSpec(imc),
2287+
WithSequenceSteps([]v1.SequenceStep{
2288+
{Destination: createDestination(0)},
2289+
{Destination: createDestination(1)},
2290+
{Destination: createDestination(2)},
2291+
}))),
2292+
resources.NewSubscription(2, NewSequence(sequenceName, testNS,
2293+
WithSequenceChannelTemplateSpec(imc),
2294+
WithSequenceSteps([]v1.SequenceStep{
2295+
{Destination: createDestination(0)},
2296+
{Destination: createDestination(1)},
2297+
{Destination: createDestination(2)},
2298+
}))),
2299+
// Making the event policy for the sequence:
2300+
makeEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 1), 1),
2301+
makeEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 2), 2),
2302+
},
2303+
WantErr: false,
2304+
Ctx: feature.ToContext(context.Background(), feature.Flags{
2305+
feature.OIDCAuthentication: feature.Enabled,
2306+
feature.AuthorizationDefaultMode: feature.AuthorizationAllowSameNamespace,
2307+
}),
2308+
WantDeletes: []clientgotesting.DeleteActionImpl{
2309+
{
2310+
ActionImpl: clientgotesting.ActionImpl{
2311+
Namespace: testNS,
2312+
Resource: v1.SchemeGroupVersion.WithResource("subscriptions"),
2313+
},
2314+
Name: resources.SequenceChannelName(sequenceName, 2),
2315+
}, {
2316+
ActionImpl: clientgotesting.ActionImpl{
2317+
Namespace: testNS,
2318+
Resource: v1.SchemeGroupVersion.WithResource("inmemorychannels"),
2319+
},
2320+
Name: resources.SequenceChannelName(sequenceName, 2),
2321+
},
2322+
{
2323+
ActionImpl: clientgotesting.ActionImpl{
2324+
Namespace: testNS,
2325+
Resource: v1.SchemeGroupVersion.WithResource("eventpolicies"),
2326+
},
2327+
Name: resources.SequenceEventPolicyName(sequenceName, resources.SequenceChannelName(sequenceName, 2)),
2328+
},
2329+
},
2330+
WantUpdates: []clientgotesting.UpdateActionImpl{{
2331+
ActionImpl: clientgotesting.ActionImpl{
2332+
Namespace: testNS,
2333+
Resource: v1.SchemeGroupVersion.WithResource("subscriptions"),
2334+
},
2335+
Object: resources.NewSubscription(1, NewSequence(sequenceName, testNS,
2336+
WithSequenceChannelTemplateSpec(imc),
2337+
WithSequenceSteps([]v1.SequenceStep{
2338+
{Destination: createDestination(0)},
2339+
{Destination: createDestination(1)}},
2340+
))),
2341+
}},
2342+
WantStatusUpdates: []clientgotesting.UpdateActionImpl{{
2343+
Object: NewSequence(sequenceName, testNS,
2344+
WithInitSequenceConditions,
2345+
WithSequenceChannelTemplateSpec(imc),
2346+
WithSequenceSteps([]v1.SequenceStep{
2347+
{Destination: createDestination(0)},
2348+
{Destination: createDestination(1)}}),
2349+
WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"),
2350+
WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"),
2351+
WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"),
2352+
WithSequenceEventPoliciesReadyBecauseNoPolicyAndOIDCEnabled(),
2353+
WithSequenceChannelStatuses([]v1.SequenceChannelStatus{
2354+
{
2355+
Channel: corev1.ObjectReference{
2356+
APIVersion: "messaging.knative.dev/v1",
2357+
Kind: "InMemoryChannel",
2358+
Name: resources.SequenceChannelName(sequenceName, 0),
2359+
Namespace: testNS,
2360+
},
2361+
ReadyCondition: apis.Condition{
2362+
Type: apis.ConditionReady,
2363+
Status: corev1.ConditionUnknown,
2364+
Reason: "NoReady",
2365+
Message: "Channel does not have Ready condition",
2366+
},
2367+
},
2368+
{
2369+
Channel: corev1.ObjectReference{
2370+
APIVersion: "messaging.knative.dev/v1",
2371+
Kind: "InMemoryChannel",
2372+
Name: resources.SequenceChannelName(sequenceName, 1),
2373+
Namespace: testNS,
2374+
},
2375+
ReadyCondition: apis.Condition{
2376+
Type: apis.ConditionReady,
2377+
Status: corev1.ConditionUnknown,
2378+
Reason: "NoReady",
2379+
Message: "Channel does not have Ready condition",
2380+
},
2381+
},
2382+
}),
2383+
WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{
2384+
{
2385+
Subscription: corev1.ObjectReference{
2386+
APIVersion: "messaging.knative.dev/v1",
2387+
Kind: "Subscription",
2388+
Name: resources.SequenceSubscriptionName(sequenceName, 0),
2389+
Namespace: testNS,
2390+
},
2391+
ReadyCondition: apis.Condition{
2392+
Type: apis.ConditionReady,
2393+
Status: corev1.ConditionUnknown,
2394+
Reason: "NoReady",
2395+
Message: "Subscription does not have Ready condition",
2396+
},
2397+
},
2398+
{
2399+
Subscription: corev1.ObjectReference{
2400+
APIVersion: "messaging.knative.dev/v1",
2401+
Kind: "Subscription",
2402+
Name: resources.SequenceSubscriptionName(sequenceName, 1),
2403+
Namespace: testNS,
2404+
},
2405+
ReadyCondition: apis.Condition{
2406+
Type: apis.ConditionReady,
2407+
Status: corev1.ConditionUnknown,
2408+
Reason: "NoReady",
2409+
Message: "Subscription does not have Ready condition",
2410+
},
2411+
},
2412+
})),
2413+
}},
2414+
},
2415+
{
2416+
Name: "sequenceupdate-remove-step with 2 steps with AuthZ enabled, and sequence doesn't have event policy",
2417+
Key: pKey,
2418+
Objects: []runtime.Object{
2419+
NewSequence(sequenceName, testNS,
2420+
WithInitSequenceConditions,
2421+
WithSequenceChannelTemplateSpec(imc),
2422+
WithSequenceSteps([]v1.SequenceStep{
2423+
{Destination: createDestination(0)},
2424+
})),
2425+
createChannel(sequenceName, 0),
2426+
createChannel(sequenceName, 1),
2427+
resources.NewSubscription(0, NewSequence(sequenceName, testNS,
2428+
WithSequenceChannelTemplateSpec(imc),
2429+
WithSequenceSteps([]v1.SequenceStep{
2430+
{Destination: createDestination(0)},
2431+
{Destination: createDestination(1)},
2432+
}))),
2433+
resources.NewSubscription(1, NewSequence(sequenceName, testNS,
2434+
WithSequenceChannelTemplateSpec(imc),
2435+
WithSequenceSteps([]v1.SequenceStep{
2436+
{Destination: createDestination(0)},
2437+
{Destination: createDestination(1)},
2438+
}))),
2439+
// Making the event policy for the sequence:
2440+
makeEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 1), 1),
2441+
},
2442+
WantErr: false,
2443+
Ctx: feature.ToContext(context.Background(), feature.Flags{
2444+
feature.OIDCAuthentication: feature.Enabled,
2445+
feature.AuthorizationDefaultMode: feature.AuthorizationAllowSameNamespace,
2446+
}),
2447+
WantDeletes: []clientgotesting.DeleteActionImpl{
2448+
{
2449+
ActionImpl: clientgotesting.ActionImpl{
2450+
Namespace: testNS,
2451+
Resource: v1.SchemeGroupVersion.WithResource("subscriptions"),
2452+
},
2453+
Name: resources.SequenceChannelName(sequenceName, 1),
2454+
}, {
2455+
ActionImpl: clientgotesting.ActionImpl{
2456+
Namespace: testNS,
2457+
Resource: v1.SchemeGroupVersion.WithResource("inmemorychannels"),
2458+
},
2459+
Name: resources.SequenceChannelName(sequenceName, 1),
2460+
},
2461+
{
2462+
ActionImpl: clientgotesting.ActionImpl{
2463+
Namespace: testNS,
2464+
Resource: v1.SchemeGroupVersion.WithResource("eventpolicies"),
2465+
},
2466+
Name: resources.SequenceEventPolicyName(sequenceName, resources.SequenceChannelName(sequenceName, 1)),
2467+
},
2468+
},
2469+
WantUpdates: []clientgotesting.UpdateActionImpl{{
2470+
ActionImpl: clientgotesting.ActionImpl{
2471+
Namespace: testNS,
2472+
Resource: v1.SchemeGroupVersion.WithResource("subscriptions"),
2473+
},
2474+
Object: resources.NewSubscription(0, NewSequence(sequenceName, testNS,
2475+
WithSequenceChannelTemplateSpec(imc),
2476+
WithSequenceSteps([]v1.SequenceStep{
2477+
{Destination: createDestination(0)}},
2478+
))),
2479+
}},
2480+
WantStatusUpdates: []clientgotesting.UpdateActionImpl{{
2481+
Object: NewSequence(sequenceName, testNS,
2482+
WithInitSequenceConditions,
2483+
WithSequenceChannelTemplateSpec(imc),
2484+
WithSequenceSteps([]v1.SequenceStep{
2485+
{Destination: createDestination(0)}}),
2486+
WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"),
2487+
WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"),
2488+
WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"),
2489+
WithSequenceEventPoliciesReadyBecauseNoPolicyAndOIDCEnabled(),
2490+
WithSequenceChannelStatuses([]v1.SequenceChannelStatus{
2491+
{
2492+
Channel: corev1.ObjectReference{
2493+
APIVersion: "messaging.knative.dev/v1",
2494+
Kind: "InMemoryChannel",
2495+
Name: resources.SequenceChannelName(sequenceName, 0),
2496+
Namespace: testNS,
2497+
},
2498+
ReadyCondition: apis.Condition{
2499+
Type: apis.ConditionReady,
2500+
Status: corev1.ConditionUnknown,
2501+
Reason: "NoReady",
2502+
Message: "Channel does not have Ready condition",
2503+
},
2504+
},
2505+
}),
2506+
WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{
2507+
{
2508+
Subscription: corev1.ObjectReference{
2509+
APIVersion: "messaging.knative.dev/v1",
2510+
Kind: "Subscription",
2511+
Name: resources.SequenceSubscriptionName(sequenceName, 0),
2512+
Namespace: testNS,
2513+
},
2514+
ReadyCondition: apis.Condition{
2515+
Type: apis.ConditionReady,
2516+
Status: corev1.ConditionUnknown,
2517+
Reason: "NoReady",
2518+
Message: "Subscription does not have Ready condition",
2519+
},
2520+
},
2521+
})),
2522+
}},
2523+
},
2524+
{
2525+
Name: "sequenceupdate-remove-step with 1 steps with AuthZ enabled, and sequence doesn't have event policy",
2526+
Key: pKey,
2527+
Objects: []runtime.Object{
2528+
NewSequence(sequenceName, testNS,
2529+
WithInitSequenceConditions,
2530+
WithSequenceChannelTemplateSpec(imc),
2531+
WithSequenceSteps([]v1.SequenceStep{})),
2532+
createChannel(sequenceName, 0),
2533+
resources.NewSubscription(0, NewSequence(sequenceName, testNS,
2534+
WithSequenceChannelTemplateSpec(imc),
2535+
WithSequenceSteps([]v1.SequenceStep{
2536+
{Destination: createDestination(0)},
2537+
}))),
2538+
},
2539+
WantErr: true,
2540+
Ctx: feature.ToContext(context.Background(), feature.Flags{
2541+
feature.OIDCAuthentication: feature.Enabled,
2542+
feature.AuthorizationDefaultMode: feature.AuthorizationAllowSameNamespace,
2543+
}),
2544+
WantEvents: []string{
2545+
Eventf(corev1.EventTypeWarning, "UpdateFailed", "Failed to update status for \"test-sequence\": missing field(s): spec.steps"),
2546+
},
2547+
2548+
WantStatusUpdates: []clientgotesting.UpdateActionImpl{{
2549+
Object: NewSequence(sequenceName, testNS,
2550+
WithInitSequenceConditions,
2551+
WithSequenceChannelTemplateSpec(imc),
2552+
WithSequenceSteps([]v1.SequenceStep{}),
2553+
WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"),
2554+
WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"),
2555+
WithSequenceChannelStatuses([]v1.SequenceChannelStatus{}),
2556+
WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{})),
2557+
}},
2558+
},
22652559
}
22662560

22672561
logger := logtesting.TestLogger(t)

0 commit comments

Comments
 (0)