|
92 | 92 | 'guid' => package.guid |
93 | 93 | }, |
94 | 94 | 'droplet' => nil, |
| 95 | + 'warnings' => nil, |
95 | 96 | 'relationships' => { 'app' => { 'data' => { 'guid' => app_model.guid } } }, |
96 | 97 | 'links' => { |
97 | 98 | 'self' => { |
|
199 | 200 | end |
200 | 201 | end |
201 | 202 | end |
| 203 | + |
| 204 | + context 'when stack is DISABLED' do |
| 205 | + let(:disabled_stack) { VCAP::CloudController::Stack.make(name: 'cflinuxfs3', state: 'DISABLED', description: 'cflinuxfs3 stack is now disabled') } |
| 206 | + let(:create_request) do |
| 207 | + { |
| 208 | + lifecycle: { |
| 209 | + type: 'buildpack', |
| 210 | + data: { |
| 211 | + buildpacks: ['https://github.com/myorg/awesome-buildpack'], |
| 212 | + stack: disabled_stack.name |
| 213 | + } |
| 214 | + }, |
| 215 | + package: { |
| 216 | + guid: package.guid |
| 217 | + } |
| 218 | + } |
| 219 | + end |
| 220 | + |
| 221 | + it 'returns 422 and does not create the build' do |
| 222 | + post '/v3/builds', create_request.to_json, developer_headers |
| 223 | + |
| 224 | + expect(last_response.status).to eq(422) |
| 225 | + expect(parsed_response['errors'].first['detail']).to include('disabled') |
| 226 | + expect(parsed_response['errors'].first['detail']).to include('cannot be used for staging new applications') |
| 227 | + expect(VCAP::CloudController::BuildModel.count).to eq(0) |
| 228 | + end |
| 229 | + end |
| 230 | + |
| 231 | + context 'when stack is RESTRICTED' do |
| 232 | + let(:restricted_stack) { VCAP::CloudController::Stack.make(name: 'cflinuxfs3', state: 'RESTRICTED', description: 'No new apps') } |
| 233 | + let(:create_request) do |
| 234 | + { |
| 235 | + lifecycle: { |
| 236 | + type: 'buildpack', |
| 237 | + data: { |
| 238 | + buildpacks: ['http://github.com/myorg/awesome-buildpack'], |
| 239 | + stack: restricted_stack.name |
| 240 | + } |
| 241 | + }, |
| 242 | + package: { |
| 243 | + guid: package.guid |
| 244 | + } |
| 245 | + } |
| 246 | + end |
| 247 | + |
| 248 | + context 'first build for app' do |
| 249 | + it 'returns 422 and does not create build' do |
| 250 | + expect(app_model.builds_dataset.count).to eq(0) |
| 251 | + |
| 252 | + post '/v3/builds', create_request.to_json, developer_headers |
| 253 | + |
| 254 | + expect(last_response.status).to eq(422) |
| 255 | + expect(parsed_response['errors'].first['detail']).to include('cannot be used for staging new applications') |
| 256 | + expect(VCAP::CloudController::BuildModel.count).to eq(0) |
| 257 | + end |
| 258 | + end |
| 259 | + |
| 260 | + context 'app has previous builds' do |
| 261 | + before do |
| 262 | + VCAP::CloudController::BuildModel.make(app: app_model, state: VCAP::CloudController::BuildModel::STAGED_STATE) |
| 263 | + end |
| 264 | + |
| 265 | + it 'returns 201 and creates build' do |
| 266 | + expect(app_model.builds_dataset.count).to eq(1) |
| 267 | + |
| 268 | + post '/v3/builds', create_request.to_json, developer_headers |
| 269 | + |
| 270 | + expect(last_response.status).to eq(201) |
| 271 | + expect(parsed_response['state']).to eq('STAGING') |
| 272 | + expect(app_model.builds_dataset.count).to eq(2) |
| 273 | + end |
| 274 | + end |
| 275 | + end |
| 276 | + |
| 277 | + context 'when stack is DEPRECATED' do |
| 278 | + let(:deprecated_stack) { VCAP::CloudController::Stack.make(name: 'cflinuxfs3', state: 'DEPRECATED', description: 'cflinuxfs3 stack is deprecated. Please migrate your application to cflinuxfs4') } |
| 279 | + let(:create_request) do |
| 280 | + { |
| 281 | + lifecycle: { |
| 282 | + type: 'buildpack', |
| 283 | + data: { |
| 284 | + buildpacks: ['http://github.com/myorg/awesome-buildpack'], |
| 285 | + stack: deprecated_stack.name |
| 286 | + } |
| 287 | + }, |
| 288 | + package: { |
| 289 | + guid: package.guid |
| 290 | + } |
| 291 | + } |
| 292 | + end |
| 293 | + |
| 294 | + context 'first build for app' do |
| 295 | + it 'returns 201 and does not create the build' do |
| 296 | + expect(app_model.builds_dataset.count).to eq(0) |
| 297 | + |
| 298 | + post '/v3/builds', create_request.to_json, developer_headers |
| 299 | + |
| 300 | + expect(last_response.status).to eq(201) |
| 301 | + expect(parsed_response['state']).to eq('STAGING') |
| 302 | + expect(parsed_response['warnings']).to be_present |
| 303 | + expect(parsed_response['warnings'][0]['detail']).to include('deprecated') |
| 304 | + expect(parsed_response['warnings'][0]['detail']).to include('cflinuxfs3 stack is deprecated') |
| 305 | + end |
| 306 | + end |
| 307 | + |
| 308 | + context 'app has previous builds' do |
| 309 | + before do |
| 310 | + VCAP::CloudController::BuildModel.make(app: app_model, state: VCAP::CloudController::BuildModel::STAGED_STATE) |
| 311 | + end |
| 312 | + |
| 313 | + it 'returns 201 and does not create the build' do |
| 314 | + expect(app_model.builds_dataset.count).to eq(1) |
| 315 | + |
| 316 | + post '/v3/builds', create_request.to_json, developer_headers |
| 317 | + |
| 318 | + expect(last_response.status).to eq(201) |
| 319 | + expect(parsed_response['state']).to eq('STAGING') |
| 320 | + expect(parsed_response['warnings']).to be_present |
| 321 | + expect(parsed_response['warnings'][0]['detail']).to include('deprecated') |
| 322 | + expect(parsed_response['warnings'][0]['detail']).to include('cflinuxfs3 stack is deprecated') |
| 323 | + expect(app_model.builds_dataset.count).to eq(2) |
| 324 | + end |
| 325 | + end |
| 326 | + end |
202 | 327 | end |
203 | 328 |
|
204 | 329 | describe 'GET /v3/builds' do |
|
349 | 474 | 'droplet' => { |
350 | 475 | 'guid' => droplet.guid |
351 | 476 | }, |
| 477 | + 'warnings' => nil, |
352 | 478 | 'relationships' => { 'app' => { 'data' => { 'guid' => app_model.guid } } }, |
353 | 479 | 'metadata' => { 'labels' => {}, 'annotations' => {} }, |
354 | 480 | 'links' => { |
|
378 | 504 | 'droplet' => { |
379 | 505 | 'guid' => second_droplet.guid |
380 | 506 | }, |
| 507 | + 'warnings' => nil, |
381 | 508 | 'relationships' => { 'app' => { 'data' => { 'guid' => app_model.guid } } }, |
382 | 509 | 'metadata' => { 'labels' => {}, 'annotations' => {} }, |
383 | 510 | 'links' => { |
|
480 | 607 | 'droplet' => { |
481 | 608 | 'guid' => droplet.guid |
482 | 609 | }, |
| 610 | + 'warnings' => nil, |
483 | 611 | 'metadata' => { 'labels' => {}, 'annotations' => {} }, |
484 | 612 | 'relationships' => { 'app' => { 'data' => { 'guid' => app_model.guid } } }, |
485 | 613 | 'links' => { |
|
0 commit comments