@@ -3156,3 +3156,45 @@ spec:
3156
3156
actions := client .Actions ()
3157
3157
assert .Len (t , actions , 0 )
3158
3158
}
3159
+
3160
+ func TestGetHttpRouteIndexesToPatch (t * testing.T ) {
3161
+
3162
+ // Test case when the rollout has no managed routes defined
3163
+ httpRoutes := []VirtualServiceHTTPRoute {
3164
+ {Name : "foo" , Match : nil },
3165
+ {Name : "" , Match : nil },
3166
+ }
3167
+
3168
+ indexes , err := getHttpRouteIndexesToPatch ([]string {}, httpRoutes )
3169
+ assert .NoError (t , err )
3170
+ assert .Equal (t , []int {1 }, indexes )
3171
+
3172
+ // Test case when the rollout has managed routes defined
3173
+ httpRoutes = []VirtualServiceHTTPRoute {
3174
+ {Name : "foo" , Match : nil },
3175
+ {Name : "bar" , Match : nil },
3176
+ }
3177
+
3178
+ indexes , err = getHttpRouteIndexesToPatch ([]string {"foo" , "bar" }, httpRoutes )
3179
+ assert .NoError (t , err )
3180
+ assert .Equal (t , []int {0 , 1 }, indexes )
3181
+
3182
+ // Test case when the rollout has only one managed route defined
3183
+ httpRoutes = []VirtualServiceHTTPRoute {
3184
+ {Name : "foo" , Match : nil },
3185
+ }
3186
+
3187
+ indexes , err = getHttpRouteIndexesToPatch ([]string {}, httpRoutes )
3188
+ assert .NoError (t , err )
3189
+ assert .Equal (t , []int {0 }, indexes )
3190
+
3191
+ // Test case when http route is not found
3192
+ httpRoutes = []VirtualServiceHTTPRoute {
3193
+ {Name : "foo" , Match : nil },
3194
+ }
3195
+
3196
+ indexes , err = getHttpRouteIndexesToPatch ([]string {"bar" }, httpRoutes )
3197
+ assert .Equal (t , "HTTP Route 'bar' is not found in the defined Virtual Service." , err .Error ())
3198
+ assert .Nil (t , indexes )
3199
+
3200
+ }
0 commit comments