|
5 | 5 | require 'messages/service_broker_update_message' |
6 | 6 |
|
7 | 7 | # This lifecycle test aims to use different v3 service endpoints together |
| 8 | +# rubocop:disable Naming/AccessorMethodName |
8 | 9 | RSpec.describe 'V3 services synoptic' do |
9 | 10 | before do |
10 | 11 | stub_request(:get, 'http://example.org/amazing-service-broker/v2/catalog'). |
11 | 12 | with(basic_auth: %w(admin password)). |
12 | 13 | to_return(status: 200, body: catalog, headers: {}) |
| 14 | + |
| 15 | + stub_request(:put, %r{\Ahttp://example.org/amazing-service-broker/v2/service_instances/.+\z}). |
| 16 | + with(basic_auth: %w(admin password)). |
| 17 | + to_return(status: 201, body: {}.to_json, headers: {}) |
13 | 18 | end |
14 | 19 |
|
15 | 20 | it 'works end to end' do |
| 21 | + org_guid = create_org |
| 22 | + space_guid = create_space(org_guid) |
| 23 | + |
16 | 24 | post '/v3/service_brokers', create_service_broker_request_body.to_json, admin_headers |
17 | 25 | expect(last_response).to have_status_code(202) |
18 | 26 | execute_all_jobs(expected_successes: 1, expected_failures: 0) |
19 | 27 |
|
20 | | - get '/v3/service_offerings', nil, admin_headers |
21 | | - expect(last_response).to have_status_code(200) |
22 | | - expect(parsed_response['resources'][0]).to include( |
| 28 | + service_offerings = get_service_offerings |
| 29 | + expect(service_offerings[0]).to include( |
23 | 30 | 'name' => 'service_name-1' |
24 | 31 | ) |
25 | | - expect(parsed_response['resources'][1]).to include( |
| 32 | + expect(service_offerings[1]).to include( |
26 | 33 | 'name' => 'route_volume_service_name-2' |
27 | 34 | ) |
28 | 35 |
|
29 | | - get '/v3/service_plans', nil, admin_headers |
30 | | - expect(last_response).to have_status_code(200) |
31 | | - expect(parsed_response['resources'][0]).to include( |
| 36 | + plans = get_service_plans using: admin_headers |
| 37 | + expect(plans[0]).to include( |
32 | 38 | 'name' => 'plan_name-1' |
33 | 39 | ) |
34 | | - expect(parsed_response['resources'][1]).to include( |
| 40 | + expect(plans[1]).to include( |
35 | 41 | 'name' => 'plan_name-2' |
36 | 42 | ) |
| 43 | + plan_guid = plans[0]['guid'] |
| 44 | + |
| 45 | + expect( |
| 46 | + get_service_plans(using: empty_headers) |
| 47 | + ).to have(0).elements |
37 | 48 |
|
38 | | - plan_guid = parsed_response['resources'][0]['guid'] |
| 49 | + make_plan_visible plan_guid |
39 | 50 |
|
40 | | - get '/v3/service_plans', nil, {} |
| 51 | + expect( |
| 52 | + get_service_plans(using: empty_headers) |
| 53 | + ).to have(1).elements |
| 54 | + |
| 55 | + job_location = create_service_instance(space_guid, plan_guid) |
| 56 | + |
| 57 | + service_instance_location = |
| 58 | + wait_for_service_instance_to_be_created(job_location) |
| 59 | + |
| 60 | + get service_instance_location, nil, admin_headers |
41 | 61 | expect(last_response).to have_status_code(200) |
42 | | - expect(parsed_response['resources']).to have(0).elements |
43 | 62 |
|
44 | | - post "v3/service_plans/#{plan_guid}/visibility", visibility_request.to_json, admin_headers |
| 63 | + service_instances = get_all_service_instances |
| 64 | + expect(service_instances[0]).to include( |
| 65 | + 'name' => service_instance_name |
| 66 | + ) |
| 67 | + |
| 68 | + # TODO: bind a service instance once those endpoints are written |
| 69 | + end |
| 70 | + |
| 71 | + def create_org |
| 72 | + org_request_body = { name: 'my-organization' } |
| 73 | + |
| 74 | + post '/v3/organizations', org_request_body.to_json, admin_headers |
| 75 | + expect(last_response).to have_status_code(201) |
| 76 | + parsed_response['guid'] |
| 77 | + end |
| 78 | + |
| 79 | + def create_space(org_guid) |
| 80 | + space_request_body = { |
| 81 | + name: 'my-space', |
| 82 | + relationships: { |
| 83 | + organization: { |
| 84 | + data: { |
| 85 | + guid: org_guid |
| 86 | + } |
| 87 | + } |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + post '/v3/spaces', space_request_body.to_json, admin_headers |
| 92 | + expect(last_response).to have_status_code(201) |
| 93 | + parsed_response['guid'] |
| 94 | + end |
| 95 | + |
| 96 | + def get_service_offerings |
| 97 | + get '/v3/service_offerings', nil, admin_headers |
45 | 98 | expect(last_response).to have_status_code(200) |
| 99 | + parsed_response['resources'] |
| 100 | + end |
| 101 | + |
| 102 | + def get_service_plans(using:) |
| 103 | + headers = using |
| 104 | + get '/v3/service_plans', nil, headers |
| 105 | + expect(last_response).to have_status_code(200) |
| 106 | + |
| 107 | + parsed_response['resources'] |
| 108 | + end |
46 | 109 |
|
47 | | - get '/v3/service_plans', nil, {} |
| 110 | + def make_plan_visible(plan_guid) |
| 111 | + post "v3/service_plans/#{plan_guid}/visibility", visibility_request.to_json, admin_headers |
48 | 112 | expect(last_response).to have_status_code(200) |
49 | | - expect(parsed_response['resources']).to have(1).elements |
50 | 113 |
|
51 | 114 | get "v3/service_plans/#{plan_guid}/visibility", nil, admin_headers |
52 | 115 | expect(last_response).to have_status_code(200) |
53 | 116 | expect(parsed_response['type']).to eq('public') |
| 117 | + end |
| 118 | + |
| 119 | + def create_service_instance(space_guid, plan_guid) |
| 120 | + create_service_instance_request_body = { |
| 121 | + name: service_instance_name, |
| 122 | + relationships: { |
| 123 | + service_plan: { |
| 124 | + data: { |
| 125 | + guid: plan_guid |
| 126 | + } |
| 127 | + }, |
| 128 | + space: { |
| 129 | + data: { |
| 130 | + guid: space_guid |
| 131 | + } |
| 132 | + } |
| 133 | + }, |
| 134 | + type: 'managed' |
| 135 | + } |
| 136 | + |
| 137 | + post '/v3/service_instances', create_service_instance_request_body.to_json, admin_headers |
| 138 | + expect(last_response).to have_status_code(202) |
| 139 | + last_response.headers['Location'] |
| 140 | + end |
| 141 | + |
| 142 | + def wait_for_service_instance_to_be_created(job_location) |
| 143 | + get job_location, nil, admin_headers |
| 144 | + expect(last_response).to have_status_code(200) |
| 145 | + expect(parsed_response['state']).to eql('PROCESSING') |
| 146 | + |
| 147 | + execute_all_jobs(expected_successes: 1, expected_failures: 0) |
54 | 148 |
|
55 | | - # TODO: create a service instance once those endpoints are written |
| 149 | + get job_location, nil, admin_headers |
| 150 | + expect(last_response).to have_status_code(200) |
| 151 | + expect(parsed_response['state']).to eql('COMPLETE') |
| 152 | + |
| 153 | + parsed_response['links']['service_instances']['href'] |
56 | 154 | end |
57 | 155 |
|
| 156 | + def get_all_service_instances |
| 157 | + get '/v3/service_instances', nil, admin_headers |
| 158 | + expect(last_response).to have_status_code(200) |
| 159 | + parsed_response['resources'] |
| 160 | + end |
| 161 | + |
| 162 | + let(:service_instance_name) { 'my-service-instance' } |
| 163 | + |
58 | 164 | let(:visibility_request) do |
59 | 165 | { |
60 | 166 | type: 'public' |
61 | 167 | } |
62 | 168 | end |
63 | 169 |
|
| 170 | + let(:create_service_broker_request_body) do |
| 171 | + { |
| 172 | + name: 'amazing-service-broker', |
| 173 | + url: 'http://example.org/amazing-service-broker', |
| 174 | + authentication: { |
| 175 | + type: 'basic', |
| 176 | + credentials: { |
| 177 | + username: 'admin', |
| 178 | + password: 'password', |
| 179 | + } |
| 180 | + }, |
| 181 | + metadata: { |
| 182 | + labels: { to_update: 'value', to_delete: 'value', 'to.delete/with_prefix' => 'value' }, |
| 183 | + annotations: { to_update: 'value', to_delete: 'value', 'to.delete/with_prefix' => 'value' } |
| 184 | + } |
| 185 | + } |
| 186 | + end |
| 187 | + |
| 188 | + let(:empty_headers) do |
| 189 | + {} |
| 190 | + end |
| 191 | + |
64 | 192 | let(:create_service_broker_request_body) do |
65 | 193 | { |
66 | 194 | name: 'amazing-service-broker', |
|
115 | 243 | }.to_json |
116 | 244 | end |
117 | 245 | end |
| 246 | +# rubocop:enable Naming/AccessorMethodName |
0 commit comments