From 231b11b910612ed94fd67b75caa715b782d5efe9 Mon Sep 17 00:00:00 2001 From: Daniel Reichert Date: Wed, 17 Jul 2013 11:05:39 -0700 Subject: [PATCH] Added list tests, helper formats. Cleaned check_tests. --- .../requests/monitoring/check_tests.rb | 15 +--- tests/rackspace/requests/monitoring/helper.rb | 69 ++++++++++++++++--- .../monitoring/list_check_type_tests.rb | 15 ++++ .../requests/monitoring/list_checks_tests.rb | 17 +++++ .../monitoring/list_entities_tests.rb | 15 ++++ .../monitoring/list_overview_tests.rb | 15 ++++ 6 files changed, 124 insertions(+), 22 deletions(-) create mode 100644 tests/rackspace/requests/monitoring/list_check_type_tests.rb create mode 100644 tests/rackspace/requests/monitoring/list_checks_tests.rb create mode 100644 tests/rackspace/requests/monitoring/list_entities_tests.rb create mode 100644 tests/rackspace/requests/monitoring/list_overview_tests.rb diff --git a/tests/rackspace/requests/monitoring/check_tests.rb b/tests/rackspace/requests/monitoring/check_tests.rb index 47793671d..0c2eb4dc4 100644 --- a/tests/rackspace/requests/monitoring/check_tests.rb +++ b/tests/rackspace/requests/monitoring/check_tests.rb @@ -1,4 +1,4 @@ -Shindo.tests('Fog::Rackspace::Monitoring | check_tests', ['rackspace','rackspacemonitoring']) do +Shindo.tests('Fog::Rackspace::Monitoring | check_tests', ['rackspace']) do pending if Fog.mocking? account = Fog::Rackspace::Monitoring.new @@ -6,18 +6,7 @@ Shindo.tests('Fog::Rackspace::Monitoring | check_tests', ['rackspace','rackspace check_id = nil tests('success') do tests('#create new check').formats(DATA_FORMAT) do - obj = { - :details => { - :url => 'http://www.rackspace.com', - :method => 'GET', - }, - :type => "remote.http", - :monitoring_zones_poll => ["mzdfw"], - :target_hostname => 'rackspace.com', - :timeout => 30, - :period => 100 - } - response = account.create_check(entity_id, obj).data + response = account.create_check(entity_id, CHECK_CREATE_OPTIONS).data check_id = response[:headers]['X-Object-ID'] response end diff --git a/tests/rackspace/requests/monitoring/helper.rb b/tests/rackspace/requests/monitoring/helper.rb index 2fd7a3789..5ca15f32f 100644 --- a/tests/rackspace/requests/monitoring/helper.rb +++ b/tests/rackspace/requests/monitoring/helper.rb @@ -1,18 +1,26 @@ -DELETE_HEADERS_FORMAT = { - 'X-LB' => String, - 'X-Response-Id' => String, - 'X-RateLimit-Remaining' => String, +MINIMAL_HEADERS_FORMAT = { 'X-RateLimit-Window' => String, + 'X-RateLimit-Limit' => String, 'X-RateLimit-Type' => String, 'Content-Type' => String, 'Date' => String, - 'X-RateLimit-Limit' => String, - 'Content-Length' => String } -HEADERS_FORMAT = DELETE_HEADERS_FORMAT.merge({ - 'X-Object-ID' => String, - 'Location' => String, +DELETE_HEADERS_FORMAT = MINIMAL_HEADERS_FORMAT.merge({ + 'Content-Length' => String }) +HEADERS_FORMAT = MINIMAL_HEADERS_FORMAT.merge({ + 'Content-Length' => String, + 'X-Object-ID' => String, + 'Location' => String +}) +LIST_HEADERS_FORMAT = MINIMAL_HEADERS_FORMAT.merge({ + 'X-RateLimit-Remaining' => String, + 'X-Response-Id' => String, + 'Transfer-Encoding' => String, + 'X-LB' => String, + 'Vary' => String +}) + DATA_FORMAT = { :status => Integer, :body => String, @@ -25,3 +33,46 @@ DELETE_DATA_FORMAT = { :headers => DELETE_HEADERS_FORMAT, :remote_ip => String } + +CHECK_CREATE_OPTIONS = { + :details => { + :url => 'http://www.rackspace.com', + :method => 'GET', + }, + :type => 'remote.http', + :monitoring_zones_poll => ['mzdfw'], + :target_hostname => 'rackspace.com', + :timeout => 30, + :period => 100 +} + +OVERVIEW_FORMAT = { + :status => Integer, + :body=> { + :values => [ + { + :entity => { + :id => String, + :label => String, + :ip_addresses => { }, + :metadata => String + }, + :checks => [ + ], + :alarms => [ + ], + :latest_alarm_states => [ + ] + } + ], + :metadata => { + :count => Integer, + :limit => Integer, + :marker => String, + :next_marker => String, + :next_href => String + } + }, + :headers => LIST_HEADERS_FORMAT, + :remote_ip => String +} diff --git a/tests/rackspace/requests/monitoring/list_check_type_tests.rb b/tests/rackspace/requests/monitoring/list_check_type_tests.rb new file mode 100644 index 000000000..478cb8c8f --- /dev/null +++ b/tests/rackspace/requests/monitoring/list_check_type_tests.rb @@ -0,0 +1,15 @@ +Shindo.tests('Fog::Rackspace::Monitoring | list_check_type_tests', ['rackspace']) do + pending if Fog.mocking? + + account = Fog::Rackspace::Monitoring.new + tests('success') do + tests('#get check types').formats(LIST_HEADERS_FORMAT) do + account.list_check_types().data[:headers] + end + end + tests('failure') do + tests('#fail to list check types').raises(Fog::Rackspace::Monitoring::ArgumentError) do + account.list_check_types(-1) + end + end +end diff --git a/tests/rackspace/requests/monitoring/list_checks_tests.rb b/tests/rackspace/requests/monitoring/list_checks_tests.rb new file mode 100644 index 000000000..ce416caa0 --- /dev/null +++ b/tests/rackspace/requests/monitoring/list_checks_tests.rb @@ -0,0 +1,17 @@ +Shindo.tests('Fog::Rackspace::Monitoring | list_checks_tests', ['rackspace']) do + pending if Fog.mocking? + + account = Fog::Rackspace::Monitoring.new + entity_id = account.create_entity(:label => "Foo").data[:headers]["X-Object-ID"] + tests('success') do + tests('#get list of checks').formats(LIST_HEADERS_FORMAT) do + account.list_checks(entity_id).data[:headers] + end + end + tests('failure') do + tests('#fail to list checks').raises(Fog::Rackspace::Monitoring::NotFound) do + account.list_checks(-1) + end + end + account.delete_entity(entity_id) +end diff --git a/tests/rackspace/requests/monitoring/list_entities_tests.rb b/tests/rackspace/requests/monitoring/list_entities_tests.rb new file mode 100644 index 000000000..0a6ed3ff8 --- /dev/null +++ b/tests/rackspace/requests/monitoring/list_entities_tests.rb @@ -0,0 +1,15 @@ +Shindo.tests('Fog::Rackspace::Monitoring | list_entities_tests', ['rackspace']) do + pending if Fog.mocking? + + account = Fog::Rackspace::Monitoring.new + tests('success') do + tests('#get list of entities').formats(CHECKS_HEADERS_FORMAT) do + account.list_entities().data[:headers] + end + end + tests('failure') do + tests('#fail to list entities').raises(Fog::Rackspace::Monitoring::ArgumentError) do + account.list_entities(-1) + end + end +end diff --git a/tests/rackspace/requests/monitoring/list_overview_tests.rb b/tests/rackspace/requests/monitoring/list_overview_tests.rb new file mode 100644 index 000000000..a40f6337b --- /dev/null +++ b/tests/rackspace/requests/monitoring/list_overview_tests.rb @@ -0,0 +1,15 @@ +Shindo.tests('Fog::Rackspace::Monitoring | list_overview_tests', ['rackspace']) do + pending if Fog.mocking? + + account = Fog::Rackspace::Monitoring.new + tests('success') do + tests('#get list overview').formats(OVERVIEW_HEADERS_FORMAT) do + account.list_overview().data[:headers] + end + end + tests('failure') do + tests('#fail to list overview').raises(Fog::Rackspace::Monitoring::NoMethodError) do + account.list_overview(-1) + end + end +end