2010-11-16 18:31:34 -05:00
|
|
|
def collection_tests(collection, params = {}, mocks_implemented = true)
|
2010-11-11 14:54:55 -05:00
|
|
|
|
|
|
|
tests('success') do
|
|
|
|
|
|
|
|
tests("#new(#{params.inspect})").succeeds do
|
|
|
|
pending if Fog.mocking? && !mocks_implemented
|
|
|
|
collection.new(params)
|
|
|
|
end
|
|
|
|
|
|
|
|
tests("#create(#{params.inspect})").succeeds do
|
|
|
|
pending if Fog.mocking? && !mocks_implemented
|
|
|
|
@instance = collection.create(params)
|
|
|
|
end
|
|
|
|
|
2011-09-23 17:53:01 -04:00
|
|
|
# FIXME: work around for timing issue on AWS describe_instances mocks
|
|
|
|
if Fog.mocking? && @instance.respond_to?(:ready?)
|
|
|
|
@instance.wait_for { ready? }
|
|
|
|
end
|
|
|
|
|
2010-11-11 14:54:55 -05:00
|
|
|
tests("#all").succeeds do
|
|
|
|
pending if Fog.mocking? && !mocks_implemented
|
|
|
|
collection.all
|
|
|
|
end
|
|
|
|
|
2010-11-16 16:24:43 -05:00
|
|
|
if !Fog.mocking? || mocks_implemented
|
|
|
|
@identity = @instance.identity
|
|
|
|
end
|
2010-11-11 14:54:55 -05:00
|
|
|
|
|
|
|
tests("#get(#{@identity})").succeeds do
|
|
|
|
pending if Fog.mocking? && !mocks_implemented
|
|
|
|
collection.get(@identity)
|
|
|
|
end
|
|
|
|
|
|
|
|
if block_given?
|
|
|
|
yield
|
|
|
|
end
|
|
|
|
|
|
|
|
if !Fog.mocking? || mocks_implemented
|
|
|
|
@instance.destroy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
tests('failure') do
|
|
|
|
|
2010-11-16 16:24:43 -05:00
|
|
|
if !Fog.mocking? || mocks_implemented
|
2011-07-22 12:46:55 -04:00
|
|
|
@identity = @identity.to_s
|
2011-08-16 13:22:15 -04:00
|
|
|
@identity = @identity.gsub(/[a-zA-Z]/) { Fog::Mock.random_letters(1) }
|
|
|
|
@identity = @identity.gsub(/\d/) { Fog::Mock.random_numbers(1) }
|
2011-07-22 12:46:55 -04:00
|
|
|
@identity
|
2010-11-16 16:24:43 -05:00
|
|
|
end
|
2010-11-11 14:54:55 -05:00
|
|
|
|
|
|
|
tests("#get('#{@identity}')").returns(nil) do
|
|
|
|
pending if Fog.mocking? && !mocks_implemented
|
|
|
|
collection.get(@identity)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|