|
309 | 309 | end |
310 | 310 |
|
311 | 311 | context 'when the app name is not a valid host name and the default-route flag is set to true' do |
312 | | - let(:app1_model) { VCAP::CloudController::AppModel.make(name: '!' * 64, space: space) } |
| 312 | + let(:app1_model) { VCAP::CloudController::AppModel.make(name: 'a' * 64, space: space) } |
313 | 313 | let(:yml_manifest) do |
314 | 314 | { |
315 | 315 | 'applications' => [ |
|
319 | 319 | }.to_yaml |
320 | 320 | end |
321 | 321 |
|
322 | | - it 'returns a 422 with an informative message' do |
| 322 | + it 'returns a 202 but fails on the job' do |
323 | 323 | expect { |
324 | 324 | post "/v3/spaces/#{space.guid}/actions/apply_manifest", yml_manifest, yml_headers(user_header) |
325 | 325 | }.to change { VCAP::CloudController::AppModel.count }.by(0) |
326 | 326 |
|
327 | | - expect(last_response).to have_status_code(422) |
328 | | - expect(last_response).to include_error_message( |
329 | | - /Failed to create default route from app name: Host cannot exceed 63 characters/) |
330 | | - expect(last_response).to include_error_message( |
331 | | - /Failed to create default route from app name: Host must be either "\*" or contain only alphanumeric characters, "_", or "-"/) |
| 327 | + expect(last_response).to have_status_code(202) |
| 328 | + expect(last_response.status).to eq(202), last_response.body |
| 329 | + |
| 330 | + job_guid = VCAP::CloudController::PollableJobModel.last.guid |
| 331 | + expect(last_response.headers['Location']).to match(%r(/v3/jobs/#{job_guid})) |
| 332 | + |
| 333 | + Delayed::Worker.new.work_off |
| 334 | + job = VCAP::CloudController::PollableJobModel.find(guid: job_guid) |
| 335 | + errors = YAML.safe_load(job.cf_api_error)['errors'] |
| 336 | + expect(errors.length).to eq 1 |
| 337 | + expect(errors[0]['detail']).to include('Host cannot exceed 63 characters') |
| 338 | + end |
| 339 | + |
| 340 | + context 'and routes are provided in the manifest' do |
| 341 | + let(:yml_manifest) do |
| 342 | + { |
| 343 | + 'applications' => [ |
| 344 | + { 'name' => app1_model.name, |
| 345 | + 'default-route' => true, |
| 346 | + 'routes' => [{ 'route' => "http://#{route.host}.#{shared_domain.name}" }] }, |
| 347 | + ] |
| 348 | + }.to_yaml |
| 349 | + end |
| 350 | + |
| 351 | + it 'returns a 202 and succeeds' do |
| 352 | + expect { |
| 353 | + post "/v3/spaces/#{space.guid}/actions/apply_manifest", yml_manifest, yml_headers(user_header) |
| 354 | + }.to change { VCAP::CloudController::AppModel.count }.by(0) |
| 355 | + |
| 356 | + expect(last_response).to have_status_code(202) |
| 357 | + expect(last_response.status).to eq(202), last_response.body |
| 358 | + |
| 359 | + job_guid = VCAP::CloudController::PollableJobModel.last.guid |
| 360 | + expect(last_response.headers['Location']).to match(%r(/v3/jobs/#{job_guid})) |
| 361 | + |
| 362 | + Delayed::Worker.new.work_off |
| 363 | + job = VCAP::CloudController::PollableJobModel.find(guid: job_guid) |
| 364 | + expect(job.complete?).to be true |
| 365 | + expect(job.cf_api_error).to be nil |
| 366 | + end |
332 | 367 | end |
333 | 368 | end |
334 | 369 |
|
|
0 commit comments