vmware-vra 2.7.2 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -1
  3. data/CHANGELOG.md +5 -0
  4. data/README.md +79 -144
  5. data/Rakefile +0 -11
  6. data/lib/vra/catalog.rb +39 -8
  7. data/lib/vra/catalog_base.rb +62 -0
  8. data/lib/vra/catalog_item.rb +28 -74
  9. data/lib/vra/catalog_source.rb +116 -0
  10. data/lib/vra/catalog_type.rb +56 -0
  11. data/lib/vra/client.rb +62 -54
  12. data/lib/vra/deployment.rb +155 -0
  13. data/lib/vra/deployment_request.rb +117 -0
  14. data/lib/vra/{resources.rb → deployments.rb} +26 -17
  15. data/lib/vra/exceptions.rb +1 -1
  16. data/lib/vra/http.rb +11 -6
  17. data/lib/vra/request.rb +28 -36
  18. data/lib/vra/request_parameters.rb +12 -12
  19. data/lib/vra/resource.rb +32 -203
  20. data/lib/vra/version.rb +2 -2
  21. data/lib/vra.rb +15 -12
  22. data/spec/catalog_item_spec.rb +64 -222
  23. data/spec/catalog_source_spec.rb +178 -0
  24. data/spec/catalog_spec.rb +112 -72
  25. data/spec/catalog_type_spec.rb +114 -0
  26. data/spec/client_spec.rb +271 -226
  27. data/spec/deployment_request_spec.rb +192 -0
  28. data/spec/deployment_spec.rb +227 -0
  29. data/spec/deployments_spec.rb +80 -0
  30. data/spec/fixtures/resource/sample_catalog_item.json +18 -0
  31. data/spec/fixtures/resource/sample_catalog_item_2.json +18 -0
  32. data/spec/fixtures/resource/sample_catalog_source.json +20 -0
  33. data/spec/fixtures/resource/sample_catalog_type.json +49 -0
  34. data/spec/fixtures/resource/sample_dep_actions.json +58 -0
  35. data/spec/fixtures/resource/sample_dep_request.json +19 -0
  36. data/spec/fixtures/resource/sample_dep_resource.json +112 -0
  37. data/spec/fixtures/resource/sample_deployment.json +26 -0
  38. data/spec/fixtures/resource/sample_entitlements.json +25 -0
  39. data/spec/http_spec.rb +63 -61
  40. data/spec/request_spec.rb +62 -68
  41. data/spec/resource_spec.rb +71 -390
  42. data/spec/spec_helper.rb +10 -4
  43. data/vmware-vra.gemspec +0 -1
  44. metadata +40 -30
  45. data/.travis.yml +0 -14
  46. data/lib/vra/catalog_request.rb +0 -137
  47. data/lib/vra/requests.rb +0 -41
  48. data/spec/catalog_request_spec.rb +0 -268
  49. data/spec/requests_spec.rb +0 -60
  50. data/spec/resources_spec.rb +0 -71
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  #
3
3
  # Author:: Chef Partner Engineering (<partnereng@chef.io>)
4
- # Copyright:: Copyright (c) 2015 Chef Software, Inc.
4
+ # Copyright:: Copyright (c) 2022 Chef Software, Inc.
5
5
  # License:: Apache License, Version 2.0
6
6
  #
7
7
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,267 +17,109 @@
17
17
  # limitations under the License.
18
18
  #
19
19
 
20
- require "spec_helper"
20
+ require 'spec_helper'
21
21
 
22
22
  describe Vra::CatalogItem do
23
23
  let(:client) do
24
- Vra::Client.new(username: "user@corp.local",
25
- password: "password",
26
- tenant: "tenant",
27
- base_url: "https://vra.corp.local")
24
+ Vra::Client.new(
25
+ username: 'user@corp.local',
26
+ password: 'password',
27
+ tenant: 'tenant',
28
+ base_url: 'https://vra.corp.local'
29
+ )
28
30
  end
29
31
 
30
- let(:catalog_id) { "9e98042e-5443-4082-afd5-ab5a32939bbc" }
32
+ let(:catalog_id) { '123456' }
31
33
 
32
34
  let(:catalog_item_payload) do
33
- {
34
- "@type" => "CatalogItem",
35
- "id" => "9e98042e-5443-4082-afd5-ab5a32939bbc",
36
- "version" => 2,
37
- "name" => "CentOS 6.6",
38
- "description" => "Blueprint for deploying a CentOS Linux development server",
39
- "status" => "PUBLISHED",
40
- "statusName" => "Published",
41
- "organization" => {
42
- "tenantRef" => "vsphere.local",
43
- "tenantLabel" => "vsphere.local",
44
- "subtenantRef" => "962ab3f9-858c-4483-a49f-fa97392c314b",
45
- "subtenantLabel" => "catalog_subtenant",
46
- },
47
- "providerBinding" => {
48
- "bindingId" => "33af5413-4f20-4b3b-8268-32edad434dfb",
49
- "providerRef" => {
50
- "id" => "c3b2bc30-47b0-454f-b57d-df02a7356fe6",
51
- "label" => "iaas-service",
52
- },
53
- },
54
- }
35
+ JSON.parse(File.read('spec/fixtures/resource/sample_catalog_item.json'))
55
36
  end
56
37
 
57
38
  let(:other_catalog_item_payload) do
58
- {
59
- "@type" => "CatalogItem",
60
- "id" => "3232323e-5443-4082-afd5-ab5a32939bbc",
61
- "version" => 2,
62
- "name" => "CentOS 6.6",
63
- "description" => "Blueprint for deploying a CentOS Linux development server",
64
- "status" => "PUBLISHED",
65
- "statusName" => "Published",
66
- "organization" => {
67
- "tenantRef" => "vsphere.local",
68
- "tenantLabel" => "vsphere.local",
69
- "subtenantRef" => "962ab3f9-858c-4483-a49f-fa97392c314b",
70
- "subtenantLabel" => "catalog_subtenant",
71
- },
72
- "providerBinding" => {
73
- "bindingId" => "33af5413-4f20-4b3b-8268-32edad434dfb",
74
- "providerRef" => {
75
- "id" => "c3b2bc30-47b0-454f-b57d-df02a7356fe6",
76
- "label" => "iaas-service",
77
- },
78
- },
79
- }
39
+ JSON.parse(File.read('spec/fixtures/resource/sample_catalog_item_2.json'))
80
40
  end
81
41
 
82
- describe "#initialize" do
83
- it "raises an error if no ID or catalog item data have been provided" do
84
- expect { Vra::CatalogItem.new }.to raise_error(ArgumentError)
42
+ describe '#initialize' do
43
+ it 'raises an error if no ID or catalog item data have been provided' do
44
+ expect { Vra::CatalogItem.new(client) }.to raise_error(ArgumentError)
85
45
  end
86
46
 
87
- it "raises an error if an ID and catalog item data have both been provided" do
88
- expect { Vra::CatalogItem.new(id: 123, data: "foo") }.to raise_error(ArgumentError)
47
+ it 'raises an error if an ID and catalog item data have both been provided' do
48
+ expect { Vra::CatalogItem.new(client, id: 123, data: 'foo') }.to raise_error(ArgumentError)
89
49
  end
90
50
 
91
- context "when an ID is provided" do
92
- it "fetches the catalog_item record" do
51
+ context 'when an ID is provided' do
52
+ it 'fetches the catalog_item record' do
93
53
  catalog_item = Vra::CatalogItem.allocate
94
54
  expect(catalog_item).to receive(:fetch_catalog_item)
95
55
  catalog_item.send(:initialize, client, id: catalog_id)
96
56
  end
97
57
  end
98
58
 
99
- context "when catalog item data is provided" do
100
- it "populates the ID correctly" do
59
+ context 'when catalog item data is provided' do
60
+ it 'populates the ID correctly' do
101
61
  catalog_item = Vra::CatalogItem.new(client, data: catalog_item_payload)
102
62
  expect(catalog_item.id).to eq catalog_id
103
63
  end
104
64
  end
105
65
  end
106
66
 
107
- describe "#fetch_catalog_item" do
108
- context "when the catalog item exists" do
109
- let(:response) { double("response", code: 200, body: catalog_item_payload.to_json) }
67
+ describe '#fetch_catalog_item' do
68
+ context 'when the catalog item exists' do
69
+ let(:response) { double('response', code: 200, body: catalog_item_payload.to_json) }
110
70
 
111
- it "calls http_get against the catalog_service" do
112
- expect(client).to receive(:http_get).with("/catalog-service/api/consumer/catalogItems/catalog-12345").and_return(response)
113
- Vra::CatalogItem.new(client, id: "catalog-12345")
71
+ it 'calls http_get against the catalog_service' do
72
+ expect(client).to receive(:http_get).with('/catalog/api/admin/items/catalog-12345').and_return(response)
73
+ Vra::CatalogItem.new(client, id: 'catalog-12345')
114
74
  end
115
75
  end
116
76
 
117
- context "when the catalog item does not exist" do
118
- it "raises an exception" do
119
- allow(client).to receive(:http_get).with("/catalog-service/api/consumer/catalogItems/catalog-12345").and_raise(Vra::Exception::HTTPNotFound)
120
- expect { Vra::CatalogItem.new(client, id: "catalog-12345") }.to raise_error(Vra::Exception::NotFound)
77
+ context 'when the catalog item does not exist' do
78
+ it 'raises an exception' do
79
+ allow(client)
80
+ .to receive(:http_get)
81
+ .with('/catalog/api/admin/items/catalog-12345')
82
+ .and_raise(Vra::Exception::HTTPNotFound)
83
+
84
+ expect { Vra::CatalogItem.new(client, id: 'catalog-12345') }
85
+ .to raise_error(Vra::Exception::NotFound)
86
+ .with_message('catalog ID catalog-12345 does not exist')
121
87
  end
122
88
  end
123
89
  end
124
90
 
125
- describe "#organization" do
126
- let(:catalog_item) { Vra::CatalogItem.new(client, data: catalog_item_payload) }
91
+ describe '#entitle!' do
92
+ it 'should entitle the catalog item' do
93
+ allow(client).to receive(:authorized?).and_return(true)
94
+ stub_request(:get, client.full_url('/catalog/api/admin/items/123456'))
95
+ .to_return(status: 200, body: catalog_item_payload.to_json, headers: {})
127
96
 
128
- context "when organization data exists" do
129
- let(:catalog_item_payload) do
130
- {
131
- "@type" => "CatalogItem",
132
- "id" => "9e98042e-5443-4082-afd5-ab5a32939bbc",
133
- "organization" => {
134
- "tenantRef" => "vsphere.local",
135
- "tenantLabel" => "vsphere.local",
136
- "subtenantRef" => "962ab3f9-858c-4483-a49f-fa97392c314b",
137
- "subtenantLabel" => "catalog_subtenant",
138
- },
139
- }
140
- end
97
+ response = double('response', body: '{"message": "success"}', success?: true)
98
+ allow(client).to receive(:http_post).and_return(response)
141
99
 
142
- it "returns the correct organization data" do
143
- expect(catalog_item.organization["tenantRef"]).to eq("vsphere.local")
144
- end
100
+ entitle_response = described_class.entitle!(client, '123456')
101
+ expect(entitle_response).not_to be_nil
145
102
  end
103
+ end
146
104
 
147
- context "when organization data does not exist" do
148
- let(:catalog_item_payload) do
149
- {
150
- "@type" => "CatalogItem",
151
- "id" => "9e98042e-5443-4082-afd5-ab5a32939bbc",
152
- }
153
- end
154
-
155
- it "returns an empty hash" do
156
- expect(catalog_item.organization).to eq({})
157
- end
158
-
159
- it "returns nil for any organization keys" do
160
- expect(catalog_item.organization["tenantRef"]).to eq(nil)
161
- end
162
- end
163
-
164
- describe "class methods" do
165
- let(:response) { double("response", code: 200, body: catalog_item_payload.to_json) }
166
-
167
- it "#dump_template" do
168
- expect(client).to receive(:http_get).with("/catalog-service/api/consumer/entitledCatalogItems/#{catalog_id}/requests/template")
169
- .and_return(response)
170
- described_class.dump_template(client, catalog_id )
171
- end
172
-
173
- it "#write_template" do
174
- allow(client).to receive(:http_get).with("/catalog-service/api/consumer/entitledCatalogItems/#{catalog_id}/requests/template")
175
- .and_return(response)
176
- expect(File).to receive(:write).with("9e98042e-5443-4082-afd5-ab5a32939bbc.json", JSON.pretty_generate(catalog_item_payload))
177
- expect(described_class.write_template(client, catalog_id)).to eq("9e98042e-5443-4082-afd5-ab5a32939bbc.json")
178
- end
179
-
180
- it "#write_template with custom filename" do
181
- allow(client).to receive(:http_get).with("/catalog-service/api/consumer/entitledCatalogItems/#{catalog_id}/requests/template")
182
- .and_return(response)
183
- expect(File).to receive(:write).with("somefile.json", JSON.pretty_generate(catalog_item_payload))
184
- expect(described_class.write_template(client, catalog_id, "somefile.json")).to eq("somefile.json")
185
- end
186
-
187
- context "entitled items" do
188
- let(:response2) { double("response", code: 200, body: other_catalog_item_payload.to_json) }
189
-
190
- let(:entitled_catalog_item) do
191
- {
192
- "@type" => "ConsumerEntitledCatalogItem",
193
- "catalogItem" => {
194
- "id" => "d29efd6b-3cd6-4f8d-b1d8-da4ddd4e52b1",
195
- "version" => 2,
196
- "name" => "WindowsServer2012",
197
- "description" => "Windows Server 2012 with the latest updates and patches.",
198
- "status" => "PUBLISHED",
199
- "statusName" => "Published",
200
- "organization" => {
201
- "tenantRef" => "vsphere.local",
202
- "tenantLabel" => "vsphere.local",
203
- "subtenantRef" => nil,
204
- "subtenantLabel" => nil,
205
- },
206
- "providerBinding" => {
207
- "bindingId" => "59fd02a1-acca-4918-9d3d-2298d310caef",
208
- "providerRef" => {
209
- "id" => "c3b2bc30-47b0-454f-b57d-df02a7356fe6",
210
- "label" => "iaas-service",
211
- },
212
- },
213
- },
214
- }
215
- end
216
-
217
- let(:entitled_catalog_item2) do
218
- {
219
- "@type" => "ConsumerEntitledCatalogItem",
220
- "catalogItem" => {
221
- "id" => "3232323e-5443-4082-afd5-ab5a32939bbc",
222
- "version" => 2,
223
- "name" => "WindowsServer2016",
224
- "description" => "Windows Server 2012 with the latest updates and patches.",
225
- "status" => "PUBLISHED",
226
- "statusName" => "Published",
227
- "organization" => {
228
- "tenantRef" => "vsphere.local",
229
- "tenantLabel" => "vsphere.local",
230
- "subtenantRef" => nil,
231
- "subtenantLabel" => nil,
232
- },
233
- "providerBinding" => {
234
- "bindingId" => "59fd02a1-acca-4918-9d3d-2298d310caef",
235
- "providerRef" => {
236
- "id" => "c3b2bc30-47b0-454f-b57d-df02a7356fe6",
237
- "label" => "iaas-service",
238
- },
239
- },
240
- },
241
- }
242
- end
243
-
244
- before(:each) do
245
- allow(client).to receive(:http_get_paginated_array!).with("/catalog-service/api/consumer/entitledCatalogItems")
246
- .and_return([ entitled_catalog_item, entitled_catalog_item2 ])
247
- allow(client).to receive(:http_get)
248
- .with("/catalog-service/api/consumer/entitledCatalogItems/d29efd6b-3cd6-4f8d-b1d8-da4ddd4e52b1/requests/template")
249
- .and_return(response)
250
- allow(client).to receive(:http_get)
251
- .with("/catalog-service/api/consumer/entitledCatalogItems/3232323e-5443-4082-afd5-ab5a32939bbc/requests/template")
252
- .and_return(response)
253
- allow(File).to receive(:write).with("vra_templates/d29efd6b-3cd6-4f8d-b1d8-da4ddd4e52b1.json", JSON.pretty_generate(catalog_item_payload))
254
- allow(File).to receive(:write).with("vra_templates/3232323e-5443-4082-afd5-ab5a32939bbc.json", JSON.pretty_generate(catalog_item_payload))
255
- allow(File).to receive(:write).with("vra_templates/windowsserver2012.json", JSON.pretty_generate(catalog_item_payload))
256
- allow(File).to receive(:write).with("vra_templates/windowsserver2016.json", JSON.pretty_generate(catalog_item_payload))
257
- allow(File).to receive(:write).with("custom_dir/windowsserver2012.json", JSON.pretty_generate(catalog_item_payload))
258
- allow(File).to receive(:write).with("custom_dir/windowsserver2016.json", JSON.pretty_generate(catalog_item_payload))
259
-
260
- end
261
-
262
- it "#dump_templates" do
263
- expect(described_class.dump_templates(client)).to eq(["vra_templates/windowsserver2012.json",
264
- "vra_templates/windowsserver2016.json"])
265
- end
266
-
267
- it "#dump_templates with custom directory" do
268
- expect(described_class.dump_templates(client, "custom_dir")).to eq(["custom_dir/windowsserver2012.json",
269
- "custom_dir/windowsserver2016.json"])
270
- end
271
-
272
- it "#dump_templates with id" do
273
- expect(described_class.dump_templates(client, "vra_templates", true))
274
- .to eq(["vra_templates/d29efd6b-3cd6-4f8d-b1d8-da4ddd4e52b1.json",
275
- "vra_templates/3232323e-5443-4082-afd5-ab5a32939bbc.json"])
276
-
277
- end
278
- end
279
-
105
+ describe '#attributes' do
106
+ it 'should have the correct attributes' do
107
+ allow(client).to receive(:authorized?).and_return(true)
108
+ stub_request(:get, client.full_url('/catalog/api/admin/sources/source-123456'))
109
+ .to_return(
110
+ status: 200,
111
+ body: File.read('spec/fixtures/resource/sample_catalog_source.json'),
112
+ headers: {}
113
+ )
114
+ catalog_item = described_class.new(client, data: catalog_item_payload)
115
+
116
+ expect(catalog_item.name).to eq('centos')
117
+ expect(catalog_item.description).to eq('Centos Cat')
118
+ expect(catalog_item.source_id).to eq('source-123456')
119
+ expect(catalog_item.source_name).to eq('Source 123')
120
+ expect(catalog_item.icon_id).to eq('1495b8d9')
121
+ expect(catalog_item.source).to be_a(Vra::CatalogSource)
122
+ expect(catalog_item.type).to be_a(Vra::CatalogType)
280
123
  end
281
-
282
124
  end
283
125
  end
@@ -0,0 +1,178 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Author:: Ashique Saidalavi (<ashique.saidalavi@progress.com>)
4
+ # Copyright:: Copyright (c) 2022 Chef Software, Inc.
5
+ # License:: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+ require 'spec_helper'
20
+
21
+ describe Vra::CatalogSource do
22
+ let(:client) do
23
+ Vra::Client.new(
24
+ username: 'user@corp.local',
25
+ password: 'password',
26
+ tenant: 'tenant',
27
+ base_url: 'https://vra.corp.local'
28
+ )
29
+ end
30
+
31
+ let(:sample_data) do
32
+ JSON.parse(File.read('spec/fixtures/resource/sample_catalog_source.json'))
33
+ end
34
+
35
+ describe '#initialize' do
36
+ let(:source) do
37
+ described_class.allocate
38
+ end
39
+
40
+ before(:each) do
41
+ allow(client).to receive(:get_parsed).and_return(sample_data)
42
+ end
43
+
44
+ it 'should validate and fetch data' do
45
+ expect(source).to receive(:validate!)
46
+ expect(source).to receive(:fetch_data)
47
+
48
+ source.send(:initialize, client, id: '123456')
49
+ end
50
+
51
+ it 'should fetch data when id is passed' do
52
+ source.send(:initialize, client, id: '123456')
53
+
54
+ expect(source.send(:data)).not_to be_nil
55
+ end
56
+
57
+ it 'should set id when data is passed' do
58
+ source.send(:initialize, client, data: sample_data)
59
+
60
+ expect(source.id).to eq('123456')
61
+ end
62
+ end
63
+
64
+ describe '#validate' do
65
+ let(:source) do
66
+ described_class.allocate
67
+ end
68
+
69
+ it 'should raise exception when neither id nor data passed' do
70
+ expect { source.send(:initialize, client) }.to raise_error(ArgumentError)
71
+ end
72
+
73
+ it 'should raise exception when both id and data is passed' do
74
+ params = [client, { id: 'com.vmw.vra.workflow', data: sample_data }]
75
+ expect { source.send(:initialize, *params) }.to raise_error(ArgumentError)
76
+ end
77
+ end
78
+
79
+ describe '#fetch_data' do
80
+ let(:source) do
81
+ described_class.allocate
82
+ end
83
+
84
+ it 'should fetch the data correctly' do
85
+ allow(client).to receive(:get_parsed).and_return(sample_data)
86
+ source.send(:initialize, client, id: '123456')
87
+
88
+ data = source.send(:data)
89
+ expect(data).to be(sample_data)
90
+ expect(source.id).to eq(data['id'])
91
+ expect(data['name']).to eq('Devops')
92
+ end
93
+
94
+ it 'should raise when catalog with id not found' do
95
+ allow(client).to receive(:get_parsed).and_raise(Vra::Exception::HTTPNotFound)
96
+
97
+ expect { source.send(:initialize, client, id: sample_data['id']) }
98
+ .to raise_error(Vra::Exception::NotFound)
99
+ .with_message("catalog source ID #{sample_data['id']} does not exist")
100
+ end
101
+ end
102
+
103
+ describe 'attributes' do
104
+ let(:sample_type_data) do
105
+ JSON.parse(File.read('spec/fixtures/resource/sample_catalog_type.json'))
106
+ end
107
+
108
+ it 'should have the correct attributes' do
109
+ allow(client).to receive(:get_parsed).twice.and_return(sample_data, sample_type_data)
110
+
111
+ source = described_class.new(client, id: sample_data['id'])
112
+ expect(source.name).to eq('Devops')
113
+ expect(source.catalog_type_id).to eq('com.vmw.blueprint')
114
+ expect(source.catalog_type).to be_a(Vra::CatalogType)
115
+ expect(source.config).to eq({ 'sourceProjectId' => 'pro-123456'})
116
+ expect(source.global?).to be_falsey
117
+ expect(source.project_id).to eq('pro-123456')
118
+ end
119
+ end
120
+
121
+ describe '#create' do
122
+ let(:create_params) do
123
+ {
124
+ name: 'Devops',
125
+ catalog_type_id: 'com.vmw.blueprint',
126
+ project_id: 'pro-123456'
127
+ }
128
+ end
129
+
130
+ before(:each) do
131
+ allow(client).to receive(:authorized?).and_return(true)
132
+ end
133
+
134
+ it 'should call the create api' do
135
+ response = double('response', code: 200, body: sample_data.to_json, success?: true)
136
+ expect(Vra::Http).to receive(:execute)
137
+ .with(method: :post,
138
+ url: client.full_url('/catalog/api/admin/sources'),
139
+ payload: {
140
+ name: 'Devops',
141
+ typeId: 'com.vmw.blueprint',
142
+ config: {
143
+ sourceProjectId: 'pro-123456'
144
+ }
145
+ }.to_json,
146
+ headers: anything,
147
+ verify_ssl: true)
148
+ .and_return(response)
149
+
150
+ described_class.create(client, create_params)
151
+ end
152
+
153
+ it 'should create a new source' do
154
+ response = double('response', code: 200, body: sample_data.to_json, success?: true)
155
+ allow(Vra::Http).to receive(:execute).and_return(response)
156
+
157
+ new_source = described_class.create(client, create_params)
158
+
159
+ expect(new_source).to be_a(described_class)
160
+ expect(new_source.name).to eq('Devops')
161
+ expect(new_source.project_id).to eq('pro-123456')
162
+ end
163
+ end
164
+
165
+ describe '#entitle!' do
166
+ it 'should entitle the source' do
167
+ allow(client).to receive(:authorized?).and_return(true)
168
+ stub_request(:get, client.full_url('/catalog/api/admin/sources/123456'))
169
+ .to_return(status: 200, body: sample_data.to_json, headers: {})
170
+
171
+ response = double('response', body: '{"message": "success"}', success?: true)
172
+ allow(client).to receive(:http_post).and_return(response)
173
+
174
+ entitle_response = described_class.entitle!(client, '123456')
175
+ expect(entitle_response).not_to be_nil
176
+ end
177
+ end
178
+ end