Skip to content

Commit 6eb3450

Browse files
committed
reformat and rearrange tests
1 parent 2f393c8 commit 6eb3450

File tree

2 files changed

+40
-39
lines changed

2 files changed

+40
-39
lines changed

src/ec2/model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ export class Ec2ConnectionManager {
184184
this.throwGeneralConnectionError(selection, err as Error)
185185
}
186186
}
187+
187188
public async prepareEc2RemoteEnvWithProgress(selection: Ec2Selection, remoteUser: string): Promise<Ec2RemoteEnv> {
188189
const timeout = new Timeout(60000)
189190
await showMessageWithCancel('AWS: Opening remote connection...', timeout)

src/test/ec2/model.test.ts

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,45 @@ describe('Ec2ConnectClient', function () {
4343
})
4444
})
4545

46+
describe('hasProperPolicies', async function () {
47+
it('correctly determines if proper policies are included', async function () {
48+
async function assertAcceptsPolicies(policies: IAM.Policy[], expectedResult: boolean) {
49+
sinon.stub(DefaultIamClient.prototype, 'listAttachedRolePolicies').resolves(policies)
50+
51+
const result = await client.hasProperPolicies('')
52+
assert.strictEqual(result, expectedResult)
53+
54+
sinon.restore()
55+
}
56+
await assertAcceptsPolicies(
57+
[{ PolicyName: 'name' }, { PolicyName: 'name2' }, { PolicyName: 'name3' }],
58+
false
59+
)
60+
await assertAcceptsPolicies(
61+
[
62+
{ PolicyName: 'AmazonSSMManagedInstanceCore' },
63+
{ PolicyName: 'AmazonSSMManagedEC2InstanceDefaultPolicy' },
64+
],
65+
true
66+
)
67+
await assertAcceptsPolicies([{ PolicyName: 'AmazonSSMManagedEC2InstanceDefaultPolicy' }], false)
68+
await assertAcceptsPolicies([{ PolicyName: 'AmazonSSMManagedEC2InstanceDefaultPolicy' }], false)
69+
})
70+
71+
it('throws error when sdk throws error', async function () {
72+
sinon.stub(DefaultIamClient.prototype, 'listAttachedRolePolicies').throws(new ToolkitError('error'))
73+
74+
try {
75+
await client.hasProperPolicies('')
76+
assert.ok(false)
77+
} catch {
78+
assert.ok(true)
79+
}
80+
81+
sinon.restore()
82+
})
83+
})
84+
4685
describe('isInstanceRunning', async function () {
4786
it('only returns true with the instance is running', async function () {
4887
sinon.stub(Ec2Client.prototype, 'getInstanceStatus').callsFake(async (input: string) => input.split(':')[0])
@@ -118,45 +157,6 @@ describe('Ec2ConnectClient', function () {
118157
})
119158
})
120159

121-
describe('hasProperPolicies', async function () {
122-
it('correctly determines if proper policies are included', async function () {
123-
async function assertAcceptsPolicies(policies: IAM.Policy[], expectedResult: boolean) {
124-
sinon.stub(DefaultIamClient.prototype, 'listAttachedRolePolicies').resolves(policies)
125-
126-
const result = await client.hasProperPolicies('')
127-
assert.strictEqual(result, expectedResult)
128-
129-
sinon.restore()
130-
}
131-
await assertAcceptsPolicies(
132-
[{ PolicyName: 'name' }, { PolicyName: 'name2' }, { PolicyName: 'name3' }],
133-
false
134-
)
135-
await assertAcceptsPolicies(
136-
[
137-
{ PolicyName: 'AmazonSSMManagedInstanceCore' },
138-
{ PolicyName: 'AmazonSSMManagedEC2InstanceDefaultPolicy' },
139-
],
140-
true
141-
)
142-
await assertAcceptsPolicies([{ PolicyName: 'AmazonSSMManagedEC2InstanceDefaultPolicy' }], false)
143-
await assertAcceptsPolicies([{ PolicyName: 'AmazonSSMManagedEC2InstanceDefaultPolicy' }], false)
144-
})
145-
146-
it('throws error when sdk throws error', async function () {
147-
sinon.stub(DefaultIamClient.prototype, 'listAttachedRolePolicies').throws(new ToolkitError('error'))
148-
149-
try {
150-
await client.hasProperPolicies('')
151-
assert.ok(false)
152-
} catch {
153-
assert.ok(true)
154-
}
155-
156-
sinon.restore()
157-
})
158-
})
159-
160160
describe('sendSshKeysToInstance', async function () {
161161
it('calls the sdk with the proper parameters', async function () {
162162
const sendCommandStub = sinon.stub(SsmClient.prototype, 'sendCommandAndWait')

0 commit comments

Comments
 (0)