|
624 | 624 | end |
625 | 625 | end |
626 | 626 |
|
| 627 | + describe 'route options' do |
| 628 | + context 'when an empty route options hash is provided' do |
| 629 | + let(:yml_manifest) do |
| 630 | + { |
| 631 | + 'applications' => [ |
| 632 | + { |
| 633 | + 'name' => app1_model.name, |
| 634 | + 'routes' => [ |
| 635 | + { 'route' => "https://#{route.host}.#{route.domain.name}", |
| 636 | + 'options' => {} } |
| 637 | + ] |
| 638 | + } |
| 639 | + ] |
| 640 | + }.to_yaml |
| 641 | + end |
| 642 | + |
| 643 | + it 'applies the manifest' do |
| 644 | + post "/v3/spaces/#{space.guid}/actions/apply_manifest", yml_manifest, yml_headers(user_header) |
| 645 | + |
| 646 | + expect(last_response.status).to eq(202) |
| 647 | + end |
| 648 | + end |
| 649 | + |
| 650 | + context 'when an invalid route option is provided' do |
| 651 | + let(:yml_manifest) do |
| 652 | + { |
| 653 | + 'applications' => [ |
| 654 | + { |
| 655 | + 'name' => app1_model.name, |
| 656 | + 'routes' => [ |
| 657 | + { 'route' => "https://#{route.host}.#{route.domain.name}", |
| 658 | + 'options' => { |
| 659 | + 'doesnt-exist' => 'doesnt-exist' |
| 660 | + } } |
| 661 | + ] |
| 662 | + } |
| 663 | + ] |
| 664 | + }.to_yaml |
| 665 | + end |
| 666 | + |
| 667 | + it 'returns a 422' do |
| 668 | + post "/v3/spaces/#{space.guid}/actions/apply_manifest", yml_manifest, yml_headers(user_header) |
| 669 | + |
| 670 | + expect(last_response).to have_status_code(422) |
| 671 | + expect(last_response).to have_error_message('Routes contains an invalid loadbalancing-algorithm option') |
| 672 | + end |
| 673 | + end |
| 674 | + |
| 675 | + context 'loadbalancing-algorithm' do |
| 676 | + context 'when the loadbalancing-algorithm is not supported' do |
| 677 | + let(:yml_manifest) do |
| 678 | + { |
| 679 | + 'applications' => [ |
| 680 | + { |
| 681 | + 'name' => app1_model.name, |
| 682 | + 'routes' => [ |
| 683 | + { 'route' => "https://#{route.host}.#{route.domain.name}", |
| 684 | + 'options' => { |
| 685 | + 'loadbalancing-algorithm' => 'unsupported-lb-algorithm' |
| 686 | + } } |
| 687 | + ] |
| 688 | + } |
| 689 | + ] |
| 690 | + }.to_yaml |
| 691 | + end |
| 692 | + |
| 693 | + it 'returns a 422' do |
| 694 | + post "/v3/spaces/#{space.guid}/actions/apply_manifest", yml_manifest, yml_headers(user_header) |
| 695 | + |
| 696 | + expect(last_response).to have_status_code(422) |
| 697 | + expect(last_response).to have_error_message('Routes contains an invalid loadbalancing-algorithm option') |
| 698 | + end |
| 699 | + end |
| 700 | + |
| 701 | + context 'when the loadbalancing-algorithm is supported' do |
| 702 | + context 'when a new route is added' do |
| 703 | + let(:yml_manifest) do |
| 704 | + { |
| 705 | + 'applications' => [ |
| 706 | + { 'name' => app1_model.name, |
| 707 | + 'routes' => [ |
| 708 | + { 'route' => "https://round-robin-app.#{shared_domain.name}", |
| 709 | + 'options' => { |
| 710 | + 'loadbalancing-algorithm' => 'round-robin' |
| 711 | + } } |
| 712 | + ] } |
| 713 | + ] |
| 714 | + }.to_yaml |
| 715 | + end |
| 716 | + |
| 717 | + it 'adds and removes the loadbalancing-algorithm to the route' do |
| 718 | + post "/v3/spaces/#{space.guid}/actions/apply_manifest", yml_manifest, yml_headers(user_header) |
| 719 | + |
| 720 | + expect(last_response.status).to eq(202) |
| 721 | + job_guid = VCAP::CloudController::PollableJobModel.last.guid |
| 722 | + |
| 723 | + Delayed::Worker.new.work_off |
| 724 | + expect(VCAP::CloudController::PollableJobModel.find(guid: job_guid)).to be_complete, VCAP::CloudController::PollableJobModel.find(guid: job_guid).cf_api_error |
| 725 | + |
| 726 | + app1_model.reload |
| 727 | + expect(app1_model.routes.first.options).to eq({ 'lb_algo' => 'round-robin' }) |
| 728 | + # expect(route.route_mappings_dataset.first(app: app1_model).protocol).to eq('http1') |
| 729 | + # expect(second_route.route_mappings_dataset.first(app: app1_model).protocol).to eq('http2') |
| 730 | + |
| 731 | + ### remove the loadbalancing-algorithm from the route |
| 732 | + |
| 733 | + yml_manifest = { |
| 734 | + 'applications' => [ |
| 735 | + { 'name' => app1_model.name, |
| 736 | + 'routes' => [ |
| 737 | + { 'route' => "https://round-robin-app.#{shared_domain.name}" } |
| 738 | + ] } |
| 739 | + ] |
| 740 | + }.to_yaml |
| 741 | + |
| 742 | + post "/v3/spaces/#{space.guid}/actions/apply_manifest", yml_manifest, yml_headers(user_header) |
| 743 | + |
| 744 | + expect(last_response.status).to eq(202) |
| 745 | + job_guid = VCAP::CloudController::PollableJobModel.last.guid |
| 746 | + |
| 747 | + Delayed::Worker.new.work_off |
| 748 | + expect(VCAP::CloudController::PollableJobModel.find(guid: job_guid)).to be_complete, VCAP::CloudController::PollableJobModel.find(guid: job_guid).cf_api_error |
| 749 | + |
| 750 | + app1_model.reload |
| 751 | + expect(app1_model.routes.first.options).to eq({}) |
| 752 | + |
| 753 | + end |
| 754 | + |
| 755 | + end |
| 756 | + end |
| 757 | + end |
| 758 | + |
| 759 | + end |
| 760 | + |
627 | 761 | describe 'audit events' do |
628 | 762 | let!(:process1) { nil } |
629 | 763 |
|
|
0 commit comments