@@ -576,3 +576,158 @@ func TestCAPTenantDeprovisioningVersionNotReady(t *testing.T) {
576576 },
577577 )
578578}
579+
580+ func TestCAPTenantProvisioningCompletedWithSessionAffinityEnabled (t * testing.T ) {
581+ reconcileTestItem (
582+ context .TODO (), t ,
583+ QueueItem {Key : ResourceCAPTenant , ResourceKey : NamespacedResourceKey {Namespace : "default" , Name : "test-cap-01-provider" }},
584+ TestData {
585+ description : "captenant provisioning operation completed (creates virtual service and destination rule) with session affinity enabled" ,
586+ initialResources : []string {
587+ "testdata/common/domain-ready.yaml" ,
588+ "testdata/common/cluster-domain-ready.yaml" ,
589+ "testdata/common/capapplication-session-affinity.yaml" ,
590+ "testdata/common/capapplicationversion-v1.yaml" ,
591+ "testdata/captenant/cat-04.initial.yaml" ,
592+ },
593+ expectedResources : "testdata/captenant/cat-with-session-affinity-dr-vs.yaml" ,
594+ },
595+ )
596+ }
597+
598+ func TestCAPTenantProvisioningCompletedWithSessionAffinityEnabledAndVsheaders (t * testing.T ) {
599+ reconcileTestItem (
600+ context .TODO (), t ,
601+ QueueItem {Key : ResourceCAPTenant , ResourceKey : NamespacedResourceKey {Namespace : "default" , Name : "test-cap-01-provider" }},
602+ TestData {
603+ description : "captenant provisioning operation completed (creates virtual service and destination rule) with session affinity enabled and virtual service headers" ,
604+ initialResources : []string {
605+ "testdata/common/domain-ready.yaml" ,
606+ "testdata/common/cluster-domain-ready.yaml" ,
607+ "testdata/common/capapplication-session-affinity-vs-headers.yaml" ,
608+ "testdata/common/capapplicationversion-v1.yaml" ,
609+ "testdata/captenant/cat-04.initial.yaml" ,
610+ },
611+ expectedResources : "testdata/captenant/cat-with-session-affinity-dr-vs-headers.yaml" ,
612+ },
613+ )
614+ }
615+
616+ func TestCAPTenantProvisioningCompletedWithSessionAffinityEnabledCustomLogout (t * testing.T ) {
617+ reconcileTestItem (
618+ context .TODO (), t ,
619+ QueueItem {Key : ResourceCAPTenant , ResourceKey : NamespacedResourceKey {Namespace : "default" , Name : "test-cap-01-provider" }},
620+ TestData {
621+ description : "captenant provisioning operation completed (creates virtual service and destination rule) with session affinity enabled using custom logout routes" ,
622+ initialResources : []string {
623+ "testdata/common/domain-ready.yaml" ,
624+ "testdata/common/cluster-domain-ready.yaml" ,
625+ "testdata/common/capapplication-session-affinity.yaml" ,
626+ "testdata/common/capapplicationversion-v1-custom-logout-endpoint.yaml" ,
627+ "testdata/captenant/cat-04.initial.yaml" ,
628+ },
629+ expectedResources : "testdata/captenant/cat-with-session-affinity-dr-vs-logout-endpoint.yaml" ,
630+ },
631+ )
632+ }
633+
634+ func TestCAPTenantUpgradeOperationCompletedWithSessionAffinityEnabled (t * testing.T ) {
635+ reconcileTestItem (
636+ context .TODO (), t ,
637+ QueueItem {Key : ResourceCAPTenant , ResourceKey : NamespacedResourceKey {Namespace : "default" , Name : "test-cap-01-provider" }},
638+ TestData {
639+ description : "captenant upgrade operation completed expecting virtual service, destination rule adjustments with session affinity enabled" ,
640+ initialResources : []string {
641+ "testdata/common/domain-ready.yaml" ,
642+ "testdata/common/cluster-domain-ready.yaml" ,
643+ "testdata/common/capapplication-session-affinity.yaml" ,
644+ "testdata/common/capapplicationversion-v1.yaml" ,
645+ "testdata/common/capapplicationversion-v2.yaml" ,
646+ "testdata/captenant/provider-tenant-vs-v1.yaml" ,
647+ "testdata/captenant/provider-tenant-dr-v1.yaml" ,
648+ "testdata/captenant/cat-13.initial.yaml" ,
649+ },
650+ expectedResources : "testdata/captenant/cat-with-session-affinity-dr-vs-upgrade.yaml" ,
651+ },
652+ )
653+ }
654+
655+ func TestCAPTenantUpgradedThirdTimeWithSessionAffinityEnabled (t * testing.T ) {
656+ reconcileTestItem (
657+ context .TODO (), t ,
658+ QueueItem {Key : ResourceCAPTenant , ResourceKey : NamespacedResourceKey {Namespace : "default" , Name : "test-cap-01-provider" }},
659+ TestData {
660+ description : "captenant upgraded third time - expecting virtual service, destination rule adjustments by removing config corresponding to v1 and by adding config for v3" ,
661+ initialResources : []string {
662+ "testdata/common/domain-ready.yaml" ,
663+ "testdata/common/cluster-domain-ready.yaml" ,
664+ "testdata/common/capapplication-session-affinity.yaml" ,
665+ "testdata/common/capapplicationversion-v1.yaml" ,
666+ "testdata/common/capapplicationversion-v2.yaml" ,
667+ "testdata/common/capapplicationversion-v3.yaml" ,
668+ "testdata/captenant/cat-with-session-affinity-dr-vs-upgrade-to-cav-v3.yaml" ,
669+ },
670+ expectedResources : "testdata/captenant/cat-with-session-affinity-dr-vs-upgrade-to-cav-v3.expected.yaml" ,
671+ },
672+ )
673+ }
674+
675+ func TestCAPTenantUpgradeOperationCompletedWithSessionAffinityEnabledAndPreviousCAVRemoved (t * testing.T ) {
676+ reconcileTestItem (
677+ context .TODO (), t ,
678+ QueueItem {Key : ResourceCAPTenant , ResourceKey : NamespacedResourceKey {Namespace : "default" , Name : "test-cap-01-provider" }},
679+ TestData {
680+ description : "captenant upgraded - expecting virtual service, destination rule adjustments after removing previous cav v1" ,
681+ initialResources : []string {
682+ "testdata/common/domain-ready.yaml" ,
683+ "testdata/common/cluster-domain-ready.yaml" ,
684+ "testdata/common/capapplication-session-affinity.yaml" ,
685+ "testdata/common/capapplicationversion-v2.yaml" ,
686+ "testdata/captenant/cat-with-session-affinity-dr-vs-upgrade.yaml" ,
687+ },
688+ expectedResources : "testdata/captenant/cat-with-session-affinity-dr-vs-prev-cav-removed.yaml" ,
689+ },
690+ )
691+ }
692+
693+ func TestCAPTenantUpgradeOperationCompletedWithSessionAffinitySwitchedFromEnabledToDisabled (t * testing.T ) {
694+ reconcileTestItem (
695+ context .TODO (), t ,
696+ QueueItem {Key : ResourceCAPTenant , ResourceKey : NamespacedResourceKey {Namespace : "default" , Name : "test-cap-01-provider" }},
697+ TestData {
698+ description : "captenant upgraded - expecting virtual service, destination rule adjustments after switching session affinity from enabled to disabled" ,
699+ initialResources : []string {
700+ "testdata/common/domain-ready.yaml" ,
701+ "testdata/common/cluster-domain-ready.yaml" ,
702+ "testdata/common/capapplication.yaml" ,
703+ "testdata/common/capapplicationversion-v1.yaml" ,
704+ "testdata/common/capapplicationversion-v2.yaml" ,
705+ "testdata/captenant/cat-with-session-affinity-dr-vs-upgrade.yaml" ,
706+ },
707+ expectedResources : "testdata/captenant/cat-with-session-affinity-disabled-dr-vs.yaml" ,
708+ },
709+ )
710+ }
711+
712+ func TestCAPTenantUpgradeOperationCompletedWithSessionAffinityEnabledAndPreviousCAVRemovedButDRDeletionFailed (t * testing.T ) {
713+ err := reconcileTestItem (
714+ context .TODO (), t ,
715+ QueueItem {Key : ResourceCAPTenant , ResourceKey : NamespacedResourceKey {Namespace : "default" , Name : "test-cap-01-provider" }},
716+ TestData {
717+ description : "captenant upgraded - expecting virtual service, destination rule adjustments after removing previous cav v1 but DR deletion fails for some reason" ,
718+ initialResources : []string {
719+ "testdata/common/domain-ready.yaml" ,
720+ "testdata/common/cluster-domain-ready.yaml" ,
721+ "testdata/common/capapplication-session-affinity.yaml" ,
722+ "testdata/common/capapplicationversion-v2.yaml" ,
723+ "testdata/captenant/cat-with-session-affinity-dr-vs-upgrade.yaml" ,
724+ },
725+ mockErrorForResources : []ResourceAction {{Verb : "delete" , Group : "networking.istio.io" , Version : "v1" , Resource : "destinationrules" , Namespace : "*" , Name : "test-cap-01-provider-test-cap-01-cav-v1" }},
726+ expectError : true ,
727+ },
728+ )
729+
730+ if err .Error () != "mocked api error (destinationrules.networking.istio.io/v1)" {
731+ t .Error ("error message is different from expected, actual:" , err .Error ())
732+ }
733+ }
0 commit comments