mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Adding Tests and Mocks
Adding several test cases for flavors and updating network tests to support new attributes.
This commit is contained in:
parent
2702f22e33
commit
83ed0422d1
7 changed files with 88 additions and 10 deletions
|
@ -8,7 +8,7 @@ module Fog
|
|||
model Fog::Compute::OpenNebula::Network
|
||||
|
||||
def all(filter={})
|
||||
load(service.list_networks(filter))
|
||||
self.get_by_filter(filter)
|
||||
end
|
||||
|
||||
def get(id)
|
||||
|
@ -16,7 +16,7 @@ module Fog
|
|||
end
|
||||
|
||||
def get_by_filter(filter)
|
||||
self.all(filter)
|
||||
load(service.list_networks(filter))
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -33,10 +33,11 @@ module Fog
|
|||
def network_to_attributes(net)
|
||||
return if net.nil?
|
||||
h = {
|
||||
:id => net["VNET"]["ID"],
|
||||
:name => net["VNET"]["NAME"],
|
||||
:uid => net["VNET"]["UID"],
|
||||
:gid => net["VNET"]["GID"],
|
||||
:id => net["VNET"]["ID"],
|
||||
:name => net["VNET"]["NAME"],
|
||||
:uid => net["VNET"]["UID"],
|
||||
:uname => net["VNET"]["UNAME"],
|
||||
:gid => net["VNET"]["GID"],
|
||||
}
|
||||
|
||||
h[:description] = net["VNET"]["TEMPLATE"]["DESCRIPTION"] unless net["VNET"]["TEMPLATE"]["DESCRIPTION"].nil?
|
||||
|
@ -59,6 +60,7 @@ module Fog
|
|||
:id => "5",
|
||||
:name => name,
|
||||
:uid => "5",
|
||||
:uname => "mock",
|
||||
:gid => "5",
|
||||
:description => "netDescription",
|
||||
:vlan => "5"
|
||||
|
|
|
@ -53,7 +53,8 @@ module Fog
|
|||
h = Hash[
|
||||
:id => t.to_hash["VMTEMPLATE"]["ID"],
|
||||
:name => t.to_hash["VMTEMPLATE"]["NAME"],
|
||||
:content => t.template_str
|
||||
:content => t.template_str,
|
||||
:USER_VARIABLES => "" # Default if not set in template
|
||||
]
|
||||
h.merge! t.to_hash["VMTEMPLATE"]["TEMPLATE"]
|
||||
|
||||
|
@ -99,7 +100,34 @@ module Fog
|
|||
|
||||
class Mock
|
||||
def template_pool(filter = { })
|
||||
[ {}, {} ]
|
||||
[
|
||||
{
|
||||
:content => %Q{
|
||||
NAME = mock-vm
|
||||
MEMORY = 512
|
||||
VCPU = 1
|
||||
CPU = 1
|
||||
},
|
||||
:id => 1,
|
||||
:name => 'mock',
|
||||
:cpu => 1,
|
||||
:vcpu => 1,
|
||||
:memory => 512,
|
||||
:sched_requirements => 'CPUSPEED > 1000',
|
||||
:sched_rank => 'FREECPU',
|
||||
:sched_ds_requirements => "NAME=mock",
|
||||
:sched_ds_rank => "FREE_MB",
|
||||
:disk => {},
|
||||
:nic => {},
|
||||
:os => {
|
||||
'ARCH' => 'x86_64'
|
||||
},
|
||||
:graphics => {},
|
||||
:raw => {},
|
||||
:context => {},
|
||||
:user_variables => {}
|
||||
}
|
||||
]
|
||||
end
|
||||
end #class Mock
|
||||
end #class OpenNebula
|
||||
|
|
29
tests/opennebula/models/compute/flavor_tests.rb
Normal file
29
tests/opennebula/models/compute/flavor_tests.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
Shindo.tests('Fog::Compute[:opennebula] | flavor model', ['opennebula']) do
|
||||
|
||||
flavors = Fog::Compute[:opennebula].flavors
|
||||
flavor = flavors.last
|
||||
|
||||
tests('The flavor model should') do
|
||||
tests('have the action') do
|
||||
test('reload') { flavor.respond_to? 'reload' }
|
||||
end
|
||||
tests('have attributes') do
|
||||
model_attribute_hash = flavor.attributes
|
||||
attributes =
|
||||
tests("The flavor model should respond to") do
|
||||
[:name, :id, :to_label, :to_s, :get_cpu, :get_vcpu, :get_memory, :get_raw, :get_disk, :get_os,
|
||||
:get_graphics, :get_nic, :get_sched_ds_requirements, :get_sched_ds_rank, :get_sched_requirements,
|
||||
:get_sched_rank, :get_context, :get_user_variables].each do |attribute|
|
||||
test("#{attribute}") { flavor.respond_to? attribute }
|
||||
end
|
||||
end
|
||||
tests("The attributes hash should have key") do
|
||||
[:name, :id, :content, :cpu, :vcpu, :memory, :os, :graphics, :raw, :context, :user_variables ].each do |attribute|
|
||||
test("#{attribute}") { model_attribute_hash.has_key? attribute }
|
||||
end
|
||||
end
|
||||
end
|
||||
test('be a kind of Fog::Compute::OpenNebula::Flavor') { flavor.kind_of? Fog::Compute::OpenNebula::Flavor }
|
||||
end
|
||||
|
||||
end
|
17
tests/opennebula/models/compute/flavors_tests.rb
Normal file
17
tests/opennebula/models/compute/flavors_tests.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
Shindo.tests('Fog::Compute[:opennebula] | flavors collection', ['opennebula']) do
|
||||
|
||||
flavors = Fog::Compute[:opennebula].flavors
|
||||
|
||||
tests('The flavors collection should') do
|
||||
test('should be a kind of Fog::Compute::OpenNebula::Flavors') { flavors.kind_of? Fog::Compute::OpenNebula::Flavors }
|
||||
tests('should be able to reload itself').succeeds { flavors.reload }
|
||||
|
||||
tests('should be able to get models') do
|
||||
tests('all').succeeds { flavors.all }
|
||||
tests('by instance id').succeeds { flavors.get flavors.first.id }
|
||||
tests('by name').succeeds { flavors.get_by_name "fogtest" }
|
||||
tests('by filter').succeeds { flavors.get_by_filter ({:name => "fogtest", :id => flavors.first.id }) }
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -11,12 +11,12 @@ Shindo.tests('Fog::Compute[:opennebula] | network model', ['opennebula']) do
|
|||
model_attribute_hash = network.attributes
|
||||
attributes =
|
||||
tests("The network model should respond to") do
|
||||
[:name, :id, :vlan, :uid, :gid, :description].each do |attribute|
|
||||
[:name, :id, :vlan, :uid, :uname, :gid, :description].each do |attribute|
|
||||
test("#{attribute}") { network.respond_to? attribute }
|
||||
end
|
||||
end
|
||||
tests("The attributes hash should have key") do
|
||||
[:name, :id, :uid, :gid].each do |attribute|
|
||||
[:name, :id, :uid, :uname, :gid ].each do |attribute|
|
||||
test("#{attribute}") { model_attribute_hash.has_key? attribute }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,7 +6,9 @@ Shindo.tests('Fog::Compute[:opennebula] | networks collection', ['opennebula'])
|
|||
test('should be a kind of Fog::Compute::OpenNebula::Networks') { networks.kind_of? Fog::Compute::OpenNebula::Networks }
|
||||
tests('should be able to reload itself').succeeds { networks.reload }
|
||||
tests('should be able to get a model') do
|
||||
tests('all').succeeds { networks.all }
|
||||
tests('by instance id').succeeds { networks.get networks.first.id }
|
||||
tests('by filter').succeeds { networks.get_by_filter ({ :id => networks.first.id }) }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue