1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Implement agent_info tests; better mocks

This commit is contained in:
kfafel 2013-12-23 14:59:36 -06:00
parent faf0d1a7db
commit af0f84f5b6
10 changed files with 55 additions and 23 deletions

View file

@ -61,6 +61,7 @@ module Fog
request_path 'fog/rackspace/requests/monitoring' request_path 'fog/rackspace/requests/monitoring'
request :list_agent_tokens request :list_agent_tokens
request :list_agents
request :list_alarms request :list_alarms
request :list_alarm_examples request :list_alarm_examples
request :list_checks request :list_checks
@ -72,6 +73,7 @@ module Fog
request :list_notification_plans request :list_notification_plans
request :list_notifications request :list_notifications
request :get_agent
request :get_agent_token request :get_agent_token
request :get_alarm request :get_alarm
request :get_alarm_example request :get_alarm_example

View file

@ -15,10 +15,8 @@ module Fog
class Mock class Mock
def get_cpus_info(agent_id) def get_cpus_info(agent_id)
agent_id = Fog::Rackspace::MockData.uuid
if agent_id == -1 if agent_id == -1
raise Fog::Rackspace::Monitoring::NotFound raise Fog::Rackspace::Monitoring::BadRequest
end end
response = Excon::Response.new response = Excon::Response.new

View file

@ -15,10 +15,8 @@ module Fog
class Mock class Mock
def get_disks_info(agent_id) def get_disks_info(agent_id)
agent_id = Fog::Rackspace::MockData.uuid
if agent_id == -1 if agent_id == -1
raise Fog::Rackspace::Monitoring::NotFound raise Fog::Rackspace::Monitoring::BadRequest
end end
response = Excon::Response.new response = Excon::Response.new

View file

@ -15,10 +15,8 @@ module Fog
class Mock class Mock
def get_filesystems_info(agent_id) def get_filesystems_info(agent_id)
agent_id = Fog::Rackspace::MockData.uuid
if agent_id == -1 if agent_id == -1
raise Fog::Rackspace::Monitoring::NotFound raise Fog::Rackspace::Monitoring::BadRequest
end end
response = Excon::Response.new response = Excon::Response.new

View file

@ -15,10 +15,8 @@ module Fog
class Mock class Mock
def get_logged_in_user_info(agent_id) def get_logged_in_user_info(agent_id)
agent_id = Fog::Rackspace::MockData.uuid
if agent_id == -1 if agent_id == -1
raise Fog::Rackspace::Monitoring::NotFound raise Fog::Rackspace::Monitoring::BadRequest
end end
response = Excon::Response.new response = Excon::Response.new

View file

@ -15,10 +15,8 @@ module Fog
class Mock class Mock
def get_memory_info(agent_id) def get_memory_info(agent_id)
agent_id = Fog::Rackspace::MockData.uuid
if agent_id == -1 if agent_id == -1
raise Fog::Rackspace::Monitoring::NotFound raise Fog::Rackspace::Monitoring::BadRequest
end end
response = Excon::Response.new response = Excon::Response.new

View file

@ -15,10 +15,8 @@ module Fog
class Mock class Mock
def get_network_interfaces_info(agent_id) def get_network_interfaces_info(agent_id)
agent_id = Fog::Rackspace::MockData.uuid
if agent_id == -1 if agent_id == -1
raise Fog::Rackspace::Monitoring::NotFound raise Fog::Rackspace::Monitoring::BadRequest
end end
response = Excon::Response.new response = Excon::Response.new

View file

@ -15,13 +15,12 @@ module Fog
class Mock class Mock
def get_processes_info(agent_id) def get_processes_info(agent_id)
agent_id = Fog::Rackspace::MockData.uuid
memory_major_faults = Fog::Mock.random_numbers(1).to_i memory_major_faults = Fog::Mock.random_numbers(1).to_i
memory_minor_faults = Fog::Mock.random_numbers(3).to_i memory_minor_faults = Fog::Mock.random_numbers(3).to_i
memory_page_faults = memory_major_faults+memory_minor_faults memory_page_faults = memory_major_faults+memory_minor_faults
if agent_id == -1 if agent_id == -1
raise Fog::Rackspace::Monitoring::NotFound raise Fog::Rackspace::Monitoring::BadRequest
end end
response = Excon::Response.new response = Excon::Response.new

View file

@ -15,10 +15,8 @@ module Fog
class Mock class Mock
def get_system_info(agent_id) def get_system_info(agent_id)
agent_id = Fog::Rackspace::MockData.uuid
if agent_id == -1 if agent_id == -1
raise Fog::Rackspace::Monitoring::NotFound raise Fog::Rackspace::Monitoring::BadRequest
end end
response = Excon::Response.new response = Excon::Response.new

View file

@ -3,6 +3,11 @@ Shindo.tests('Fog::Rackspace::Monitoring | agent_tests', ['rackspace','rackspace
account = Fog::Rackspace::Monitoring.new account = Fog::Rackspace::Monitoring.new
agent_token = nil agent_token = nil
options = { "label" => "Bar" } options = { "label" => "Bar" }
values_format = Hash
# values_format = {
# 'info' => Fog::Nullable::Hash
# }
tests('success') do tests('success') do
tests('#create new agent token').formats(DATA_FORMAT) do tests('#create new agent token').formats(DATA_FORMAT) do
response = account.create_agent_token(options).data response = account.create_agent_token(options).data
@ -12,13 +17,47 @@ Shindo.tests('Fog::Rackspace::Monitoring | agent_tests', ['rackspace','rackspace
tests('#list agent tokens').formats(LIST_HEADERS_FORMAT) do tests('#list agent tokens').formats(LIST_HEADERS_FORMAT) do
account.list_agent_tokens().data[:headers] account.list_agent_tokens().data[:headers]
end end
tests("#list_agents") do
data_matches_schema(values_format, {:allow_extra_keys => true}) { account.list_agents.body }
end
tests("#get_agent") do
data_matches_schema(values_format, {:allow_extra_keys => true}) { account.get_agent("agent_id").body }
end
tests('#get agent token').formats(LIST_HEADERS_FORMAT) do tests('#get agent token').formats(LIST_HEADERS_FORMAT) do
account.get_agent_token(agent_token).data[:headers] account.get_agent_token(agent_token).data[:headers]
end end
tests('#delete agent token').formats(DELETE_HEADERS_FORMAT) do tests('#delete agent token').formats(DELETE_HEADERS_FORMAT) do
account.delete_agent_token(agent_token).data[:headers] account.delete_agent_token(agent_token).data[:headers]
end end
tests("#get_cpus_info") do
data_matches_schema(values_format, {:allow_extra_keys => true}) { account.get_cpus_info("agent_id").body }
end
tests("#get_disks_info") do
data_matches_schema(values_format, {:allow_extra_keys => true}) { account.get_disks_info("agent_id").body }
end
tests("#get_filesystems_info") do
data_matches_schema(values_format, {:allow_extra_keys => true}) { account.get_filesystems_info("agent_id").body }
end
tests("#get_logged_in_user_info") do
data_matches_schema(values_format, {:allow_extra_keys => true}) { account.get_logged_in_user_info("agent_id").body }
end
tests("#get_memory_info") do
data_matches_schema(values_format, {:allow_extra_keys => true}) { account.get_memory_info("agent_id").body }
end
tests("#get_network_interfaces_info") do
data_matches_schema(values_format, {:allow_extra_keys => true}) { account.get_network_interfaces_info("agent_id").body }
end
tests("#get_processes_info") do
data_matches_schema(values_format, {:allow_extra_keys => true}) { account.get_processes_info("agent_id").body }
end
tests("#get_system_info") do
data_matches_schema(values_format, {:allow_extra_keys => true}) { account.get_system_info("agent_id").body }
end
end end
tests('failure') do tests('failure') do
tests('#fail to create agent token(-1)').raises(TypeError) do tests('#fail to create agent token(-1)').raises(TypeError) do
account.create_agent_token(-1) account.create_agent_token(-1)
@ -29,5 +68,11 @@ Shindo.tests('Fog::Rackspace::Monitoring | agent_tests', ['rackspace','rackspace
tests('#fail to delete agent token(-1)').raises(Fog::Rackspace::Monitoring::NotFound) do tests('#fail to delete agent token(-1)').raises(Fog::Rackspace::Monitoring::NotFound) do
account.delete_agent_token(-1) account.delete_agent_token(-1)
end end
tests('#fail to connect to agent(-1)').raises(Fog::Rackspace::Monitoring::BadRequest) do
account.get_cpus_info(-1)
end
tests('#fail to get agent (-1)').raises(Fog::Rackspace::Monitoring::NotFound) do
account.get_agent(-1)
end
end end
end end