4
4
*/
5
5
6
6
import * as assert from 'assert'
7
+ import * as sinon from 'sinon'
7
8
import { Ec2ParentNode , contextValueEc2 } from '../../../ec2/explorer/ec2ParentNode'
8
- import { stub } from '../../utilities/stubber'
9
9
import { Ec2Client , Ec2Instance } from '../../../shared/clients/ec2Client'
10
10
import { intoCollection } from '../../../shared/utilities/collectionUtils'
11
11
import {
12
12
assertNodeListOnlyHasErrorNode ,
13
13
assertNodeListOnlyHasPlaceholderNode ,
14
14
} from '../../utilities/explorerNodeAssertions'
15
15
import { Ec2InstanceNode } from '../../../ec2/explorer/ec2InstanceNode'
16
+ import { EC2 } from 'aws-sdk'
17
+ import { AsyncCollection } from '../../../shared/utilities/asyncCollection'
16
18
17
19
describe ( 'ec2ParentNode' , function ( ) {
18
20
let testNode : Ec2ParentNode
19
21
let instances : Ec2Instance [ ]
22
+ let client : Ec2Client
23
+ let getInstanceStub : sinon . SinonStub < [ filters ?: EC2 . Filter [ ] | undefined ] , Promise < AsyncCollection < EC2 . Instance > > >
24
+
20
25
const testRegion = 'testRegion'
21
26
const testPartition = 'testPartition'
22
27
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 ( ) =>
26
45
intoCollection (
27
46
instances . map ( instance => ( {
28
47
InstanceId : instance . InstanceId ,
@@ -31,16 +50,11 @@ describe('ec2ParentNode', function () {
31
50
)
32
51
)
33
52
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
+ } )
42
55
43
- testNode = new Ec2ParentNode ( testRegion , testPartition , createClient ( ) )
56
+ afterEach ( function ( ) {
57
+ getInstanceStub . restore ( )
44
58
} )
45
59
46
60
it ( 'returns placeholder node if no children are present' , async function ( ) {
@@ -87,11 +101,10 @@ describe('ec2ParentNode', function () {
87
101
} )
88
102
89
103
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 ( ) )
93
105
const node = new Ec2ParentNode ( testRegion , testPartition , client )
94
106
assertNodeListOnlyHasErrorNode ( await node . getChildren ( ) )
107
+ getInstanceStub . restore ( )
95
108
} )
96
109
97
110
it ( 'is able to handle children with duplicate names' , async function ( ) {
0 commit comments