@@ -13,9 +13,7 @@ module CloudController
1313 ServiceRouteBindingsListMessage . from_params ( { } )
1414 )
1515
16- fetched_route_binding_guids = fetched_route_bindings . map ( &:guid )
17- expected_route_binding_guids = route_bindings . map ( &:guid )
18- expect ( fetched_route_binding_guids ) . to match_array ( expected_route_binding_guids )
16+ expect_binding_guids ( fetched_route_bindings , route_bindings )
1917 end
2018
2119 it 'can be filtered by service_instance_guids' do
@@ -26,9 +24,7 @@ module CloudController
2624 ServiceRouteBindingsListMessage . from_params ( { 'service_instance_guids' => service_instance_guids } )
2725 )
2826
29- fetched_route_binding_guids = fetched_route_bindings . map ( &:guid )
30- expected_binding_guids = filtered_route_bindings . map ( &:guid )
31- expect ( fetched_route_binding_guids ) . to match_array ( expected_binding_guids )
27+ expect_binding_guids ( fetched_route_bindings , filtered_route_bindings )
3228 end
3329
3430 it 'can be filtered by service_instance_names' do
@@ -39,9 +35,7 @@ module CloudController
3935 ServiceRouteBindingsListMessage . from_params ( { 'service_instance_names' => service_instance_names } )
4036 )
4137
42- fetched_route_binding_guids = fetched_route_bindings . map ( &:guid )
43- expected_binding_guids = filtered_route_bindings . map ( &:guid )
44- expect ( fetched_route_binding_guids ) . to match_array ( expected_binding_guids )
38+ expect_binding_guids ( fetched_route_bindings , filtered_route_bindings )
4539 end
4640
4741 it 'can be filtered by route_guids' do
@@ -52,9 +46,25 @@ module CloudController
5246 ServiceRouteBindingsListMessage . from_params ( { 'route_guids' => route_guids } )
5347 )
5448
55- fetched_route_binding_guids = fetched_route_bindings . map ( &:guid )
56- expected_binding_guids = filtered_route_bindings . map ( &:guid )
57- expect ( fetched_route_binding_guids ) . to match_array ( expected_binding_guids )
49+ expect_binding_guids ( fetched_route_bindings , filtered_route_bindings )
50+ end
51+
52+ context 'can be filtered by label selector' do
53+ before do
54+ RouteBindingLabelModel . make ( key_name : 'fruit' , value : 'strawberry' , route_binding : route_bindings [ 0 ] )
55+ RouteBindingLabelModel . make ( key_name : 'fruit' , value : 'strawberry' , route_binding : route_bindings [ 1 ] )
56+ RouteBindingLabelModel . make ( key_name : 'fruit' , value : 'lemon' , route_binding : route_bindings [ 2 ] )
57+ end
58+
59+ it 'returns instances with matching labels' do
60+ filtered_route_bindings = route_bindings [ 0 ..1 ]
61+
62+ fetched_route_bindings = fetcher . fetch_all (
63+ ServiceRouteBindingsListMessage . from_params ( { 'label_selector' => 'fruit=strawberry' } )
64+ )
65+
66+ expect_binding_guids ( fetched_route_bindings , filtered_route_bindings )
67+ end
5868 end
5969 end
6070
@@ -74,9 +84,7 @@ module CloudController
7484 space_guids : [ target_space . guid ]
7585 )
7686
77- fetched_route_binding_guids = fetched_route_bindings . map ( &:guid )
78- target_space_route_binding_guids = route_bindings_in_target_space . map ( &:guid )
79- expect ( fetched_route_binding_guids ) . to match_array ( target_space_route_binding_guids )
87+ expect_binding_guids ( fetched_route_bindings , route_bindings_in_target_space )
8088 end
8189
8290 it 'can be filtered by service_instance_guids' do
@@ -93,9 +101,7 @@ module CloudController
93101 space_guids : [ target_space . guid ]
94102 )
95103
96- fetched_route_binding_guids = fetched_route_bindings . map ( &:guid )
97- expected_binding_guids = filtered_route_bindings . map ( &:guid )
98- expect ( fetched_route_binding_guids ) . to match_array ( expected_binding_guids )
104+ expect_binding_guids ( fetched_route_bindings , filtered_route_bindings )
99105 end
100106
101107 it 'can be filtered by service_instance_names' do
@@ -112,9 +118,7 @@ module CloudController
112118 space_guids : [ target_space . guid ]
113119 )
114120
115- fetched_route_binding_guids = fetched_route_bindings . map ( &:guid )
116- expected_binding_guids = filtered_route_bindings . map ( &:guid )
117- expect ( fetched_route_binding_guids ) . to match_array ( expected_binding_guids )
121+ expect_binding_guids ( fetched_route_bindings , filtered_route_bindings )
118122 end
119123
120124 it 'can be filtered by route_guids' do
@@ -131,15 +135,17 @@ module CloudController
131135 space_guids : [ target_space . guid ]
132136 )
133137
134- fetched_route_binding_guids = fetched_route_bindings . map ( &:guid )
135- expected_binding_guids = filtered_route_bindings . map ( &:guid )
136- expect ( fetched_route_binding_guids ) . to match_array ( expected_binding_guids )
138+ expect_binding_guids ( fetched_route_bindings , filtered_route_bindings )
137139 end
138140
139141 def make_other_route_bindings
140142 Array . new ( 3 ) { RouteBinding . make }
141143 end
142144 end
145+
146+ def expect_binding_guids ( fetched_route_bindings , expected_route_bindings )
147+ expect ( fetched_route_bindings . map ( &:guid ) ) . to match_array ( expected_route_bindings . map ( &:guid ) )
148+ end
143149 end
144150 end
145151end
0 commit comments