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
|
2014-08-06 20:58:55 -04:00
|
|
|
|
2010-11-11 14:54:55 -05:00
|
|
|
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
|
2014-08-06 20:58:55 -04:00
|
|
|
|
2011-09-23 17:53:01 -04:00
|
|
|
if Fog.mocking? && @instance.respond_to?(:ready?)
|
|
|
|
@instance.wait_for { ready? }
|
|
|
|
end
|
2014-08-06 20:58:55 -04:00
|
|
|
|
2010-11-11 14:54:55 -05:00
|
|
|
tests("#all").succeeds do
|
|
|
|
pending if Fog.mocking? && !mocks_implemented
|
|
|
|
collection.all
|
|
|
|
end
|
2014-08-06 20:58:55 -04:00
|
|
|
|
2010-11-16 16:24:43 -05:00
|
|
|
if !Fog.mocking? || mocks_implemented
|
|
|
|
@identity = @instance.identity
|
|
|
|
end
|
2014-08-06 20:58:55 -04:00
|
|
|
|
2010-11-11 14:54:55 -05:00
|
|
|
tests("#get(#{@identity})").succeeds do
|
|
|
|
pending if Fog.mocking? && !mocks_implemented
|
|
|
|
collection.get(@identity)
|
|
|
|
end
|
2014-08-06 20:58:55 -04:00
|
|
|
|
2013-03-13 04:39:38 -04:00
|
|
|
tests('Enumerable') do
|
|
|
|
pending if Fog.mocking? && !mocks_implemented
|
|
|
|
|
2013-11-25 10:43:29 -05:00
|
|
|
methods = [
|
2013-07-10 20:41:12 -04:00
|
|
|
'all?', 'any?', 'find', 'detect', 'collect', 'map',
|
2013-03-13 04:39:38 -04:00
|
|
|
'find_index', 'flat_map', 'collect_concat', 'group_by',
|
|
|
|
'none?', 'one?'
|
2013-11-25 10:43:29 -05:00
|
|
|
]
|
|
|
|
|
|
|
|
methods.each do |enum_method|
|
2013-03-13 04:39:38 -04:00
|
|
|
if collection.respond_to?(enum_method)
|
|
|
|
tests("##{enum_method}").succeeds do
|
|
|
|
block_called = false
|
|
|
|
collection.send(enum_method) {|x| block_called = true }
|
|
|
|
block_called
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
[
|
|
|
|
'max_by','min_by'
|
|
|
|
].each do |enum_method|
|
|
|
|
if collection.respond_to?(enum_method)
|
|
|
|
tests("##{enum_method}").succeeds do
|
|
|
|
block_called = false
|
|
|
|
collection.send(enum_method) {|x| block_called = true; 0 }
|
|
|
|
block_called
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2010-11-11 14:54:55 -05:00
|
|
|
if block_given?
|
2014-06-16 04:59:19 -04:00
|
|
|
yield(@instance)
|
2010-11-11 14:54:55 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
if !Fog.mocking? || mocks_implemented
|
|
|
|
@instance.destroy
|
|
|
|
end
|
|
|
|
end
|
2013-07-10 20:41:12 -04:00
|
|
|
|
2010-11-11 14:54:55 -05:00
|
|
|
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
|