forked from fog/fog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompute_tests.rb
55 lines (44 loc) · 1.6 KB
/
compute_tests.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
Shindo.tests('Fog::Compute[:vsphere]', ['vsphere']) do
compute = Fog::Compute[:vsphere]
tests("| convert_vm_mob_ref_to_attr_hash") do
# Mock the RbVmomi::VIM::ManagedObject class
class MockManagedObject
attr_reader :parent, :_ref
def initialize
@parent = @_ref = 'vm-123'
end
def collect! *pathSet
{ '_ref' => 'vm-123', 'name' => 'fakevm' }
end
end
fake_vm_mob_ref = MockManagedObject.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_mob_ref).kind_of? Hash
end
tests("The converted Hash should") do
attr_hash = compute.convert_vm_mob_ref_to_attr_hash(fake_vm_mob_ref)
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