|
350 | 350 | expect(Delayed::Job.count).to eq(1) |
351 | 351 | end |
352 | 352 |
|
353 | | - context 'last operation indicates success' do |
| 353 | + context 'last operation response is 200 OK and indicates success' do |
354 | 354 | let(:state) { 'succeeded' } |
355 | 355 | let(:fetch_binding_status_code) { 200 } |
356 | 356 | let(:fetch_binding_body) do |
|
381 | 381 | end |
382 | 382 | end |
383 | 383 |
|
384 | | - context 'last operation indicates failure' do |
| 384 | + context 'last operation response is 200 OK and indicates failure' do |
385 | 385 | let(:state) { 'failed' } |
386 | 386 |
|
387 | | - it 'does not queue another polling job' do |
| 387 | + it 'updates the binding and job' do |
388 | 388 | execute_all_jobs(expected_successes: 1, expected_failures: 0) |
389 | | - expect(Delayed::Job.count).to eq(0) |
| 389 | + |
| 390 | + expect(binding.last_operation.type).to eq('create') |
| 391 | + expect(binding.last_operation.state).to eq(state) |
| 392 | + expect(binding.last_operation.description).to eq(description) |
| 393 | + |
| 394 | + expect(job.state).to eq(VCAP::CloudController::PollableJobModel::COMPLETE_STATE) |
390 | 395 | end |
| 396 | + end |
| 397 | + |
| 398 | + context 'last operation response is 400 Bad Request' do |
| 399 | + let(:last_operation_status_code) { 400 } |
| 400 | + let(:state) { 'failed' } |
| 401 | + let(:description) { 'a helpful description' } |
391 | 402 |
|
392 | 403 | it 'updates the binding and job' do |
393 | 404 | execute_all_jobs(expected_successes: 1, expected_failures: 0) |
|
399 | 410 | expect(job.state).to eq(VCAP::CloudController::PollableJobModel::COMPLETE_STATE) |
400 | 411 | end |
401 | 412 | end |
| 413 | + |
| 414 | + context 'last operation response is 404 Not Found' do |
| 415 | + let(:last_operation_status_code) { 404 } |
| 416 | + let(:last_operation_body) { 'cannot see it' } |
| 417 | + |
| 418 | + it 'updates the binding and job' do |
| 419 | + execute_all_jobs(expected_successes: 1, expected_failures: 0) |
| 420 | + |
| 421 | + expect(binding.last_operation.type).to eq('create') |
| 422 | + expect(binding.last_operation.state).to eq('failed') |
| 423 | + expect(binding.last_operation.description).to eq('The service broker rejected the request. Status Code: 404 Not Found, Body: "cannot see it"') |
| 424 | + |
| 425 | + expect(job.state).to eq(VCAP::CloudController::PollableJobModel::COMPLETE_STATE) |
| 426 | + end |
| 427 | + end |
| 428 | + |
| 429 | + context 'last operation response is 500 Internal Server Error' do |
| 430 | + let(:last_operation_status_code) { 500 } |
| 431 | + let(:last_operation_body) { 'something awful' } |
| 432 | + |
| 433 | + it 'updates the binding and job' do |
| 434 | + execute_all_jobs(expected_successes: 0, expected_failures: 1) |
| 435 | + |
| 436 | + expect(binding.last_operation.type).to eq('create') |
| 437 | + expect(binding.last_operation.state).to eq('failed') |
| 438 | + expect(binding.last_operation.description).to eq('The service broker returned an invalid response. Status Code: 500 Internal Server Error, Body: "something awful"') |
| 439 | + |
| 440 | + expect(job.state).to eq(VCAP::CloudController::PollableJobModel::FAILED_STATE) |
| 441 | + end |
| 442 | + end |
| 443 | + |
| 444 | + context 'binding not retrievable' do |
| 445 | + let(:offering) { VCAP::CloudController::Service.make(bindings_retrievable: false, requires: ['route_forwarding']) } |
| 446 | + |
| 447 | + it 'fails the job with an appropriate error' do |
| 448 | + execute_all_jobs(expected_successes: 0, expected_failures: 1) |
| 449 | + |
| 450 | + expect(binding.last_operation.type).to eq('create') |
| 451 | + expect(binding.last_operation.state).to eq('failed') |
| 452 | + expect(binding.last_operation.description).to eq('The broker responded asynchronously but does not support fetching binding data') |
| 453 | + |
| 454 | + expect(job.state).to eq(VCAP::CloudController::PollableJobModel::FAILED_STATE) |
| 455 | + expect(job.cf_api_error).not_to be_nil |
| 456 | + error = YAML.safe_load(job.cf_api_error) |
| 457 | + expect(error['errors'].first).to include({ |
| 458 | + 'code' => 90001, |
| 459 | + 'title' => 'CF-ServiceBindingInvalid', |
| 460 | + 'detail' => 'The service binding is invalid: The broker responded asynchronously but does not support fetching binding data', |
| 461 | + }) |
| 462 | + end |
| 463 | + end |
402 | 464 | end |
403 | 465 | end |
404 | 466 |
|
|
0 commit comments