2010-11-16 15:31:34 -08:00
|
|
|
def collection_tests(collection, params = {}, mocks_implemented = true)
|
2010-11-11 13:54:55 -06:00
|
|
|
tests('success') do
|
2014-08-07 00:58:55 +00:00
|
|
|
|
2010-11-11 13:54:55 -06: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 16:53:01 -05:00
|
|
|
# FIXME: work around for timing issue on AWS describe_instances mocks
|
2014-08-07 00:58:55 +00:00
|
|
|
|
2011-09-23 16:53:01 -05:00
|
|
|
if Fog.mocking? && @instance.respond_to?(:ready?)
|
|
|
|
@instance.wait_for { ready? }
|
|
|
|
end
|
2014-08-07 00:58:55 +00:00
|
|
|
|
2010-11-11 13:54:55 -06:00
|
|
|
tests("#all").succeeds do
|
|
|
|
pending if Fog.mocking? && !mocks_implemented
|
|
|
|
collection.all
|
|
|
|
end
|
2014-08-07 00:58:55 +00:00
|
|
|
|
2010-11-16 13:24:43 -08:00
|
|
|
if !Fog.mocking? || mocks_implemented
|
|
|
|
@identity = @instance.identity
|
|
|
|
end
|
2014-08-07 00:58:55 +00:00
|
|
|
|
2010-11-11 13:54:55 -06:00
|
|
|
tests("#get(#{@identity})").succeeds do
|
|
|
|
pending if Fog.mocking? && !mocks_implemented
|
|
|
|
collection.get(@identity)
|
|
|
|
end
|
2014-08-07 00:58:55 +00:00
|
|
|
|
2013-03-13 09:39:38 +01:00
|
|
|
tests('Enumerable') do
|
|
|
|
pending if Fog.mocking? && !mocks_implemented
|
|
|
|
|
2013-11-25 16:43:29 +01:00
|
|
|
methods = [
|
2013-07-10 17:41:12 -07:00
|
|
|
'all?', 'any?', 'find', 'detect', 'collect', 'map',
|
2013-03-13 09:39:38 +01:00
|
|
|
'find_index', 'flat_map', 'collect_concat', 'group_by',
|
|
|
|
'none?', 'one?'
|
2013-11-25 16:43:29 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
# JRuby 1.7.5+ issue causes a SystemStackError: stack level too deep
|
|
|
|
# https://github.com/jruby/jruby/issues/1265
|
|
|
|
if RUBY_PLATFORM == "java" and JRUBY_VERSION =~ /1\.7\.[5-8]/
|
|
|
|
methods.delete('all?')
|
|
|
|
end
|
2014-08-07 00:58:55 +00:00
|
|
|
|
2013-11-25 16:43:29 +01:00
|
|
|
methods.each do |enum_method|
|
2013-03-13 09:39:38 +01: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 13:54:55 -06:00
|
|
|
if block_given?
|
2014-06-16 11:59:19 +03:00
|
|
|
yield(@instance)
|
2010-11-11 13:54:55 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
if !Fog.mocking? || mocks_implemented
|
|
|
|
@instance.destroy
|
|
|
|
end
|
|
|
|
end
|
2013-07-10 17:41:12 -07:00
|
|
|
|
2010-11-11 13:54:55 -06:00
|
|
|
tests('failure') do
|
|
|
|
|
2010-11-16 13:24:43 -08:00
|
|
|
if !Fog.mocking? || mocks_implemented
|
2011-07-22 11:46:55 -05:00
|
|
|
@identity = @identity.to_s
|
2011-08-16 12:22:15 -05:00
|
|
|
@identity = @identity.gsub(/[a-zA-Z]/) { Fog::Mock.random_letters(1) }
|
|
|
|
@identity = @identity.gsub(/\d/) { Fog::Mock.random_numbers(1) }
|
2011-07-22 11:46:55 -05:00
|
|
|
@identity
|
2010-11-16 13:24:43 -08:00
|
|
|
end
|
2010-11-11 13:54:55 -06:00
|
|
|
|
|
|
|
tests("#get('#{@identity}')").returns(nil) do
|
|
|
|
pending if Fog.mocking? && !mocks_implemented
|
|
|
|
collection.get(@identity)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|