-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #283 from ekristen/issue-279
feat(iam-role): add new properties (name, path, dates and more)
- Loading branch information
Showing
11 changed files
with
532 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package resources | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/golang/mock/gomock" | ||
"github.com/gotidy/ptr" | ||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/aws/aws-sdk-go/aws/awserr" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/iam" | ||
|
||
"github.com/ekristen/aws-nuke/v3/mocks/mock_iamiface" | ||
"github.com/ekristen/aws-nuke/v3/pkg/nuke" | ||
) | ||
|
||
func Test_Mock_IAMInstanceProfile_List(t *testing.T) { | ||
a := assert.New(t) | ||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
|
||
mockIAM := mock_iamiface.NewMockIAMAPI(ctrl) | ||
|
||
instanceProfile := &iam.InstanceProfile{ | ||
Arn: ptr.String("arn:aws:iam::123456789012:instance-profile/profile:foobar"), | ||
InstanceProfileName: ptr.String("profile:foobar"), | ||
CreateDate: ptr.Time(time.Now()), | ||
Roles: []*iam.Role{ | ||
{ | ||
Arn: ptr.String("arn:aws:iam::123456789012:role/role:foobar"), | ||
RoleName: ptr.String("role:foobar"), | ||
}, | ||
}, | ||
} | ||
|
||
instanceProfile2 := &iam.InstanceProfile{ | ||
Arn: ptr.String("arn:aws:iam::123456789012:instance-profile/profile:foobar2"), | ||
InstanceProfileName: ptr.String("profile:foobar2"), | ||
CreateDate: ptr.Time(time.Now()), | ||
Roles: []*iam.Role{ | ||
{ | ||
Arn: ptr.String("arn:aws:iam::123456789012:role/role:foobar2"), | ||
RoleName: ptr.String("role:foobar2"), | ||
}, | ||
}, | ||
} | ||
|
||
mockIAM.EXPECT().ListInstanceProfiles(gomock.Any()).Return(&iam.ListInstanceProfilesOutput{ | ||
InstanceProfiles: []*iam.InstanceProfile{ | ||
instanceProfile, | ||
instanceProfile2, | ||
}, | ||
}, nil) | ||
|
||
mockIAM.EXPECT().GetInstanceProfile(&iam.GetInstanceProfileInput{ | ||
InstanceProfileName: ptr.String("profile:foobar"), | ||
}).Return(&iam.GetInstanceProfileOutput{ | ||
InstanceProfile: instanceProfile, | ||
}, nil) | ||
|
||
mockIAM.EXPECT().GetInstanceProfile(&iam.GetInstanceProfileInput{ | ||
InstanceProfileName: ptr.String("profile:foobar2"), | ||
}).Return(nil, awserr.New("400", "InstanceProfileNotFound", nil)) | ||
|
||
lister := IAMInstanceProfileLister{ | ||
mockSvc: mockIAM, | ||
} | ||
|
||
resources, err := lister.List(context.TODO(), &nuke.ListerOpts{ | ||
Region: &nuke.Region{ | ||
Name: "us-east-2", | ||
}, | ||
Session: session.Must(session.NewSession()), | ||
}) | ||
|
||
a.Nil(err) | ||
a.Len(resources, 1) | ||
} | ||
|
||
func Test_Mock_IAMInstanceProfile_Remove(t *testing.T) { | ||
a := assert.New(t) | ||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
|
||
mockIAM := mock_iamiface.NewMockIAMAPI(ctrl) | ||
|
||
iamInstanceProfile := IAMInstanceProfile{ | ||
svc: mockIAM, | ||
Name: ptr.String("ip:foobar"), | ||
Path: ptr.String("/"), | ||
} | ||
|
||
mockIAM.EXPECT().DeleteInstanceProfile(gomock.Eq(&iam.DeleteInstanceProfileInput{ | ||
InstanceProfileName: iamInstanceProfile.Name, | ||
})).Return(&iam.DeleteInstanceProfileOutput{}, nil) | ||
|
||
err := iamInstanceProfile.Remove(context.TODO()) | ||
a.Nil(err) | ||
} | ||
|
||
func Test_Mock_IAMInstanceProfile_Properties(t *testing.T) { | ||
a := assert.New(t) | ||
|
||
iamInstanceProfile := IAMInstanceProfile{ | ||
Name: ptr.String("ip:foobar"), | ||
Path: ptr.String("/"), | ||
Tags: []*iam.Tag{ | ||
{ | ||
Key: ptr.String("foo"), | ||
Value: ptr.String("bar"), | ||
}, | ||
}, | ||
} | ||
|
||
a.Equal("ip:foobar", iamInstanceProfile.Properties().Get("Name")) | ||
a.Equal("/", iamInstanceProfile.Properties().Get("Path")) | ||
a.Equal("bar", iamInstanceProfile.Properties().Get("tag:foo")) | ||
|
||
a.Equal("ip:foobar", iamInstanceProfile.String()) | ||
} |
Oops, something went wrong.