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

more instance profile mocks

This commit is contained in:
Eugene Howe 2017-01-19 13:24:44 -05:00
parent 337c7560a8
commit 8689919d77
6 changed files with 46 additions and 0 deletions

View file

@ -50,6 +50,11 @@ module Fog
service.managed_policies(:role_name => self.rolename)
end
def instance_profiles
requires :rolename
service.instance_profiles.load(service.list_instance_profiles_for_role(self.rolename).body["InstanceProfiles"])
end
def destroy
requires :rolename

View file

@ -43,6 +43,15 @@ module Fog
}.merge!(options))
end
end
class Mock
def list_instance_profiles(options={})
response = Excon::Response.new
profiles = self.data[:instance_profiles].values
response.body = { "InstanceProfiles" => profiles, "IsTruncated" => false, "RequestId" => Fog::AWS::Mock.request_id }
response
end
end
end
end
end

View file

@ -44,6 +44,16 @@ module Fog
}.merge!(options))
end
end
class Mock
def list_instance_profiles_for_role(role_name, options={})
response = Excon::Response.new
profiles = self.data[:instance_profiles].values.select { |p| p["Roles"].include?(role_name) }
response.body = { "InstanceProfiles" => profiles, "IsTruncated" => false, "RequestId" => Fog::AWS::Mock.request_id }
response
end
end
end
end
end

View file

@ -6,6 +6,9 @@ Shindo.tests("Fog::AWS[:iam] | instance_profiles", ['aws', 'iam']) do
returns(true) { @instance.add_role(@role.rolename) }
end
returns(1) { @role.instance_profiles.count }
returns(@instance) { @role.instance_profiles.first }
tests("#remove_role('#{@role.rolename}')") do
returns(true) { @instance.remove_role(@role.rolename) }
end

View file

@ -144,6 +144,11 @@ Xb9WSr07saxZQbxBPQyTlb0Q9Tu2djAq2/o/nYD1/50/fXUTuWMB
INSTANCE_PROFILE_RESULT = BASIC.merge(
'InstanceProfile' => INSTANCE_PROFILE
)
LIST_INSTANCE_PROFILE_RESULT = BASIC.merge(
"IsTruncated" => Fog::Boolean,
"InstanceProfiles" => [INSTANCE_PROFILE]
)
end
end
end

View file

@ -3,10 +3,18 @@ include AWS::IAM::Formats
Shindo.tests("AWS::IAM | instance profile requests", ['aws']) do
tests('success') do
profile_name = uniq_id('fog-instance-profile')
@instance_profile_count = Fog::AWS[:iam].list_instance_profiles.body["InstanceProfiles"].count
tests("#create_instance_profile('#{profile_name}')").formats(INSTANCE_PROFILE_RESULT) do
Fog::AWS[:iam].create_instance_profile(profile_name).body
end
tests("#list_instance_profiles").formats(LIST_INSTANCE_PROFILE_RESULT) do
body = Fog::AWS[:iam].list_instance_profiles.body
returns(@instance_profile_count + 1) { body["InstanceProfiles"].count }
body
end
tests("#get_instance_profile('#{profile_name}')").formats(INSTANCE_PROFILE_RESULT) do
Fog::AWS[:iam].get_instance_profile(profile_name).body
end
@ -17,6 +25,12 @@ Shindo.tests("AWS::IAM | instance profile requests", ['aws']) do
Fog::AWS[:iam].add_role_to_instance_profile(@role.rolename, profile_name).body
end
tests("#list_instance_profiles_for_role('#{@role.rolename}')").formats(LIST_INSTANCE_PROFILE_RESULT) do
body = Fog::AWS[:iam].list_instance_profiles_for_role(@role.rolename).body
returns(1) { body["InstanceProfiles"].count }
body
end
tests("#remove_role_from_instance_profile('#{@role.rolename}', '#{profile_name}')").formats(BASIC) do
Fog::AWS[:iam].remove_role_from_instance_profile(@role.rolename, profile_name).body
end