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

Adding monitoring tests and their required changes

Changes made to lib/bin/rackspace.rb and lib/fog/rackspace.rb were required in
order to allow the tests to actually run. Changes to
lib/fog/rackspace/monitoring.rb were made in an effort to get failure tests to
run without the error that I am purposefully creating causing the test to fail.
This commit is contained in:
Daniel Reichert 2013-07-11 15:30:37 -07:00
parent 6bc5cba9f3
commit 002a918b21
5 changed files with 90 additions and 5 deletions

View file

@ -21,6 +21,8 @@ class Rackspace < Fog::Bin
Fog::Rackspace::Identity
when :databases
Fog::Rackspace::Databases
when :monitoring
Fog::Rackspace::Monitoring
else
raise ArgumentError, "Unrecognized service: #{key}"
end
@ -52,6 +54,8 @@ class Rackspace < Fog::Bin
Fog::Rackspace::Databases.new
when :block_storage
Fog::Rackspace::BlockStorage.new
when :monitoring
Fog::Rackspace::Monitoring.new
else
raise ArgumentError, "Unrecognized service: #{key.inspect}"
end

View file

@ -71,6 +71,7 @@ module Fog
service(:load_balancers, 'rackspace/load_balancers', 'LoadBalancers')
service(:identity, 'rackspace/identity', 'Identity')
service(:databases, 'rackspace/databases', 'Databases')
service(:monitoring, 'rackspace/monitoring', 'Monitoring')
def self.authenticate(options, connection_options = {})
rackspace_auth_url = options[:rackspace_auth_url]

View file

@ -4,6 +4,12 @@ require 'fog/core'
module Fog
module Rackspace
class Monitoring < Fog::Service
include Fog::Rackspace::Errors
class IdentifierTaken < Fog::Errors::Error; end
class ServiceError < Fog::Rackspace::Errors::ServiceError; end
class InternalServerError < Fog::Rackspace::Errors::InternalServerError; end
class BadRequest < Fog::Rackspace::Errors::BadRequest; end
ENDPOINT = 'https://monitoring.api.rackspacecloud.com/v1.0'
@ -11,7 +17,7 @@ module Fog
recognizes :rackspace_auth_url, :persistent, :raise_errors
recognizes :rackspace_auth_token, :rackspace_service_url, :rackspace_account_id
model_path 'fog/rackspace/models/monitoring/models'
model_path 'fog/rackspace/models/monitoring'
model :entity
collection :entities
model :check
@ -29,7 +35,7 @@ module Fog
model :check_type
collection :check_types
request_path 'fog/rackspace/models/monitoring/requests'
request_path 'fog/rackspace/requests/monitoring'
request :list_agent_tokens
request :list_alarms
request :list_alarm_examples
@ -61,11 +67,13 @@ module Fog
request :evaluate_alarm_example
class Mock
class Mock < Fog::Rackspace::Service
def request(params)
Fog::Mock.not_implemented
end
end
class Real
class Real < Fog::Rackspace::Service
def initialize(options={})
@rackspace_api_key = options[:rackspace_api_key]
@rackspace_username = options[:rackspace_username]

View file

@ -0,0 +1,45 @@
Shindo.tests('Fog::Rackspace::Monitoring | entity_tests', ['rackspace','rackspacemonitoring']) do
pending if Fog.mocking?
require 'pp'
account = Fog::Rackspace::Monitoring.new
entity_id = nil
tests('success') do
tests('#create new entity').formats(DATA_FORMAT) do
response = account.create_entity(:label => "Foo").data
entity_id = response[:headers]["X-Object-ID"]
response[:status] == 201 ? response : false
end
tests('#update entity').formats(DATA_FORMAT) do
options = { :testing => "Bar"}
response = account.update_entity(entity_id,options).data
response[:status] == 204 ? response : false
end
tests('#delete entity').formats(DELETE_DATA_FORMAT) do
response = account.delete_entity(entity_id).data
response[:status] == 204 ? response : false
end
end
end
__END__
tests('failure') do
tests('#create new entity(-1)').raises(Fog::Rackspace::Monitoring::BadRequest) do
response = account.create_entity(:label => "").data
puts "I made it this far"
pp response
puts "All done now"
end
tests('#update entity(-1)').raises(Fog::Rackspace::Monitoring::Notfound) do
entity_id = account.create_entity(:label => "Foo").data[:headers]["X-Object-ID"] #setup
options = { :testing => "Bar" }
response = account.update_entity(entity_id,options)
puts ""
pp response
account.delete_entity(entity_id) #cleanup
response
end
tests('#delete entity(-1)').raises(Fog::Rackspace::Monitoring::NotFound) do
account.delete_entity(-1)
end
end
end

View file

@ -0,0 +1,27 @@
DELETE_HEADERS_FORMAT = {
'X-LB' => String,
'X-Response-Id' => String,
'X-RateLimit-Remaining' => String,
'X-RateLimit-Window' => 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,
})
DATA_FORMAT = {
:status => Integer,
:body => String,
:headers => HEADERS_FORMAT,
:remote_ip => String
}
DELETE_DATA_FORMAT = {
:status => Integer,
:body => String,
:headers => DELETE_HEADERS_FORMAT,
:remote_ip => String
}