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

[rackspace|monitoring] adding mocks for get_entity

This commit is contained in:
Kyle Rames 2013-08-28 15:14:39 -05:00
parent f3e873bb1a
commit a170575984
2 changed files with 42 additions and 1 deletions

View file

@ -12,6 +12,39 @@ module Fog
end
end
class Mock
def get_entity(entity_id)
response = Excon::Response.new
response.status = 200
response.body = {
"id" => entity_id,
"label"=>"mocked_fog_entitiy",
"ip_addresses"=>{
"private0_v4"=>"10.0.0.1"
},
"metadata"=>nil,
"managed"=>false,
"uri"=>"https://ord.servers.api.rackspacecloud.com/5555/servers/23kj2q4hk234",
"agent_id"=>nil,
"created_at"=> Time.now.to_i - 5000,
"updated_at"=> Time.now.to_i
}
response.headers = {
"Date"=> Time.now.utc.to_s,
"Content-Type"=>"application/json; charset=UTF-8",
"X-RateLimit-Limit"=>"50000",
"X-RateLimit-Remaining"=>"49627",
"X-RateLimit-Window"=>"24 hours",
"X-RateLimit-Type"=>"global",
"X-Response-Id"=>"j23jlk234jl2j34j",
"X-LB"=>"dfw1-maas-prod-api0",
"Vary"=>"Accept-Encoding",
"Transfer-Encoding"=>"chunked"
}
response
end
end
end
end
end

View file

@ -1,9 +1,9 @@
Shindo.tests('Fog::Rackspace::Monitoring | entity_tests', ['rackspace','rackspace_monitoring']) do
pending if Fog.mocking?
account = Fog::Rackspace::Monitoring.new
entity_id = nil
tests('success') do
tests('#create new entity').formats(DATA_FORMAT) do
pending if Fog.mocking?
response = account.create_entity(:label => "Foo").data
entity_id = response[:headers]["X-Object-ID"]
response
@ -12,25 +12,33 @@ Shindo.tests('Fog::Rackspace::Monitoring | entity_tests', ['rackspace','rackspac
account.get_entity(entity_id).data[:headers]
end
tests('#update entity').formats(DATA_FORMAT) do
pending if Fog.mocking?
options = { :testing => "Bar"}
account.update_entity(entity_id,options).data
end
tests('#delete entity').formats(DELETE_DATA_FORMAT) do
pending if Fog.mocking?
account.delete_entity(entity_id).data
end
end
tests('failure') do
tests('#create new entity(-1)').raises(Fog::Rackspace::Monitoring::BadRequest) do
pending if Fog.mocking?
account.create_entity(:label => "")
end
tests('#get entity(-1)').raises(Fog::Rackspace::Monitoring::NotFound) do
pending if Fog.mocking?
account.get_entity(-1)
end
tests('#update invalid entity(-1)').raises(Fog::Rackspace::Monitoring::NotFound) do
pending if Fog.mocking?
options = { :testing => "Bar" }
response = account.update_entity(-1,options)
end
tests('#delete entity(-1)').raises(Fog::Rackspace::Monitoring::NotFound) do
pending if Fog.mocking?
account.delete_entity(-1)
end
end