vmware-vra 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/spec/http_spec.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
- require 'spec_helper'
3
- require 'webmock'
2
+ require "spec_helper"
3
+ require "webmock"
4
4
 
5
5
  describe Vra::Http do
6
- def expecting_request(method, url, with=nil)
6
+ def expecting_request(method, url, with = nil)
7
7
  stub = stub_request(method, url)
8
8
  stub.with(with) if with
9
9
  yield if block_given?
@@ -26,114 +26,114 @@ describe Vra::Http do
26
26
  execute :head, params
27
27
  end
28
28
 
29
- describe '#execute' do
30
- it 'makes a HEAD request' do
31
- headers = { 'X-Made-Up-Header' => 'Foo AND bar? Are you sure?' }
29
+ describe "#execute" do
30
+ it "makes a HEAD request" do
31
+ headers = { "X-Made-Up-Header" => "Foo AND bar? Are you sure?" }
32
32
 
33
- expecting_request(:head, 'http://test.local', headers: headers) do
34
- head url: 'http://test.local', headers: headers
33
+ expecting_request(:head, "http://test.local", headers: headers) do
34
+ head url: "http://test.local", headers: headers
35
35
  end
36
36
  end
37
37
 
38
- it 'makes a GET request' do
39
- headers = { 'X-Made-Up-Header' => 'Foo AND bar? Are you sure?' }
38
+ it "makes a GET request" do
39
+ headers = { "X-Made-Up-Header" => "Foo AND bar? Are you sure?" }
40
40
 
41
- expecting_request(:get, 'http://test.local', headers: headers) do
42
- get url: 'http://test.local', headers: headers
41
+ expecting_request(:get, "http://test.local", headers: headers) do
42
+ get url: "http://test.local", headers: headers
43
43
  end
44
44
  end
45
45
 
46
- it 'makes a POST request' do
47
- headers = { 'X-Made-Up-Header' => 'Foo AND bar? Are you sure?' }
48
- payload = 'withabodylikethis'
46
+ it "makes a POST request" do
47
+ headers = { "X-Made-Up-Header" => "Foo AND bar? Are you sure?" }
48
+ payload = "withabodylikethis"
49
49
 
50
- expecting_request(:post, 'http://test.local', headers: headers, body: payload) do
51
- post url: 'http://test.local', headers: headers, payload: payload
50
+ expecting_request(:post, "http://test.local", headers: headers, body: payload) do
51
+ post url: "http://test.local", headers: headers, payload: payload
52
52
  end
53
53
  end
54
54
 
55
- it 'preserves Location' do
56
- stub_request(:head, 'http://test.local')
57
- .to_return(headers: { 'Location' => 'http://test-location.local' })
55
+ it "preserves Location" do
56
+ stub_request(:head, "http://test.local")
57
+ .to_return(headers: { "Location" => "http://test-location.local" })
58
58
 
59
- response = head(url: 'http://test.local')
59
+ response = head(url: "http://test.local")
60
60
 
61
- expect(response.location).to eq 'http://test-location.local'
61
+ expect(response.location).to eq "http://test-location.local"
62
62
  end
63
63
 
64
- it 'preserves status code' do
65
- stub_request(:head, 'http://test.local')
66
- .to_return(status: [204, 'No content'])
64
+ it "preserves status code" do
65
+ stub_request(:head, "http://test.local")
66
+ .to_return(status: [204, "No content"])
67
67
 
68
- response = head(url: 'http://test.local')
68
+ response = head(url: "http://test.local")
69
69
 
70
70
  expect(response.code).to eq 204
71
71
  end
72
72
 
73
- it 'configures ssl verification' do
73
+ it "configures ssl verification" do
74
74
  allow(Net::HTTP).to receive(:start).and_wrap_original do |_http, *args|
75
75
  expect(args.last).to include(verify_mode: OpenSSL::SSL::VERIFY_NONE)
76
- double('response', final?: true, success?: true)
76
+ double("response", final?: true, success?: true)
77
77
  end
78
78
 
79
- execute(:get, url: 'https://test.local', verify_ssl: false)
79
+ execute(:get, url: "https://test.local", verify_ssl: false)
80
80
  end
81
81
 
82
- context 'when successful' do
83
- it 'returns a successful response given a status 200' do
84
- stub_request(:head, 'http://test.local')
85
- .to_return(status: [200, 'Whatevs'])
82
+ context "when successful" do
83
+ it "returns a successful response given a status 200" do
84
+ stub_request(:head, "http://test.local")
85
+ .to_return(status: [200, "Whatevs"])
86
86
 
87
- response = head(url: 'http://test.local')
87
+ response = head(url: "http://test.local")
88
88
 
89
89
  expect(response.success_ok?).to be_truthy
90
90
  end
91
91
 
92
- it 'returns a successful response given a status 204' do
93
- stub_request(:head, 'http://test.local')
94
- .to_return(status: [204, 'Whatevs'])
92
+ it "returns a successful response given a status 204" do
93
+ stub_request(:head, "http://test.local")
94
+ .to_return(status: [204, "Whatevs"])
95
95
 
96
- response = head(url: 'http://test.local')
96
+ response = head(url: "http://test.local")
97
97
 
98
98
  expect(response.success_no_content?).to be_truthy
99
99
  end
100
100
  end
101
101
 
102
- context 'when unsuccessful' do
102
+ context "when unsuccessful" do
103
103
  (400..418).each do |status|
104
104
  it 'raises an exception given a status #{status}' do
105
- stub_request(:get, 'http://test.local')
106
- .to_return(status: [status, 'Whatevs'],
107
- body: 'Error body')
105
+ stub_request(:get, "http://test.local")
106
+ .to_return(status: [status, "Whatevs"],
107
+ body: "Error body")
108
108
 
109
- expect { get(url: 'http://test.local') }.to raise_error do |error|
109
+ expect { get(url: "http://test.local") }.to raise_error do |error|
110
110
  expect(error).to be_a(StandardError)
111
111
  expect(error.http_code).to eq status
112
- expect(error.response).to eq 'Error body'
112
+ expect(error.response).to eq "Error body"
113
113
  end
114
114
  end
115
115
  end
116
116
  end
117
117
 
118
- context 'when redirected' do
118
+ context "when redirected" do
119
119
  [301, 302, 307].each do |status|
120
120
  [:get, :head].each do |method|
121
121
  it "follows #{status} redirected #{method.to_s.upcase} requests" do
122
- stub_request(method, 'http://test.local')
123
- .to_return(status: [status, 'redirect'],
124
- headers: { 'Location' => 'http://test.local/redirect' })
125
- expecting_request(method, 'http://test.local/redirect') do
126
- execute(method, url: 'http://test.local')
122
+ stub_request(method, "http://test.local")
123
+ .to_return(status: [status, "redirect"],
124
+ headers: { "Location" => "http://test.local/redirect" })
125
+ expecting_request(method, "http://test.local/redirect") do
126
+ execute(method, url: "http://test.local")
127
127
  end
128
128
  end
129
129
  end
130
130
 
131
131
  it "does not follow #{status} redirected POST requests" do
132
- stub_request(:post, 'http://test.local')
133
- .to_return(status: [status, 'redirect'],
134
- headers: { 'Location' => 'http://test.local/redirect' })
132
+ stub_request(:post, "http://test.local")
133
+ .to_return(status: [status, "redirect"],
134
+ headers: { "Location" => "http://test.local/redirect" })
135
135
 
136
- expect { post(url: 'http://test.local') }.to raise_error do |error|
136
+ expect { post(url: "http://test.local") }.to raise_error do |error|
137
137
  expect(error).to be_a(StandardError)
138
138
  expect(error.http_code).to eq status
139
139
  end
@@ -142,12 +142,12 @@ describe Vra::Http do
142
142
 
143
143
  [:head, :post].each do |method|
144
144
  it "converts #{method.to_s.upcase} to GET on 303 redirect" do
145
- stub_request(method, 'http://test.local')
146
- .to_return(status: [303, 'See Other'],
147
- headers: { 'Location' => 'http://test.local/redirect' })
145
+ stub_request(method, "http://test.local")
146
+ .to_return(status: [303, "See Other"],
147
+ headers: { "Location" => "http://test.local/redirect" })
148
148
 
149
- expecting_request(:get, 'http://test.local/redirect') do
150
- execute method, url: 'http://test.local'
149
+ expecting_request(:get, "http://test.local/redirect") do
150
+ execute method, url: "http://test.local"
151
151
  end
152
152
  end
153
153
  end
data/spec/request_spec.rb CHANGED
@@ -17,15 +17,15 @@
17
17
  # limitations under the License.
18
18
  #
19
19
 
20
- require 'spec_helper'
20
+ require "spec_helper"
21
21
 
22
- shared_examples 'refresh_trigger_method' do |method|
23
- it 'calls #refresh_if_needed' do
22
+ shared_examples "refresh_trigger_method" do |method|
23
+ it "calls #refresh_if_needed" do
24
24
  expect(request).to receive(:refresh_if_empty)
25
25
  request.send(method)
26
26
  end
27
27
 
28
- it 'returns nil if request data is empty' do
28
+ it "returns nil if request data is empty" do
29
29
  allow(request).to receive(:refresh_if_empty)
30
30
  allow(request).to receive(:request_empty?).and_return true
31
31
  expect(request.send(method)).to eq nil
@@ -34,44 +34,44 @@ end
34
34
 
35
35
  describe Vra::Request do
36
36
  let(:client) do
37
- Vra::Client.new(username: 'user@corp.local',
38
- password: 'password',
39
- tenant: 'tenant',
40
- base_url: 'https://vra.corp.local')
37
+ Vra::Client.new(username: "user@corp.local",
38
+ password: "password",
39
+ tenant: "tenant",
40
+ base_url: "https://vra.corp.local")
41
41
  end
42
42
 
43
- let(:request_id) { '2c3df007-b1c4-4687-b332-310089c4851d' }
43
+ let(:request_id) { "2c3df007-b1c4-4687-b332-310089c4851d" }
44
44
 
45
45
  let(:in_progress_payload) do
46
46
  {
47
- 'phase' => 'IN_PROGRESS',
48
- 'requestCompletion' => {
49
- 'requestCompletionState' => nil,
50
- 'completionDetails' => nil
51
- }
47
+ "phase" => "IN_PROGRESS",
48
+ "requestCompletion" => {
49
+ "requestCompletionState" => nil,
50
+ "completionDetails" => nil,
51
+ },
52
52
  }
53
53
  end
54
54
 
55
55
  let(:completed_payload) do
56
56
  {
57
- 'phase' => 'SUCCESSFUL',
58
- 'requestCompletion' => {
59
- 'requestCompletionState' => 'SUCCESSFUL',
60
- 'completionDetails' => 'Request succeeded. Created test-machine.'
61
- }
57
+ "phase" => "SUCCESSFUL",
58
+ "requestCompletion" => {
59
+ "requestCompletionState" => "SUCCESSFUL",
60
+ "completionDetails" => "Request succeeded. Created test-machine.",
61
+ },
62
62
  }
63
63
  end
64
64
 
65
65
  let(:request) { Vra::Request.new(client, request_id) }
66
66
 
67
- describe '#initialize' do
68
- it 'sets the id' do
67
+ describe "#initialize" do
68
+ it "sets the id" do
69
69
  expect(request.id).to eq request_id
70
70
  end
71
71
  end
72
72
 
73
- describe '#refresh' do
74
- it 'calls the request API endpoint' do
73
+ describe "#refresh" do
74
+ it "calls the request API endpoint" do
75
75
  expect(client).to receive(:get_parsed)
76
76
  .with("/catalog-service/api/consumer/requests/#{request_id}")
77
77
  .and_return(in_progress_payload)
@@ -80,45 +80,45 @@ describe Vra::Request do
80
80
  end
81
81
  end
82
82
 
83
- describe '#refresh_if_empty' do
84
- context 'request data is empty' do
85
- it 'calls #refresh' do
83
+ describe "#refresh_if_empty" do
84
+ context "request data is empty" do
85
+ it "calls #refresh" do
86
86
  expect(request).to receive(:refresh)
87
87
  request.refresh_if_empty
88
88
  end
89
89
  end
90
90
 
91
- context 'request data is not empty' do
92
- it 'does not call #refresh' do
91
+ context "request data is not empty" do
92
+ it "does not call #refresh" do
93
93
  allow(request).to receive(:request_empty?).and_return(false)
94
94
  expect(request).to_not receive(:refresh)
95
95
  end
96
96
  end
97
97
  end
98
98
 
99
- describe '#status' do
100
- it_behaves_like 'refresh_trigger_method', :status
99
+ describe "#status" do
100
+ it_behaves_like "refresh_trigger_method", :status
101
101
  end
102
102
 
103
- describe '#completed?' do
104
- context 'when the request is neither successful or failed yet' do
105
- it 'returns false' do
103
+ describe "#completed?" do
104
+ context "when the request is neither successful or failed yet" do
105
+ it "returns false" do
106
106
  allow(request).to receive(:successful?).and_return(false)
107
107
  allow(request).to receive(:failed?).and_return(false)
108
108
  expect(request.completed?).to eq false
109
109
  end
110
110
  end
111
111
 
112
- context 'when the request is successful' do
113
- it 'returns true' do
112
+ context "when the request is successful" do
113
+ it "returns true" do
114
114
  allow(request).to receive(:successful?).and_return(true)
115
115
  allow(request).to receive(:failed?).and_return(false)
116
116
  expect(request.completed?).to eq true
117
117
  end
118
118
  end
119
119
 
120
- context 'when the request failed' do
121
- it 'returns true' do
120
+ context "when the request failed" do
121
+ it "returns true" do
122
122
  allow(request).to receive(:successful?).and_return(false)
123
123
  allow(request).to receive(:failed?).and_return(true)
124
124
  expect(request.completed?).to eq true
@@ -126,16 +126,16 @@ describe Vra::Request do
126
126
  end
127
127
  end
128
128
 
129
- describe '#completion_state' do
130
- it_behaves_like 'refresh_trigger_method', :completion_state
129
+ describe "#completion_state" do
130
+ it_behaves_like "refresh_trigger_method", :completion_state
131
131
  end
132
132
 
133
- describe '#completion_details' do
134
- it_behaves_like 'refresh_trigger_method', :completion_details
133
+ describe "#completion_details" do
134
+ it_behaves_like "refresh_trigger_method", :completion_details
135
135
  end
136
136
 
137
- describe '#resources' do
138
- it 'calls the requests resources API endpoint' do
137
+ describe "#resources" do
138
+ it "calls the requests resources API endpoint" do
139
139
  expect(client).to receive(:http_get_paginated_array!)
140
140
  .with("/catalog-service/api/consumer/requests/#{request_id}/resources")
141
141
  .and_return([])
@@ -17,31 +17,31 @@
17
17
  # limitations under the License.
18
18
  #
19
19
 
20
- require 'spec_helper'
20
+ require "spec_helper"
21
21
 
22
22
  describe Vra::Requests 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(username: "user@corp.local",
25
+ password: "password",
26
+ tenant: "tenant",
27
+ base_url: "https://vra.corp.local")
28
28
  end
29
29
 
30
30
  let(:requests) { Vra::Requests.new(client) }
31
31
 
32
- describe '#all_resources' do
33
- it 'calls the requests API endpoint' do
32
+ describe "#all_resources" do
33
+ it "calls the requests API endpoint" do
34
34
  expect(client).to receive(:http_get_paginated_array!)
35
- .with('/catalog-service/api/consumer/requests')
35
+ .with("/catalog-service/api/consumer/requests")
36
36
  .and_return([])
37
37
 
38
38
  requests.all_requests
39
39
  end
40
40
 
41
- it 'returns an array of request objects' do
41
+ it "returns an array of request objects" do
42
42
  allow(client).to receive(:http_get_paginated_array!)
43
- .with('/catalog-service/api/consumer/requests')
44
- .and_return([ { 'id' => '1' }, { 'id' => '2' } ])
43
+ .with("/catalog-service/api/consumer/requests")
44
+ .and_return([ { "id" => "1" }, { "id" => "2" } ])
45
45
 
46
46
  items = requests.all_requests
47
47
 
@@ -50,11 +50,11 @@ describe Vra::Requests do
50
50
  end
51
51
  end
52
52
 
53
- describe '#by_id' do
54
- it 'returns a request object' do
55
- expect(Vra::Request).to receive(:new).with(client, '12345')
53
+ describe "#by_id" do
54
+ it "returns a request object" do
55
+ expect(Vra::Request).to receive(:new).with(client, "12345")
56
56
 
57
- requests.by_id('12345')
57
+ requests.by_id("12345")
58
58
  end
59
59
  end
60
60
  end
@@ -17,20 +17,20 @@
17
17
  # limitations under the License.
18
18
  #
19
19
 
20
- require 'spec_helper'
21
- require 'ffi_yajl'
22
-
23
- shared_examples_for 'a resource action' do |action_method, action_name|
24
- context 'when the action is available' do
25
- it 'calls gets the action ID and submits the request' do
26
- expect(resource).to receive(:action_id_by_name).with(action_name).and_return('action-123')
27
- expect(resource).to receive(:submit_action_request).with('action-123')
20
+ require "spec_helper"
21
+ require "ffi_yajl"
22
+
23
+ shared_examples_for "a resource action" do |action_method, action_name|
24
+ context "when the action is available" do
25
+ it "calls gets the action ID and submits the request" do
26
+ expect(resource).to receive(:action_id_by_name).with(action_name).and_return("action-123")
27
+ expect(resource).to receive(:submit_action_request).with("action-123")
28
28
  resource.send(action_method)
29
29
  end
30
30
  end
31
31
 
32
- context 'when the action is not available' do
33
- it 'raises an exception' do
32
+ context "when the action is not available" do
33
+ it "raises an exception" do
34
34
  expect(resource).to receive(:action_id_by_name).with(action_name).and_return nil
35
35
  expect { resource.send(action_method) }.to raise_error(Vra::Exception::NotFound)
36
36
  end
@@ -39,61 +39,61 @@ end
39
39
 
40
40
  describe Vra::Resource do
41
41
  let(:client) do
42
- Vra::Client.new(username: 'user@corp.local',
43
- password: 'password',
44
- tenant: 'tenant',
45
- base_url: 'https://vra.corp.local')
42
+ Vra::Client.new(username: "user@corp.local",
43
+ password: "password",
44
+ tenant: "tenant",
45
+ base_url: "https://vra.corp.local")
46
46
  end
47
47
 
48
- let(:resource_id) { '31a7badc-6562-458d-84f3-ec58d74a6953' }
48
+ let(:resource_id) { "31a7badc-6562-458d-84f3-ec58d74a6953" }
49
49
  let(:vm_payload) do
50
50
  FFI_Yajl::Parser.parse(File.read(File.join(File.dirname(__FILE__),
51
- 'fixtures',
52
- 'resource',
53
- 'vm_resource.json')))
51
+ "fixtures",
52
+ "resource",
53
+ "vm_resource.json")))
54
54
  end
55
55
 
56
56
  let(:vm_payload_no_ops) do
57
57
  FFI_Yajl::Parser.parse(File.read(File.join(File.dirname(__FILE__),
58
- 'fixtures',
59
- 'resource',
60
- 'vm_resource_no_operations.json')))
58
+ "fixtures",
59
+ "resource",
60
+ "vm_resource_no_operations.json")))
61
61
  end
62
62
 
63
63
  let(:non_vm_payload) do
64
64
  FFI_Yajl::Parser.parse(File.read(File.join(File.dirname(__FILE__),
65
- 'fixtures',
66
- 'resource',
67
- 'non_vm_resource.json')))
65
+ "fixtures",
66
+ "resource",
67
+ "non_vm_resource.json")))
68
68
  end
69
69
 
70
- describe '#initialize' do
71
- it 'raises an error if no ID or resource data have been provided' do
70
+ describe "#initialize" do
71
+ it "raises an error if no ID or resource data have been provided" do
72
72
  expect { Vra::Resource.new }.to raise_error(ArgumentError)
73
73
  end
74
74
 
75
- it 'raises an error if an ID and resource data have both been provided' do
76
- expect { Vra::Resource.new(id: 123, data: 'foo') }.to raise_error(ArgumentError)
75
+ it "raises an error if an ID and resource data have both been provided" do
76
+ expect { Vra::Resource.new(id: 123, data: "foo") }.to raise_error(ArgumentError)
77
77
  end
78
78
 
79
- context 'when an ID is provided' do
80
- it 'calls fetch_resource_data' do
79
+ context "when an ID is provided" do
80
+ it "calls fetch_resource_data" do
81
81
  resource = Vra::Resource.allocate
82
82
  expect(resource).to receive(:fetch_resource_data)
83
83
  resource.send(:initialize, client, id: resource_id)
84
84
  end
85
85
  end
86
86
 
87
- context 'when resource data is provided' do
88
- it 'populates the ID correctly' do
87
+ context "when resource data is provided" do
88
+ it "populates the ID correctly" do
89
89
  resource = Vra::Resource.new(client, data: vm_payload)
90
90
  expect(resource.id).to eq resource_id
91
91
  end
92
92
  end
93
93
  end
94
94
 
95
- describe '#fetch_resource_data' do
96
- it 'calls get_parsed against the resources API endpoint' do
95
+ describe "#fetch_resource_data" do
96
+ it "calls get_parsed against the resources API endpoint" do
97
97
  expect(client).to receive(:get_parsed)
98
98
  .with("/catalog-service/api/consumer/resources/#{resource_id}")
99
99
  .and_return({})
@@ -102,297 +102,297 @@ describe Vra::Resource do
102
102
  end
103
103
  end
104
104
 
105
- context 'when a valid VM resource instance has been created' do
105
+ context "when a valid VM resource instance has been created" do
106
106
  let(:resource) { Vra::Resource.new(client, data: vm_payload) }
107
107
 
108
- describe '#name' do
109
- it 'returns the correct name' do
110
- expect(resource.name).to eq 'hol-dev-11'
108
+ describe "#name" do
109
+ it "returns the correct name" do
110
+ expect(resource.name).to eq "hol-dev-11"
111
111
  end
112
112
  end
113
113
 
114
- describe '#description' do
115
- it 'returns the correct description' do
116
- expect(resource.description).to eq 'test-description'
114
+ describe "#description" do
115
+ it "returns the correct description" do
116
+ expect(resource.description).to eq "test-description"
117
117
  end
118
118
  end
119
119
 
120
- describe '#status' do
121
- it 'returns the correct status' do
122
- expect(resource.status).to eq 'ACTIVE'
120
+ describe "#status" do
121
+ it "returns the correct status" do
122
+ expect(resource.status).to eq "ACTIVE"
123
123
  end
124
124
  end
125
125
 
126
- describe '#vm?' do
127
- context 'when the resource type is Infrastructure.Virtual' do
128
- let(:resource_data) { { 'resourceTypeRef' => { 'id' => 'Infrastructure.Virtual' } } }
129
- it 'returns true' do
126
+ describe "#vm?" do
127
+ context "when the resource type is Infrastructure.Virtual" do
128
+ let(:resource_data) { { "resourceTypeRef" => { "id" => "Infrastructure.Virtual" } } }
129
+ it "returns true" do
130
130
  allow(resource).to receive(:resource_data).and_return(resource_data)
131
131
  expect(resource.vm?).to eq(true)
132
132
  end
133
133
  end
134
134
 
135
- context 'when the resource type is Infrastructure.Cloud' do
136
- let(:resource_data) { { 'resourceTypeRef' => { 'id' => 'Infrastructure.Cloud' } } }
137
- it 'returns true' do
135
+ context "when the resource type is Infrastructure.Cloud" do
136
+ let(:resource_data) { { "resourceTypeRef" => { "id" => "Infrastructure.Cloud" } } }
137
+ it "returns true" do
138
138
  allow(resource).to receive(:resource_data).and_return(resource_data)
139
139
  expect(resource.vm?).to eq(true)
140
140
  end
141
141
  end
142
142
 
143
- context 'when the resource type is an unknown type' do
144
- let(:resource_data) { { 'resourceTypeRef' => { 'id' => 'Infrastructure.Unknown' } } }
145
- it 'returns false' do
143
+ context "when the resource type is an unknown type" do
144
+ let(:resource_data) { { "resourceTypeRef" => { "id" => "Infrastructure.Unknown" } } }
145
+ it "returns false" do
146
146
  allow(resource).to receive(:resource_data).and_return(resource_data)
147
147
  expect(resource.vm?).to eq(false)
148
148
  end
149
149
  end
150
150
  end
151
151
 
152
- describe '#tenant_id' do
153
- it 'returns the correct tenant ID' do
154
- expect(resource.tenant_id).to eq 'vsphere.local'
152
+ describe "#tenant_id" do
153
+ it "returns the correct tenant ID" do
154
+ expect(resource.tenant_id).to eq "vsphere.local"
155
155
  end
156
156
  end
157
157
 
158
- describe '#tenant_name' do
159
- it 'returns the correct tenant name' do
160
- expect(resource.tenant_name).to eq 'vsphere.local'
158
+ describe "#tenant_name" do
159
+ it "returns the correct tenant name" do
160
+ expect(resource.tenant_name).to eq "vsphere.local"
161
161
  end
162
162
  end
163
163
 
164
- describe '#subtenant_id' do
165
- it 'returns the correct subtenant ID' do
166
- expect(resource.subtenant_id).to eq '5327ddd3-1a4e-4663-9e9d-63db86ffc8af'
164
+ describe "#subtenant_id" do
165
+ it "returns the correct subtenant ID" do
166
+ expect(resource.subtenant_id).to eq "5327ddd3-1a4e-4663-9e9d-63db86ffc8af"
167
167
  end
168
168
  end
169
169
 
170
- describe '#subtenant_name' do
171
- it 'returns the correct subtenant name' do
172
- expect(resource.subtenant_name).to eq 'Rainpole Developers'
170
+ describe "#subtenant_name" do
171
+ it "returns the correct subtenant name" do
172
+ expect(resource.subtenant_name).to eq "Rainpole Developers"
173
173
  end
174
174
  end
175
175
 
176
- describe '#owner_ids' do
177
- it 'returns the correct owner IDs' do
178
- expect(resource.owner_ids).to eq %w(user1@corp.local user2@corp.local)
176
+ describe "#owner_ids" do
177
+ it "returns the correct owner IDs" do
178
+ expect(resource.owner_ids).to eq %w{user1@corp.local user2@corp.local}
179
179
  end
180
180
  end
181
181
 
182
- describe '#owner_names' do
183
- it 'returns the correct owner names' do
184
- expect(resource.owner_names).to eq [ 'Joe User', 'Jane User' ]
182
+ describe "#owner_names" do
183
+ it "returns the correct owner names" do
184
+ expect(resource.owner_names).to eq [ "Joe User", "Jane User" ]
185
185
  end
186
186
  end
187
187
 
188
- describe '#machine_status' do
189
- context 'when no MachineStatus exists' do
190
- let(:resource_data) { { 'resourceData' => { 'entries' => [] } } }
188
+ describe "#machine_status" do
189
+ context "when no MachineStatus exists" do
190
+ let(:resource_data) { { "resourceData" => { "entries" => [] } } }
191
191
 
192
- it 'raises an exception' do
192
+ it "raises an exception" do
193
193
  allow(resource).to receive(:resource_data).and_return(resource_data)
194
194
  expect { resource.machine_status }.to raise_error(RuntimeError)
195
195
  end
196
196
  end
197
197
 
198
- context 'when MachineStatus Exists' do
198
+ context "when MachineStatus Exists" do
199
199
  let(:resource_data) do
200
200
  {
201
- 'resourceData' => {
202
- 'entries' => [
201
+ "resourceData" => {
202
+ "entries" => [
203
203
  {
204
- 'key' => 'MachineStatus',
205
- 'value' => { 'type' => 'string', 'value' => 'Off' }
206
- }
207
- ]
208
- }
204
+ "key" => "MachineStatus",
205
+ "value" => { "type" => "string", "value" => "Off" },
206
+ },
207
+ ],
208
+ },
209
209
  }
210
210
  end
211
211
 
212
- it 'returns the correct status value' do
212
+ it "returns the correct status value" do
213
213
  allow(resource).to receive(:resource_data).and_return(resource_data)
214
- expect(resource.machine_status).to eq('Off')
214
+ expect(resource.machine_status).to eq("Off")
215
215
  end
216
216
  end
217
217
  end
218
218
 
219
- describe '#machine_on?' do
220
- it 'returns true if the machine_status is On' do
221
- allow(resource).to receive(:machine_status).and_return('On')
219
+ describe "#machine_on?" do
220
+ it "returns true if the machine_status is On" do
221
+ allow(resource).to receive(:machine_status).and_return("On")
222
222
  expect(resource.machine_on?).to eq(true)
223
223
  end
224
224
 
225
- it 'returns false if the machine_status is not On' do
226
- allow(resource).to receive(:machine_status).and_return('Off')
225
+ it "returns false if the machine_status is not On" do
226
+ allow(resource).to receive(:machine_status).and_return("Off")
227
227
  expect(resource.machine_on?).to eq(false)
228
228
  end
229
229
  end
230
230
 
231
- describe '#machine_off?' do
232
- it 'returns true if the machine_status is Off' do
233
- allow(resource).to receive(:machine_status).and_return('Off')
231
+ describe "#machine_off?" do
232
+ it "returns true if the machine_status is Off" do
233
+ allow(resource).to receive(:machine_status).and_return("Off")
234
234
  expect(resource.machine_off?).to eq(true)
235
235
  end
236
236
 
237
- it 'returns false if the machine_status is not Off' do
238
- allow(resource).to receive(:machine_status).and_return('On')
237
+ it "returns false if the machine_status is not Off" do
238
+ allow(resource).to receive(:machine_status).and_return("On")
239
239
  expect(resource.machine_off?).to eq(false)
240
240
  end
241
241
  end
242
242
 
243
- describe '#machine_turning_on?' do
244
- it 'returns true if the machine_status is TurningOn' do
245
- allow(resource).to receive(:machine_status).and_return('TurningOn')
243
+ describe "#machine_turning_on?" do
244
+ it "returns true if the machine_status is TurningOn" do
245
+ allow(resource).to receive(:machine_status).and_return("TurningOn")
246
246
  expect(resource.machine_turning_on?).to eq(true)
247
247
  end
248
248
 
249
- it 'returns true if the machine_status is MachineActivated' do
250
- allow(resource).to receive(:machine_status).and_return('MachineActivated')
249
+ it "returns true if the machine_status is MachineActivated" do
250
+ allow(resource).to receive(:machine_status).and_return("MachineActivated")
251
251
  expect(resource.machine_turning_on?).to eq(true)
252
252
  end
253
253
 
254
- it 'returns false if the machine_status is not TurningOn' do
255
- allow(resource).to receive(:machine_status).and_return('On')
254
+ it "returns false if the machine_status is not TurningOn" do
255
+ allow(resource).to receive(:machine_status).and_return("On")
256
256
  expect(resource.machine_turning_on?).to eq(false)
257
257
  end
258
258
  end
259
259
 
260
- describe '#machine_turning_off?' do
261
- it 'returns true if the machine_status is TurningOff' do
262
- allow(resource).to receive(:machine_status).and_return('TurningOff')
260
+ describe "#machine_turning_off?" do
261
+ it "returns true if the machine_status is TurningOff" do
262
+ allow(resource).to receive(:machine_status).and_return("TurningOff")
263
263
  expect(resource.machine_turning_off?).to eq(true)
264
264
  end
265
265
 
266
- it 'returns true if the machine_status is ShuttingDown' do
267
- allow(resource).to receive(:machine_status).and_return('ShuttingDown')
266
+ it "returns true if the machine_status is ShuttingDown" do
267
+ allow(resource).to receive(:machine_status).and_return("ShuttingDown")
268
268
  expect(resource.machine_turning_off?).to eq(true)
269
269
  end
270
270
 
271
- it 'returns false if the machine_status is not TurningOff or ShuttingDown' do
272
- allow(resource).to receive(:machine_status).and_return('Off')
271
+ it "returns false if the machine_status is not TurningOff or ShuttingDown" do
272
+ allow(resource).to receive(:machine_status).and_return("Off")
273
273
  expect(resource.machine_turning_off?).to eq(false)
274
274
  end
275
275
  end
276
276
 
277
- describe '#machine_in_provisioned_state?' do
278
- it 'returns true if the machine_status is MachineProvisioned' do
279
- allow(resource).to receive(:machine_status).and_return('MachineProvisioned')
277
+ describe "#machine_in_provisioned_state?" do
278
+ it "returns true if the machine_status is MachineProvisioned" do
279
+ allow(resource).to receive(:machine_status).and_return("MachineProvisioned")
280
280
  expect(resource.machine_in_provisioned_state?).to eq(true)
281
281
  end
282
282
 
283
- it 'returns false if the machine_status is not MachineProvisioned' do
284
- allow(resource).to receive(:machine_status).and_return('On')
283
+ it "returns false if the machine_status is not MachineProvisioned" do
284
+ allow(resource).to receive(:machine_status).and_return("On")
285
285
  expect(resource.machine_in_provisioned_state?).to eq(false)
286
286
  end
287
287
  end
288
288
 
289
- describe '#network_interfaces' do
290
- it 'returns an array of 2 elements' do
289
+ describe "#network_interfaces" do
290
+ it "returns an array of 2 elements" do
291
291
  expect(resource.network_interfaces.size).to be 2
292
292
  end
293
293
 
294
- it 'contains the correct data' do
294
+ it "contains the correct data" do
295
295
  nic1, nic2 = resource.network_interfaces
296
296
 
297
- expect(nic1['NETWORK_NAME']).to eq 'VM Network'
298
- expect(nic1['NETWORK_ADDRESS']).to eq '192.168.110.200'
299
- expect(nic1['NETWORK_MAC_ADDRESS']).to eq '00:50:56:ae:95:3c'
297
+ expect(nic1["NETWORK_NAME"]).to eq "VM Network"
298
+ expect(nic1["NETWORK_ADDRESS"]).to eq "192.168.110.200"
299
+ expect(nic1["NETWORK_MAC_ADDRESS"]).to eq "00:50:56:ae:95:3c"
300
300
 
301
- expect(nic2['NETWORK_NAME']).to eq 'Management Network'
302
- expect(nic2['NETWORK_ADDRESS']).to eq '192.168.220.200'
303
- expect(nic2['NETWORK_MAC_ADDRESS']).to eq '00:50:56:ae:95:3d'
301
+ expect(nic2["NETWORK_NAME"]).to eq "Management Network"
302
+ expect(nic2["NETWORK_ADDRESS"]).to eq "192.168.220.200"
303
+ expect(nic2["NETWORK_MAC_ADDRESS"]).to eq "00:50:56:ae:95:3d"
304
304
  end
305
305
  end
306
306
 
307
- describe '#ip_addresses' do
308
- it 'returns the correct IP addresses' do
309
- skip 'broken and needs to be updated per changes -JJ 2017-04-14'
310
- stub_request(:post, 'https://vra.corp.local/identity/api/tokens')
307
+ describe "#ip_addresses" do
308
+ it "returns the correct IP addresses" do
309
+ skip "broken and needs to be updated per changes -JJ 2017-04-14"
310
+ stub_request(:post, "https://vra.corp.local/identity/api/tokens")
311
311
  .with(body: '{"username":"user@corp.local","password":"password","tenant":"tenant"}',
312
- headers: { 'Accept' => 'application/json', 'Content-Type' => 'application/json' })
313
- .to_return(status: 200, body: '', headers: {})
314
- expect(resource.ip_addresses).to eq [ '192.168.110.200', '192.168.220.200' ]
312
+ headers: { "Accept" => "application/json", "Content-Type" => "application/json" })
313
+ .to_return(status: 200, body: "", headers: {})
314
+ expect(resource.ip_addresses).to eq [ "192.168.110.200", "192.168.220.200" ]
315
315
  end
316
316
 
317
- it 'returns nil if there are no network interfaces' do
317
+ it "returns nil if there are no network interfaces" do
318
318
  allow(resource).to receive(:network_interfaces).and_return nil
319
319
  expect(resource.ip_addresses).to be_nil
320
320
  end
321
321
  end
322
322
 
323
- describe '#actions' do
324
- it 'does not call #fetch_resource_data' do
323
+ describe "#actions" do
324
+ it "does not call #fetch_resource_data" do
325
325
  expect(resource).not_to receive(:fetch_resource_data)
326
326
  resource.actions
327
327
  end
328
328
  end
329
329
 
330
- describe '#action_id_by_name' do
331
- it 'returns the correct action ID for the destroy action' do
332
- expect(resource.action_id_by_name('Destroy')).to eq 'ace8ba42-e724-48d8-9614-9b3a62b5a464'
330
+ describe "#action_id_by_name" do
331
+ it "returns the correct action ID for the destroy action" do
332
+ expect(resource.action_id_by_name("Destroy")).to eq "ace8ba42-e724-48d8-9614-9b3a62b5a464"
333
333
  end
334
334
 
335
- it 'returns nil if there are no resource operations' do
335
+ it "returns nil if there are no resource operations" do
336
336
  allow(resource).to receive(:actions).and_return nil
337
- expect(resource.action_id_by_name('Destroy')).to be_nil
337
+ expect(resource.action_id_by_name("Destroy")).to be_nil
338
338
  end
339
339
 
340
- it 'returns nil if there are actions, but none with the right name' do
341
- allow(resource).to receive(:actions).and_return([ { 'name' => 'some action' }, { 'name' => 'another action' } ])
342
- expect(resource.action_id_by_name('Destroy')).to be_nil
340
+ it "returns nil if there are actions, but none with the right name" do
341
+ allow(resource).to receive(:actions).and_return([ { "name" => "some action" }, { "name" => "another action" } ])
342
+ expect(resource.action_id_by_name("Destroy")).to be_nil
343
343
  end
344
344
  end
345
345
 
346
- describe '#destroy' do
347
- it_behaves_like 'a resource action', :destroy, 'Destroy'
346
+ describe "#destroy" do
347
+ it_behaves_like "a resource action", :destroy, "Destroy"
348
348
  end
349
349
 
350
- describe '#shutdown' do
351
- it_behaves_like 'a resource action', :shutdown, 'Shutdown'
350
+ describe "#shutdown" do
351
+ it_behaves_like "a resource action", :shutdown, "Shutdown"
352
352
  end
353
353
 
354
- describe '#poweroff' do
355
- it_behaves_like 'a resource action', :poweroff, 'Power Off'
354
+ describe "#poweroff" do
355
+ it_behaves_like "a resource action", :poweroff, "Power Off"
356
356
  end
357
357
 
358
- describe '#poweron' do
359
- it_behaves_like 'a resource action', :poweron, 'Power On'
358
+ describe "#poweron" do
359
+ it_behaves_like "a resource action", :poweron, "Power On"
360
360
  end
361
361
 
362
- describe '#submit_action_request' do
362
+ describe "#submit_action_request" do
363
363
  before do
364
364
  allow(resource).to receive(:action_request_payload).and_return({})
365
- response = double('response', location: '/requests/request-12345')
366
- allow(client).to receive(:http_post).with('/catalog-service/api/consumer/requests', '{}').and_return(response)
365
+ response = double("response", location: "/requests/request-12345")
366
+ allow(client).to receive(:http_post).with("/catalog-service/api/consumer/requests", "{}").and_return(response)
367
367
  end
368
368
 
369
- it 'calls http_post' do
370
- expect(client).to receive(:http_post).with('/catalog-service/api/consumer/requests', '{}')
369
+ it "calls http_post" do
370
+ expect(client).to receive(:http_post).with("/catalog-service/api/consumer/requests", "{}")
371
371
 
372
- resource.submit_action_request('action-123')
372
+ resource.submit_action_request("action-123")
373
373
  end
374
374
 
375
- it 'returns a Vra::Request object' do
376
- expect(resource.submit_action_request('action-123')).to be_an_instance_of(Vra::Request)
375
+ it "returns a Vra::Request object" do
376
+ expect(resource.submit_action_request("action-123")).to be_an_instance_of(Vra::Request)
377
377
  end
378
378
  end
379
379
  end
380
380
 
381
- context 'when a valid VM resource instance with no operations is created' do
381
+ context "when a valid VM resource instance with no operations is created" do
382
382
  let(:resource) { Vra::Resource.new(client, data: vm_payload_no_ops) }
383
383
 
384
- describe '#actions' do
385
- it 'calls #fetch_resource_data' do
384
+ describe "#actions" do
385
+ it "calls #fetch_resource_data" do
386
386
  expect(resource).to receive(:fetch_resource_data)
387
387
  resource.actions
388
388
  end
389
389
  end
390
390
  end
391
391
 
392
- context 'when a valid non-VM resource instance has been created' do
392
+ context "when a valid non-VM resource instance has been created" do
393
393
  let(:resource) { Vra::Resource.new(client, data: non_vm_payload) }
394
394
 
395
- it 'returns nil for network_interfaces and ip_addresses' do
395
+ it "returns nil for network_interfaces and ip_addresses" do
396
396
  expect(resource.network_interfaces).to be_nil
397
397
  expect(resource.ip_addresses).to be_nil
398
398
  end