spec/resource_spec.rb in vmware-vra-2.5.2 vs spec/resource_spec.rb in vmware-vra-2.6.0
- old
+ new
@@ -321,16 +321,77 @@
expect(nic2["NETWORK_MAC_ADDRESS"]).to eq "00:50:56:ae:95:3d"
end
end
describe "#ip_addresses" do
- it "returns the correct IP addresses" do
- skip "broken and needs to be updated per changes -JJ 2017-04-14"
- stub_request(:post, "https://vra.corp.local/identity/api/tokens")
- .with(body: '{"username":"user@corp.local","password":"password","tenant":"tenant"}',
- headers: { "Accept" => "application/json", "Content-Type" => "application/json" })
- .to_return(status: 200, body: "", headers: {})
- expect(resource.ip_addresses).to eq [ "192.168.110.200", "192.168.220.200" ]
+ let(:authn_payload) do
+ {
+ "username" => "user@corp.local",
+ "password" => "password",
+ "tenant" => "tenant",
+ }.to_json
+ end
+
+ let(:resource_view_body) do
+ File.read(File.join(File.dirname(__FILE__),
+ "fixtures",
+ "resource",
+ "ip_address.txt"))
+ end
+
+ before do
+ stub_request(
+ :post,
+ "https://vra.corp.local/identity/api/tokens"
+ ).with(
+ :body => authn_payload,
+ :headers => { "Accept" => "application/json", "Content-Type" => "application/json" }
+ ).to_return(
+ :status => 200,
+ :body => '{"id":"12345"}',
+ :headers => {}
+ )
+
+ stub_request(
+ :head,
+ "https://vra.corp.local/identity/api/tokens/12345"
+ ).with(
+ :headers => { "Accept" => "application/json", "Authorization" => "Bearer 12345", "Content-Type" => "application/json" }
+ ).to_return(
+ :status => 204,
+ :body => "",
+ :headers => {}
+ )
+
+ stub_request(
+ :get,
+ "https://vra.corp.local/catalog-service/api/consumer/requests/bogus/resourceViews"
+ ).with(
+ headers: { "Accept" => "application/json", "Content-Type" => "application/json" }
+ ).to_return(
+ status: 200,
+ body: resource_view_body,
+ headers: {}
+ )
+ end
+
+ context "with IP address in the second element" do
+ it "returns the correct IP addresses" do
+ expect(resource.ip_addresses).to eq [ "172.16.20.147" ]
+ end
+ end
+
+ context "with IP address in the third element" do
+ let(:resource_view_body) do
+ File.read(File.join(File.dirname(__FILE__),
+ "fixtures",
+ "resource",
+ "ip_address_third_element.txt"))
+ end
+
+ it "returns the correct IP addresses" do
+ expect(resource.ip_addresses).to eq [ "172.16.20.147" ]
+ end
end
it "returns nil if there are no network interfaces" do
allow(resource).to receive(:network_interfaces).and_return nil
expect(resource.ip_addresses).to be_nil