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/requests/compute/find_vm_by_ref_tests.rb
Jeff McCune 743882f032 Refactor requests to return simple hashes and add unit tests
This massive commit refactors all of the request methods on the
Fog::Compute[:vsphere] instance to return simple hashes.  The behavior
before this commit returned full vmware object references which was a
problem because it was difficult to unit test.

With this patch, it is much easier to add and maintain Mock
implementations of the request methods.  This makes adding behavior
tests for the server model much easier.

In addition, test coverage using Shindo has been added.  Previously
there was little test coverage of the behavior.

To run the tests:

    shindont tests/vsphere/
2011-09-10 15:11:18 -07:00

26 lines
973 B
Ruby

Shindo.tests('Fog::Compute[:vsphere] | find_vm_by_ref request', ['vsphere']) do
compute = Fog::Compute[:vsphere]
tests("When missing arguments") do
raises(ArgumentError, "Should raise ArgumentError when missing :vm_ref") do
compute.find_vm_by_ref
end
raises(Fog::Compute::Vsphere::NotFound, "Should raise Fog::Compute::Vsphere::NotFound when the vm does not exist") do
compute.find_vm_by_ref('vm_ref' => 'vm-000')
end
end
# centos56gm is a template
existing_vms = { 'vm-715' => 'jefftest', 'vm-698' => 'centos56gm' }
tests("When looking for existing VM's the response") do
existing_vms.each do |ref,name|
response = compute.find_vm_by_ref('vm_ref' => ref)
test("should be a kind of Hash") { response.kind_of? Hash }
test("should have virtual_machine key") { response.has_key? 'virtual_machine' }
returns(name, "#{ref} should return #{name}") { response['virtual_machine']['name'] }
end
end
end