From 5efe6777094bcdbf4a7dc3b697c926f73f0764c4 Mon Sep 17 00:00:00 2001 From: Sergio Rubio Date: Thu, 6 Dec 2012 23:44:26 +0100 Subject: [PATCH] [xenserver] Added HostMetrics tests --- .../models/compute/host_metrics_tests.rb | 48 +++++++++++++++++++ tests/xenserver/models/compute/host_tests.rb | 5 +- 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 tests/xenserver/models/compute/host_metrics_tests.rb diff --git a/tests/xenserver/models/compute/host_metrics_tests.rb b/tests/xenserver/models/compute/host_metrics_tests.rb new file mode 100644 index 000000000..4ffad3fbb --- /dev/null +++ b/tests/xenserver/models/compute/host_metrics_tests.rb @@ -0,0 +1,48 @@ +Shindo.tests('Fog::Compute[:xenserver] | PBD model', ['xenserver']) do + + host = Fog::Compute[:xenserver].hosts.first + + tests('The HostMetrics model should') do + tests('have attributes') do + model_attribute_hash = host.metrics.attributes + attributes = [ + :reference, + :uuid, + :memory_free, + :memory_total, + :other_config, + :last_updated + ] + tests("The HostMetrics model should respond to") do + attributes.each do |attribute| + test("#{attribute}") { host.metrics.respond_to? attribute } + end + end + tests("The attributes hash should have key") do + attributes.each do |attribute| + test("#{attribute}") { model_attribute_hash.has_key? attribute } + end + end + end + + test('be a kind of Fog::Compute::XenServer::HostMetrics') do + host.metrics.kind_of? Fog::Compute::XenServer::HostMetrics + end + + test("have a last_updated Time property") { host.metrics.last_updated.kind_of? Time } + + test("return a valid memory_free ammount") do + (host.metrics.memory_free =~ /^\d+$/) == 0 + end + + test("have memory_free > 0") { host.metrics.memory_free.to_i > 0 } + + test("return a valid memory_total ammount") do + (host.metrics.memory_total =~ /^\d+$/) == 0 + end + + test("have memory_total > 0") { host.metrics.memory_total.to_i > 0 } + + end + +end diff --git a/tests/xenserver/models/compute/host_tests.rb b/tests/xenserver/models/compute/host_tests.rb index 166267e74..cff171fce 100644 --- a/tests/xenserver/models/compute/host_tests.rb +++ b/tests/xenserver/models/compute/host_tests.rb @@ -19,7 +19,7 @@ Shindo.tests('Fog::Compute[:xenserver] | host model', ['xenserver']) do :allowed_operations, :enabled, :hostname, - :metrics, + :__metrics, :name_description, :other_config, :__pbds, @@ -61,6 +61,9 @@ Shindo.tests('Fog::Compute[:xenserver] | host model', ['xenserver']) do test("and each Server should be a Fog::Compute::XenServer::Server") { i.kind_of? Fog::Compute::XenServer::Server} } end + tests("return valid HostMetrics") do + test("object") { host.metrics.kind_of? Fog::Compute::XenServer::HostMetrics } + end end