@@ -539,9 +539,9 @@ func TestValidateRolloutStrategyCanarySetHeaderRoutePlugins(t *testing.T) {
539539 }
540540
541541 t .Run ("using SetHeaderRoute step with plugins" , func (t * testing.T ) {
542- invalidRo := ro .DeepCopy ()
542+ validRo := ro .DeepCopy ()
543543 routeName := "test"
544- invalidRo .Spec .Strategy .Canary .Steps = []v1alpha1.CanaryStep {{
544+ validRo .Spec .Strategy .Canary .Steps = []v1alpha1.CanaryStep {{
545545 SetHeaderRoute : & v1alpha1.SetHeaderRoute {
546546 Name : routeName ,
547547 Match : []v1alpha1.HeaderRoutingMatch {
@@ -552,7 +552,7 @@ func TestValidateRolloutStrategyCanarySetHeaderRoutePlugins(t *testing.T) {
552552 },
553553 },
554554 }}
555- invalidRo .Spec .Strategy .Canary .TrafficRouting = & v1alpha1.RolloutTrafficRouting {
555+ validRo .Spec .Strategy .Canary .TrafficRouting = & v1alpha1.RolloutTrafficRouting {
556556 ManagedRoutes : []v1alpha1.MangedRoutes {
557557 {
558558 Name : routeName ,
@@ -562,7 +562,67 @@ func TestValidateRolloutStrategyCanarySetHeaderRoutePlugins(t *testing.T) {
562562 "anyplugin" : []byte (`{"key": "value"}` ),
563563 },
564564 }
565+ allErrs := ValidateRolloutStrategyCanary (validRo , field .NewPath ("" ))
566+ assert .Equal (t , 0 , len (allErrs ))
567+ })
568+ }
569+
570+ func TestValidateRolloutStrategyCanarySetMirrorRoute (t * testing.T ) {
571+ ro := & v1alpha1.Rollout {}
572+ ro .Spec .Strategy .Canary = & v1alpha1.CanaryStrategy {
573+ CanaryService : "canary" ,
574+ StableService : "stable" ,
575+ }
576+
577+ t .Run ("using SetMirrorRoute step without the traffic routing" , func (t * testing.T ) {
578+ invalidRo := ro .DeepCopy ()
579+ invalidRo .Spec .Strategy .Canary .Steps = []v1alpha1.CanaryStep {{
580+ SetMirrorRoute : & v1alpha1.SetMirrorRoute {
581+ Name : "test-mirror-1" ,
582+ Match : nil ,
583+ Percentage : nil ,
584+ },
585+ }}
565586 allErrs := ValidateRolloutStrategyCanary (invalidRo , field .NewPath ("" ))
587+ assert .Equal (t , InvalidSetMirrorRouteTrafficPolicy , allErrs [0 ].Detail )
588+ })
589+ }
590+
591+ func TestValidateRolloutStrategyCanarySetMirrorRoutePlugins (t * testing.T ) {
592+ ro := & v1alpha1.Rollout {}
593+ ro .Spec .Strategy .Canary = & v1alpha1.CanaryStrategy {
594+ CanaryService : "canary" ,
595+ StableService : "stable" ,
596+ }
597+
598+ t .Run ("using SetMirrorRoute step with plugins" , func (t * testing.T ) {
599+ validRo := ro .DeepCopy ()
600+ routeName := "test-mirror-1"
601+ validRo .Spec .Strategy .Canary .Steps = []v1alpha1.CanaryStep {{
602+ SetMirrorRoute : & v1alpha1.SetMirrorRoute {
603+ Name : routeName ,
604+ Match : []v1alpha1.RouteMatch {{
605+ Method : & v1alpha1.StringMatch {
606+ Exact : "GET" ,
607+ },
608+ Path : & v1alpha1.StringMatch {
609+ Prefix : "/api" ,
610+ },
611+ }},
612+ Percentage : ptr.To [int32 ](50 ),
613+ },
614+ }}
615+ validRo .Spec .Strategy .Canary .TrafficRouting = & v1alpha1.RolloutTrafficRouting {
616+ ManagedRoutes : []v1alpha1.MangedRoutes {
617+ {
618+ Name : routeName ,
619+ },
620+ },
621+ Plugins : map [string ]json.RawMessage {
622+ "anyplugin" : []byte (`{"key": "value"}` ),
623+ },
624+ }
625+ allErrs := ValidateRolloutStrategyCanary (validRo , field .NewPath ("" ))
566626 assert .Equal (t , 0 , len (allErrs ))
567627 })
568628}
0 commit comments