Skip to content

Commit ad08049

Browse files
committed
refactor to avoid defaultInstances
1 parent 83e9781 commit ad08049

File tree

2 files changed

+7
-26
lines changed

2 files changed

+7
-26
lines changed

packages/core/src/awsService/ec2/explorer/ec2ParentNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class Ec2ParentNode extends AWSTreeNodeBase {
5757
if (childNode) {
5858
return childNode
5959
} else {
60-
throw new Error(`Node with id ${instanceId} not found`)
60+
throw new Error(`Node with id ${instanceId} from polling set not found`)
6161
}
6262
}
6363

packages/core/src/test/awsService/ec2/explorer/ec2ParentNode.test.ts

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,13 @@ import { EC2 } from 'aws-sdk'
1717
import { AsyncCollection } from '../../../../shared/utilities/asyncCollection'
1818
import * as FakeTimers from '@sinonjs/fake-timers'
1919
import { installFakeClock } from '../../../testUtil'
20-
import { PollingSet } from '../../../../shared/utilities/pollingSet'
2120

2221
describe('ec2ParentNode', function () {
2322
let testNode: Ec2ParentNode
24-
let defaultInstances: SafeEc2Instance[]
2523
let client: Ec2Client
2624
let getInstanceStub: sinon.SinonStub<[filters?: EC2.Filter[] | undefined], Promise<AsyncCollection<EC2.Instance>>>
2725
let clock: FakeTimers.InstalledClock
2826
let refreshStub: sinon.SinonStub<[], Promise<void>>
29-
let clearTimerStub: sinon.SinonStub<[], void>
3027

3128
const testRegion = 'testRegion'
3229
const testPartition = 'testPartition'
@@ -45,32 +42,12 @@ describe('ec2ParentNode', function () {
4542
client = new Ec2Client(testRegion)
4643
clock = installFakeClock()
4744
refreshStub = sinon.stub(Ec2InstanceNode.prototype, 'refreshNode')
48-
clearTimerStub = sinon.stub(PollingSet.prototype, 'clearTimer')
49-
defaultInstances = [
50-
{ Name: 'firstOne', InstanceId: '0', LastSeenStatus: 'running' },
51-
{ Name: 'secondOne', InstanceId: '1', LastSeenStatus: 'running' },
52-
]
5345
})
5446

5547
beforeEach(function () {
5648
getInstanceStub = sinon.stub(Ec2Client.prototype, 'getInstances')
57-
defaultInstances = [
58-
{ Name: 'firstOne', InstanceId: '0', LastSeenStatus: 'running' },
59-
{ Name: 'secondOne', InstanceId: '1', LastSeenStatus: 'stopped' },
60-
]
61-
62-
getInstanceStub.callsFake(async () =>
63-
intoCollection(
64-
defaultInstances.map((instance) => ({
65-
InstanceId: instance.InstanceId,
66-
Tags: [{ Key: 'Name', Value: instance.Name }],
67-
}))
68-
)
69-
)
70-
7149
testNode = new Ec2ParentNode(testRegion, testPartition, client)
7250
refreshStub.resetHistory()
73-
clearTimerStub.resetHistory()
7451
})
7552

7653
afterEach(function () {
@@ -91,10 +68,14 @@ describe('ec2ParentNode', function () {
9168
})
9269

9370
it('has instance child nodes', async function () {
94-
getInstanceStub.resolves(mapToInstanceCollection(defaultInstances))
71+
const instances = [
72+
{ Name: 'firstOne', InstanceId: '0', LastSeenStatus: 'running' },
73+
{ Name: 'secondOne', InstanceId: '1', LastSeenStatus: 'stopped' },
74+
]
75+
getInstanceStub.resolves(mapToInstanceCollection(instances))
9576
const childNodes = await testNode.getChildren()
9677

97-
assert.strictEqual(childNodes.length, defaultInstances.length, 'Unexpected child count')
78+
assert.strictEqual(childNodes.length, instances.length, 'Unexpected child count')
9879

9980
childNodes.forEach((node) =>
10081
assert.ok(node instanceof Ec2InstanceNode, 'Expected child node to be Ec2InstanceNode')

0 commit comments

Comments
 (0)