@@ -36,9 +36,6 @@ module VCAP::CloudController
3636 metadata : {
3737 labels : new_labels ,
3838 annotations : new_annotations
39- } ,
40- options : {
41- lb_algo : 'round-robin'
4239 }
4340 }
4441 end
@@ -136,98 +133,94 @@ module VCAP::CloudController
136133 end
137134 end
138135 end
136+
139137 describe '#update options' do
140- context 'when the route has no existing metadata ' do
141- context 'when no metadata is specified' do
138+ context 'when the route has no existing options ' do
139+ context 'when no options are specified' do
142140 let ( :body ) do
143141 { }
144142 end
145143
146- it 'adds no metadata ' do
144+ it 'adds no options ' do
147145 expect ( message ) . to be_valid
148146 subject . update ( route :, message :)
149147 route . reload
150- expect ( route . labels . size ) . to eq ( 0 )
151- expect ( route . annotations . size ) . to eq ( 0 )
148+ expect ( route . options ) . to eq ( { } )
152149 end
153150 end
154151
155- context 'when metadata is specified' do
156- it 'updates the route metadata' do
152+ context 'when an option is specified' do
153+ let ( :body ) do
154+ {
155+ options : {
156+ lb_algo : 'round-robin'
157+ }
158+ }
159+ end
160+
161+ it 'adds the route option' do
157162 expect ( message ) . to be_valid
158163 subject . update ( route :, message :)
159164
160165 route . reload
161- expect ( route ) . to have_labels (
162- { prefix : 'doordash.com' , key_name : 'potato' , value : 'mashed' } ,
163- { prefix : nil , key_name : 'fruit' , value : 'strawberries' } ,
164- { prefix : nil , key_name : 'cuisine' , value : 'thai' }
165- )
166- expect ( route ) . to have_annotations (
167- { key_name : 'potato' , value : 'idaho' }
168- )
169166 expect ( route [ :options ] ) . to eq ( '{"lb_algo":"round-robin"}' )
170167 end
171168 end
172169 end
173170
174- context 'when the route has existing metadata ' do
171+ context 'when the route has existing options ' do
175172 before do
176- VCAP ::CloudController ::LabelsUpdate . update ( route , old_labels , VCAP ::CloudController ::RouteLabelModel )
177- VCAP ::CloudController ::AnnotationsUpdate . update ( route , old_annotations , VCAP ::CloudController ::RouteAnnotationModel )
178173 route [ :options ] = '{"lb_algo": "round-robin"}'
179174 end
180175
181- context 'when no metadata is specified' do
176+ context 'when no options are specified' do
182177 let ( :body ) do
183178 { }
184179 end
185180
186- it 'adds no metadata ' do
181+ it 'modifies nothing ' do
187182 expect ( message ) . to be_valid
188183 subject . update ( route :, message :)
189184 route . reload
190- expect ( route ) . to have_labels (
191- { prefix : nil , key_name : 'fruit' , value : 'peach' } ,
192- { prefix : nil , key_name : 'clothing' , value : 'blouse' }
193- )
194- expect ( route ) . to have_annotations (
195- { key_name : 'potato' , value : 'celandine' } ,
196- { key_name : 'beet' , value : 'formanova' }
197- )
198185 expect ( route . options ) . to include ( { 'lb_algo' => 'round-robin' } )
199186 end
200187 end
201188
202- context 'when metadata is specified' do
189+ context 'when an option is specified' do
203190 let ( :body ) do
204191 {
205- metadata : {
206- labels : new_labels . merge ( fruit : nil , newstuff : 'here' ) ,
207- annotations : new_annotations . merge ( beet : nil , asparagus : 'crunchy' )
192+ options : {
193+ lb_algo : 'least-connections'
208194 }
209195 }
210196 end
211197
212- it 'updates some, deletes nils, leaves unspecified fields alone ' do
198+ it 'updates the option ' do
213199 expect ( message ) . to be_valid
214200 subject . update ( route :, message :)
215201 route . reload
216202
217- expect ( route ) . to have_labels (
218- { prefix : 'doordash.com' , key_name : 'potato' , value : 'mashed' } ,
219- { prefix : nil , key_name : 'clothing' , value : 'blouse' } ,
220- { prefix : nil , key_name : 'newstuff' , value : 'here' } ,
221- { prefix : nil , key_name : 'cuisine' , value : 'thai' }
222- )
223- expect ( route ) . to have_annotations (
224- { key_name : 'potato' , value : 'idaho' } ,
225- { key_name : 'asparagus' , value : 'crunchy' }
226- )
203+ expect ( route . options ) . to include ( { 'lb_algo' => 'least-connections' } )
204+ end
205+ end
206+
207+ context 'when the option value is set to null' do
208+ let ( :body ) do
209+ {
210+ options : {
211+ lb_algo : nil
212+ }
213+ }
214+ end
215+
216+ it 'removes this option' do
217+ expect ( message ) . to be_valid
218+ subject . update ( route :, message :)
219+ route . reload
220+ expect ( route . options ) . to eq ( { } )
227221 end
228222 end
229223 end
230224 end
231-
232225 end
233226end
0 commit comments