Issue 165: Add Test_IAMRepository_ListAllRoles in iam_repository_test

main
Louis TOUSSAINT 2021-04-23 21:00:43 +02:00
parent 09f3f82a97
commit 6c29aa04ff
1 changed files with 69 additions and 0 deletions

View File

@ -122,6 +122,75 @@ func Test_IAMRepository_ListAllAccessKeys(t *testing.T) {
})
}
}
func Test_IAMRepository_ListAllRoles(t *testing.T) {
tests := []struct {
name string
mocks func(client *mocks.FakeIAM)
want []*iam.Role
wantErr error
}{
{
name: "List only roles with multiple pages",
mocks: func(client *mocks.FakeIAM) {
client.On("ListRolesPages",
&iam.ListRolesInput{},
mock.MatchedBy(func(callback func(res *iam.ListRolesOutput, lastPage bool) bool) bool {
callback(&iam.ListRolesOutput{Roles: []*iam.Role{
{
RoleName: aws.String("test-driftctl"),
},
{
RoleName: aws.String("test-driftctl2"),
},
}}, false)
callback(&iam.ListRolesOutput{Roles: []*iam.Role{
{
RoleName: aws.String("test-driftctl3"),
},
{
RoleName: aws.String("test-driftctl4"),
},
}}, true)
return true
})).Return(nil)
},
want: []*iam.Role{
{
RoleName: aws.String("test-driftctl"),
},
{
RoleName: aws.String("test-driftctl2"),
},
{
RoleName: aws.String("test-driftctl3"),
},
{
RoleName: aws.String("test-driftctl4"),
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
client := &mocks.FakeIAM{}
tt.mocks(client)
r := &iamRepository{
client: client,
}
got, err := r.ListAllRoles()
assert.Equal(t, tt.wantErr, err)
changelog, err := diff.Diff(got, tt.want)
assert.Nil(t, err)
if len(changelog) > 0 {
for _, change := range changelog {
t.Errorf("%s: %v -> %v", strings.Join(change.Path, "."), change.From, change.To)
}
t.Fail()
}
})
}
}
func Test_IAMRepository_ListAllUserPolicyAttachments(t *testing.T) {
tests := []struct {