Issue 165: Add Test_IAMRepository_ListAllUserPolicies in iam_repository_test
parent
b4e04e0d77
commit
6e0a47ad67
|
@ -122,3 +122,92 @@ func Test_IAMRepository_ListAllAccessKeys(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_IAMRepository_ListAllUserPolicies(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
users []*iam.User
|
||||
mocks func(client *mocks.FakeIAM)
|
||||
want []string
|
||||
wantErr error
|
||||
}{
|
||||
{
|
||||
name: "List only user policies with multiple pages",
|
||||
users: []*iam.User{
|
||||
{
|
||||
UserName: aws.String("loadbalancer"),
|
||||
},
|
||||
{
|
||||
UserName: aws.String("loadbalancer2"),
|
||||
},
|
||||
},
|
||||
mocks: func(client *mocks.FakeIAM) {
|
||||
|
||||
client.On("ListUserPoliciesPages",
|
||||
&iam.ListUserPoliciesInput{
|
||||
UserName: aws.String("loadbalancer"),
|
||||
},
|
||||
mock.MatchedBy(func(callback func(res *iam.ListUserPoliciesOutput, lastPage bool) bool) bool {
|
||||
callback(&iam.ListUserPoliciesOutput{PolicyNames: []*string{
|
||||
aws.String("test"),
|
||||
aws.String("test2"),
|
||||
aws.String("test3"),
|
||||
}}, false)
|
||||
callback(&iam.ListUserPoliciesOutput{PolicyNames: []*string{
|
||||
aws.String("test4"),
|
||||
}}, true)
|
||||
return true
|
||||
})).Return(nil).Once()
|
||||
|
||||
client.On("ListUserPoliciesPages",
|
||||
&iam.ListUserPoliciesInput{
|
||||
UserName: aws.String("loadbalancer2"),
|
||||
},
|
||||
mock.MatchedBy(func(callback func(res *iam.ListUserPoliciesOutput, lastPage bool) bool) bool {
|
||||
callback(&iam.ListUserPoliciesOutput{PolicyNames: []*string{
|
||||
aws.String("test2"),
|
||||
aws.String("test22"),
|
||||
aws.String("test23"),
|
||||
}}, false)
|
||||
callback(&iam.ListUserPoliciesOutput{PolicyNames: []*string{
|
||||
aws.String("test24"),
|
||||
}}, true)
|
||||
return true
|
||||
})).Return(nil).Once()
|
||||
},
|
||||
want: []string{
|
||||
*aws.String("loadbalancer:test"),
|
||||
*aws.String("loadbalancer:test2"),
|
||||
*aws.String("loadbalancer:test3"),
|
||||
*aws.String("loadbalancer:test4"),
|
||||
*aws.String("loadbalancer2:test"),
|
||||
*aws.String("loadbalancer2:test2"),
|
||||
*aws.String("loadbalancer2:test3"),
|
||||
*aws.String("loadbalancer2:test4"),
|
||||
*aws.String("loadbalancer2:test2"),
|
||||
*aws.String("loadbalancer2:test22"),
|
||||
*aws.String("loadbalancer2:test23"),
|
||||
*aws.String("loadbalancer2:test24"),
|
||||
},
|
||||
},
|
||||
}
|
||||
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.ListAllUserPolicies(tt.users)
|
||||
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()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue