mirror of
https://github.com/fog/fog-aws.git
synced 2022-11-09 13:50:52 -05:00
assert collection is paged
This commit is contained in:
parent
edbec30380
commit
1ade2645f3
3 changed files with 20 additions and 5 deletions
|
@ -13,7 +13,9 @@ module Fog
|
|||
to_a.each(*args, &block)
|
||||
end
|
||||
|
||||
def each
|
||||
def each(options={})
|
||||
limit = options[:limit] || 100
|
||||
|
||||
if !block_given?
|
||||
self
|
||||
else
|
||||
|
@ -23,7 +25,7 @@ module Fog
|
|||
|
||||
while subset.truncated
|
||||
subset.
|
||||
all(:marker => subset.marker, :limit => 1000).
|
||||
all(:marker => subset.marker, :limit => limit).
|
||||
each_entry { |f| yield f }
|
||||
end
|
||||
|
||||
|
|
|
@ -7,13 +7,16 @@ module Fog
|
|||
|
||||
model Fog::AWS::IAM::Role
|
||||
|
||||
def all
|
||||
load(service.list_roles.body['Roles'])
|
||||
def all(options={})
|
||||
body = service.list_roles(page_params(options)).body
|
||||
|
||||
merge_attributes(body)
|
||||
load(body["Roles"])
|
||||
end
|
||||
|
||||
def get(identity)
|
||||
new(service.get_role(identity).body["Role"])
|
||||
rescue Excon::Errors::NotFound, Fog::AWS::IAM::NotFound # ignore not found error
|
||||
rescue Excon::Errors::NotFound, Fog::AWS::IAM::NotFound
|
||||
nil
|
||||
end
|
||||
|
||||
|
|
|
@ -52,6 +52,16 @@ Shindo.tests("Fog::Compute[:iam] | roles", ['aws','iam']) do
|
|||
@iam.roles.get(@role_one_name).destroy
|
||||
end
|
||||
|
||||
tests('#all', 'limit 1').succeeds do
|
||||
1 == @iam.roles.all(:limit => 1).size
|
||||
end
|
||||
|
||||
tests('#all', 'each_entry').succeeds do
|
||||
roles = []; @iam.roles.each(:limit => 1) { |r| roles << r }
|
||||
|
||||
3 == roles.size
|
||||
end
|
||||
|
||||
tests('#destroy','clean up remaining roles').succeeds do
|
||||
@iam.roles.get(@role_two_name).destroy
|
||||
@iam.roles.get(@role_three_name).destroy
|
||||
|
|
Loading…
Reference in a new issue