1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/tests/vsphere/compute_tests.rb
Jeff McCune 19cf9d7784 Add vsphere_server connection attribute
Without this patch it was difficult to figure out from the outside what
vSphere server Fog connected to.  The application using Fog should be
able to easily print out the connection information without breaking the
encapsulation Fog provides.

This patch makes the connected vSphere server hostname and API username
an attribute of the connection instance.

The tests have been updated to validate these attribute accessor
methods.
2011-09-14 09:29:30 -07:00

47 lines
1.5 KiB
Ruby

Shindo.tests('Fog::Compute[:vsphere]', ['vsphere']) do
compute = Fog::Compute[:vsphere]
tests("| convert_vm_mob_ref_to_attr_hash") do
require 'ostruct'
fake_vm = OpenStruct.new({
:_ref => 'vm-123',
:name => 'fakevm',
:summary => OpenStruct.new(:guest => OpenStruct.new),
:runtime => OpenStruct.new,
})
tests("When converting an incomplete vm object") do
test("it should return a Hash") do
compute.convert_vm_mob_ref_to_attr_hash(fake_vm).kind_of? Hash
end
tests("The converted Hash should") do
attr_hash = compute.convert_vm_mob_ref_to_attr_hash(fake_vm)
test("have a name") { attr_hash['name'] == 'fakevm' }
test("have a mo_ref") {attr_hash['mo_ref'] == 'vm-123' }
test("have an id") { attr_hash['id'] == 'vm-123' }
test("not have a instance_uuid") { attr_hash['instance_uuid'].nil? }
end
end
tests("When passed a nil object") do
attr_hash = compute.convert_vm_mob_ref_to_attr_hash(nil)
test("it should return a nil object") do
attr_hash.nil?
end
end
end
tests("Compute attributes") do
%w{ vsphere_is_vcenter vsphere_rev vsphere_username vsphere_server }.each do |attr|
test("it should respond to #{attr}") { compute.respond_to? attr }
end
end
tests("Compute collections") do
%w{ servers }.each do |collection|
test("it should respond to #{collection}") { compute.respond_to? collection }
end
end
end