1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/tests/xenserver/models/compute/servers_tests.rb

89 lines
3 KiB
Ruby
Raw Normal View History

2012-04-02 07:25:03 -04:00
Shindo.tests('Fog::Compute[:xenserver] | servers collection', ['xenserver']) do
conn = Fog::Compute[:xenserver]
destroy_ephemeral_servers
servers = conn.servers
templates = conn.servers.templates
2012-04-02 07:25:03 -04:00
tests('The servers collection') do
servers = conn.servers.all
test('should be empty') do
servers.empty?
end
server = conn.servers.create(:name => test_ephemeral_vm_name,
:template_name => test_template_name)
test('should NOT be empty') do
servers.reload
!servers.empty?
end
server.destroy
2012-04-02 07:25:03 -04:00
test('should be a kind of Fog::Compute::XenServer::Servers') { servers.kind_of? Fog::Compute::XenServer::Servers }
test('should be a kind of Fog::Compute::XenServer::Servers') { servers.kind_of? Fog::Compute::XenServer::Servers }
tests('should have Fog::Compute::XenServer::Servers inside') do
conn.servers.each do |s|
test { s.kind_of? Fog::Compute::XenServer::Server }
end
end
test("should return a list of templates") do
templates.kind_of? Array
end
tests("The servers template list should") do
test("should include only templates in servers.templates") do
ok = true
templates.each { |t| ok = false if !t.is_a_template }
ok
end
test("include a #{test_template_name} template in custom_templates") do
found = false
servers.custom_templates.each do |s|
found = (s.name == test_template_name)
end
found
end
test("NOT include a #{test_template_name} template in built-in templates") do
found = false
servers.builtin_templates.each do |s|
found = (s.name != test_template_name)
end
found
end
# This may fail in other test scenarios with more than one built-in template
# present
test("include only one custom template") { servers.custom_templates.size == 1 }
tests("not include built-in templates in custom_templates") do
servers.custom_templates.each do |s|
test("#{s.name} is NOT a built-in template") {s.allowed_operations.include?('destroy') }
end
end
test("include more than one built-in templates") { servers.builtin_templates.size >= 1 }
tests("not include real servers") do
servers.builtin_templates.each do |s|
test("#{s.name} is not a real server") { s.is_a_template }
end
end
end
2012-04-02 07:25:03 -04:00
tests('should be able to reload itself').succeeds { servers.reload }
tests('should be able to get a model') do
server = conn.servers.create(:name => test_ephemeral_vm_name,
:template_name => test_template_name)
test('by name') { servers.get_by_name(test_ephemeral_vm_name).kind_of? Fog::Compute::XenServer::Server }
test('by instance reference') { servers.get(server.reference).kind_of? Fog::Compute::XenServer::Server }
server.destroy
2012-04-02 07:25:03 -04:00
end
end
# Teardown cleaup
destroy_ephemeral_servers
2012-04-02 07:25:03 -04:00
end