Skip to content

Commit 2f393c8

Browse files
committed
add coverage for the getAttachedIamRole method
1 parent fc4af9e commit 2f393c8

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/test/ec2/model.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,27 @@ describe('Ec2ConnectClient', function () {
2222
client = new Ec2ConnectionManager('test-region')
2323
})
2424

25+
describe('getAttachedIamRole', async function () {
26+
it('only returns role if recieves ARN from instance profile', async function () {
27+
let role: IAM.Role | undefined
28+
const getInstanceProfileStub = sinon.stub(Ec2Client.prototype, 'getAttachedIamInstanceProfile')
29+
30+
getInstanceProfileStub.resolves({ Arn: 'thisIsAnArn' })
31+
sinon
32+
.stub(DefaultIamClient.prototype, 'getIAMRoleFromInstanceProfile')
33+
.resolves({ Arn: 'ThisIsARoleArn' } as IAM.Role)
34+
35+
role = await client.getAttachedIamRole('test-instance')
36+
assert.ok(role)
37+
assert.ok(role.Arn)
38+
39+
getInstanceProfileStub.resolves({})
40+
role = await client.getAttachedIamRole('test-instance')
41+
assert.strictEqual(role, undefined)
42+
sinon.restore()
43+
})
44+
})
45+
2546
describe('isInstanceRunning', async function () {
2647
it('only returns true with the instance is running', async function () {
2748
sinon.stub(Ec2Client.prototype, 'getInstanceStatus').callsFake(async (input: string) => input.split(':')[0])

0 commit comments

Comments
 (0)