@@ -167,6 +167,13 @@ module VCAP::CloudController
167167 expect ( message . errors [ :'options.canary' ] ) . to include ( 'are only valid for Canary deployments' )
168168 end
169169
170+ it 'errors when there is an unknown option' do
171+ body [ 'options' ] = { foo : 'bar' , baz : 'boo' }
172+ message = DeploymentCreateMessage . new ( body )
173+ expect ( message ) . not_to be_valid
174+ expect ( message . errors [ :options ] ) . to include ( 'has unsupported key(s): foo, baz' )
175+ end
176+
170177 context 'steps' do
171178 it 'errors when is not an array' do
172179 body [ 'options' ] = { canary : { steps : 'foo' } }
@@ -175,7 +182,7 @@ module VCAP::CloudController
175182 expect ( message . errors [ :'options.canary.steps' ] ) . to include ( 'must be an array of objects' )
176183 end
177184
178- it 'is valid when is an array' do
185+ it 'is valid when is an empty array' do
179186 body [ 'options' ] = { canary : { steps : [ ] } }
180187 message = DeploymentCreateMessage . new ( body )
181188 expect ( message ) . to be_valid
@@ -187,12 +194,6 @@ module VCAP::CloudController
187194 expect ( message ) . to be_valid
188195 end
189196
190- it 'is valid if instance_weights are Integers between 1-100 in ascending order' do
191- body [ 'options' ] = { canary : { steps : [ { instance_weight : 1 } , { instance_weight : 2 } , { instance_weight : 50 } , { instance_weight : 99 } , { instance_weight : 100 } ] } }
192- message = DeploymentCreateMessage . new ( body )
193- expect ( message ) . to be_valid
194- end
195-
196197 it 'errors if not an array of objects' do
197198 body [ 'options' ] = { canary : { steps : [ { instance_weight : 1 } , 'foo' ] } }
198199 message = DeploymentCreateMessage . new ( body )
@@ -209,20 +210,53 @@ module VCAP::CloudController
209210 end
210211
211212 context 'instance_weights' do
213+ it 'is valid if instance_weights are Integers between 1-100 in ascending order' do
214+ body [ 'options' ] = { canary : { steps : [ { instance_weight : 1 } , { instance_weight : 2 } , { instance_weight : 50 } , { instance_weight : 99 } , { instance_weight : 100 } ] } }
215+ message = DeploymentCreateMessage . new ( body )
216+ expect ( message ) . to be_valid
217+ end
218+
219+ it 'is valid if there are duplicate instance_weights' do
220+ body [ 'options' ] = { canary : { steps : [ { instance_weight : 10 } , { instance_weight : 10 } , { instance_weight : 50 } , { instance_weight : 50 } ] } }
221+ message = DeploymentCreateMessage . new ( body )
222+ expect ( message ) . to be_valid
223+ end
224+
212225 it 'errors if steps are missing instance_weight' do
213226 body [ 'options' ] = { canary : { steps : [ { instance_weight : 1 } , { foo : 'bar' } ] } }
214227 message = DeploymentCreateMessage . new ( body )
215228 expect ( message ) . not_to be_valid
216229 expect ( message . errors [ :'options.canary.steps' ] ) . to include ( 'missing key: "instance_weight"' )
217230 end
218231
219- it 'errors if any instance_weight is less than or equal to 0' do
232+ it 'errors if steps are missing instance_weight with empty hash' do
233+ body [ 'options' ] = { canary : { steps : [ { instance_weight : 1 } , { } ] } }
234+ message = DeploymentCreateMessage . new ( body )
235+ expect ( message ) . not_to be_valid
236+ expect ( message . errors [ :'options.canary.steps' ] ) . to include ( 'missing key: "instance_weight"' )
237+ end
238+
239+ it 'errors if any instance_weight is not an Integer' do
240+ body [ 'options' ] = { canary : { steps : [ { instance_weight : 'foo' } ] } }
241+ message = DeploymentCreateMessage . new ( body )
242+ expect ( message ) . not_to be_valid
243+ expect ( message . errors [ :'options.canary.steps.instance_weight' ] ) . to include ( 'must be an Integer between 1-100 (inclusive)' )
244+ end
245+
246+ it 'errors if any instance_weight is equal to 0' do
220247 body [ 'options' ] = { canary : { steps : [ { instance_weight : 0 } , { instance_weight : 50 } ] } }
221248 message = DeploymentCreateMessage . new ( body )
222249 expect ( message ) . not_to be_valid
223250 expect ( message . errors [ :'options.canary.steps.instance_weight' ] ) . to include ( 'must be an Integer between 1-100 (inclusive)' )
224251 end
225252
253+ it 'errors if any instance_weight is less than 0' do
254+ body [ 'options' ] = { canary : { steps : [ { instance_weight : -5 } , { instance_weight : 50 } ] } }
255+ message = DeploymentCreateMessage . new ( body )
256+ expect ( message ) . not_to be_valid
257+ expect ( message . errors [ :'options.canary.steps.instance_weight' ] ) . to include ( 'must be an Integer between 1-100 (inclusive)' )
258+ end
259+
226260 it 'errors if any instance_weight is greater than 100' do
227261 body [ 'options' ] = { canary : { steps : [ { instance_weight : 50 } , { instance_weight : 101 } ] } }
228262 message = DeploymentCreateMessage . new ( body )
@@ -237,8 +271,7 @@ module VCAP::CloudController
237271 expect ( message . errors [ :'options.canary.steps.instance_weight' ] ) . to include ( 'must be sorted in ascending order' )
238272 end
239273
240- it 'errors if any instance_weights are not an Integer' do
241- # TODO: should we coerce values like 25.0 to 25? only error on 25.1 etc?
274+ it 'errors if any instance_weights are not a non-integer numeric' do
242275 body [ 'options' ] = { canary : { steps : [ { instance_weight : 2 } , { instance_weight : 25.0 } ] } }
243276 message = DeploymentCreateMessage . new ( body )
244277 expect ( message ) . not_to be_valid
@@ -300,7 +333,7 @@ module VCAP::CloudController
300333
301334 context 'when options is specified, but not max_in_flight' do
302335 before do
303- body [ 'options' ] = { other_key : 'other_value' }
336+ body [ 'options' ] = { canary : nil }
304337 end
305338
306339 it 'returns the default value of 1' do
@@ -334,13 +367,5 @@ module VCAP::CloudController
334367 end
335368 end
336369 end
337-
338- context 'validations' do
339- context 'when one instance_weight is below 0'
340- context 'when one instance_weight is above 100'
341- context 'when an instance weight is a decimal or non-integer'
342- context 'when canary steps is an empty array'
343- context 'when canary steps are non-increasing (e.g. 1,50,20)'
344- end
345370 end
346371end
0 commit comments