Skip to content

Commit ba6afbf

Browse files
committed
fix failing tests
1 parent aab45f7 commit ba6afbf

File tree

3 files changed

+37
-219
lines changed

3 files changed

+37
-219
lines changed

src/test/ec2/explorer/ec2ParentNode.test.ts

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,44 @@
44
*/
55

66
import * as assert from 'assert'
7+
import * as sinon from 'sinon'
78
import { Ec2ParentNode, contextValueEc2 } from '../../../ec2/explorer/ec2ParentNode'
8-
import { stub } from '../../utilities/stubber'
99
import { Ec2Client, Ec2Instance } from '../../../shared/clients/ec2Client'
1010
import { intoCollection } from '../../../shared/utilities/collectionUtils'
1111
import {
1212
assertNodeListOnlyHasErrorNode,
1313
assertNodeListOnlyHasPlaceholderNode,
1414
} from '../../utilities/explorerNodeAssertions'
1515
import { Ec2InstanceNode } from '../../../ec2/explorer/ec2InstanceNode'
16+
import { EC2 } from 'aws-sdk'
17+
import { AsyncCollection } from '../../../shared/utilities/asyncCollection'
1618

1719
describe('ec2ParentNode', function () {
1820
let testNode: Ec2ParentNode
1921
let instances: Ec2Instance[]
22+
let client: Ec2Client
23+
let getInstanceStub: sinon.SinonStub<[filters?: EC2.Filter[] | undefined], Promise<AsyncCollection<EC2.Instance>>>
24+
2025
const testRegion = 'testRegion'
2126
const testPartition = 'testPartition'
2227

23-
function createClient() {
24-
const client = stub(Ec2Client, { regionCode: testRegion })
25-
client.getInstances.callsFake(async () =>
28+
before(function () {
29+
//getInstanceStub = sinon.stub(Ec2Client.prototype, 'getInstances')
30+
client = new Ec2Client(testRegion)
31+
})
32+
33+
after(function () {
34+
sinon.restore()
35+
})
36+
37+
beforeEach(function () {
38+
getInstanceStub = sinon.stub(Ec2Client.prototype, 'getInstances')
39+
instances = [
40+
{ name: 'firstOne', InstanceId: '0' },
41+
{ name: 'secondOne', InstanceId: '1' },
42+
]
43+
44+
getInstanceStub.callsFake(async () =>
2645
intoCollection(
2746
instances.map(instance => ({
2847
InstanceId: instance.InstanceId,
@@ -31,16 +50,11 @@ describe('ec2ParentNode', function () {
3150
)
3251
)
3352

34-
return client
35-
}
36-
37-
beforeEach(function () {
38-
instances = [
39-
{ name: 'firstOne', InstanceId: '0' },
40-
{ name: 'secondOne', InstanceId: '1' },
41-
]
53+
testNode = new Ec2ParentNode(testRegion, testPartition, client)
54+
})
4255

43-
testNode = new Ec2ParentNode(testRegion, testPartition, createClient())
56+
afterEach(function () {
57+
getInstanceStub.restore()
4458
})
4559

4660
it('returns placeholder node if no children are present', async function () {
@@ -87,11 +101,10 @@ describe('ec2ParentNode', function () {
87101
})
88102

89103
it('has an error node for a child if an error happens during loading', async function () {
90-
const client = createClient()
91-
client.getInstances.throws(new Error())
92-
104+
getInstanceStub.throws(new Error())
93105
const node = new Ec2ParentNode(testRegion, testPartition, client)
94106
assertNodeListOnlyHasErrorNode(await node.getChildren())
107+
getInstanceStub.restore()
95108
})
96109

97110
it('is able to handle children with duplicate names', async function () {

src/test/shared/clients/defaultEc2Client.test.ts

Lines changed: 0 additions & 196 deletions
This file was deleted.

src/test/shared/clients/ec2Client.test.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,14 @@ describe('extractInstancesFromReservations', function () {
103103
.getInstancesFromReservations(intoCollection([completeReservationsList]))
104104
.promise()
105105
assert.deepStrictEqual(actualResult, completeInstanceList)
106-
}),
107-
it('handles undefined and missing pieces in the ReservationList.', async function () {
108-
const actualResult = await client
109-
.getInstancesFromReservations(intoCollection([incompleteReservationsList]))
110-
.promise()
111-
assert.deepStrictEqual(actualResult, incomepleteInstanceList)
112-
})
106+
})
107+
108+
it('handles undefined and missing pieces in the ReservationList.', async function () {
109+
const actualResult = await client
110+
.getInstancesFromReservations(intoCollection([incompleteReservationsList]))
111+
.promise()
112+
assert.deepStrictEqual(actualResult, incomepleteInstanceList)
113+
})
113114
})
114115

115116
describe('updateInstancesDetail', async function () {

0 commit comments

Comments
 (0)