6
6
import * as assert from 'assert'
7
7
import { Ec2ParentNode , contextValueEc2 } from '../../../ec2/explorer/ec2ParentNode'
8
8
import { stub } from '../../utilities/stubber'
9
- import { Ec2Client } from '../../../shared/clients/ec2Client'
9
+ import { Ec2Client , Ec2Instance } from '../../../shared/clients/ec2Client'
10
10
import { intoCollection } from '../../../shared/utilities/collectionUtils'
11
11
import {
12
12
assertNodeListOnlyHasErrorNode ,
@@ -16,28 +16,35 @@ import { Ec2InstanceNode } from '../../../ec2/explorer/ec2InstanceNode'
16
16
17
17
describe ( 'ec2ParentNode' , function ( ) {
18
18
let testNode : Ec2ParentNode
19
- let instanceNames : string [ ]
19
+ let instances : Ec2Instance [ ]
20
20
const testRegion = 'testRegion'
21
21
const testPartition = 'testPartition'
22
22
23
23
function createClient ( ) {
24
24
const client = stub ( Ec2Client , { regionCode : testRegion } )
25
25
client . getInstances . callsFake ( async ( ) =>
26
26
intoCollection (
27
- instanceNames . map ( name => ( { InstanceId : name + name , Tags : [ { Key : 'Name' , Value : name } ] } ) )
27
+ instances . map ( instance => ( {
28
+ InstanceId : instance . InstanceId ,
29
+ Tags : [ { Key : 'Name' , Value : instance . name } ] ,
30
+ } ) )
28
31
)
29
32
)
30
33
31
34
return client
32
35
}
33
36
34
37
beforeEach ( function ( ) {
35
- instanceNames = [ 'firstOne' , 'secondOne' ]
38
+ instances = [
39
+ { name : 'firstOne' , InstanceId : '0' } ,
40
+ { name : 'secondOne' , InstanceId : '1' } ,
41
+ ]
42
+
36
43
testNode = new Ec2ParentNode ( testRegion , testPartition , createClient ( ) )
37
44
} )
38
45
39
46
it ( 'returns placeholder node if no children are present' , async function ( ) {
40
- instanceNames = [ ]
47
+ instances = [ ]
41
48
42
49
const childNodes = await testNode . getChildren ( )
43
50
@@ -47,7 +54,7 @@ describe('ec2ParentNode', function () {
47
54
it ( 'has instance child nodes' , async function ( ) {
48
55
const childNodes = await testNode . getChildren ( )
49
56
50
- assert . strictEqual ( childNodes . length , instanceNames . length , 'Unexpected child count' )
57
+ assert . strictEqual ( childNodes . length , instances . length , 'Unexpected child count' )
51
58
52
59
childNodes . forEach ( node =>
53
60
assert . ok ( node instanceof Ec2InstanceNode , 'Expected child node to be Ec2InstanceNode' )
@@ -64,11 +71,18 @@ describe('ec2ParentNode', function () {
64
71
65
72
it ( 'sorts child nodes' , async function ( ) {
66
73
const sortedText = [ 'aa' , 'ab' , 'bb' , 'bc' , 'cc' , 'cd' ]
67
- instanceNames = [ 'ab' , 'bb' , 'bc' , 'aa' , 'cc' , 'cd' ]
74
+ instances = [
75
+ { name : 'ab' , InstanceId : '0' } ,
76
+ { name : 'bb' , InstanceId : '1' } ,
77
+ { name : 'bc' , InstanceId : '2' } ,
78
+ { name : 'aa' , InstanceId : '3' } ,
79
+ { name : 'cc' , InstanceId : '4' } ,
80
+ { name : 'cd' , InstanceId : '5' } ,
81
+ ]
68
82
69
83
const childNodes = await testNode . getChildren ( )
70
84
71
- const actualChildOrder = childNodes . map ( node => node . label )
85
+ const actualChildOrder = childNodes . map ( node => ( node instanceof Ec2InstanceNode ? node . name : undefined ) )
72
86
assert . deepStrictEqual ( actualChildOrder , sortedText , 'Unexpected child sort order' )
73
87
} )
74
88
@@ -79,4 +93,15 @@ describe('ec2ParentNode', function () {
79
93
const node = new Ec2ParentNode ( testRegion , testPartition , client )
80
94
assertNodeListOnlyHasErrorNode ( await node . getChildren ( ) )
81
95
} )
96
+
97
+ it ( 'is able to handle children with duplicate names' , async function ( ) {
98
+ instances = [
99
+ { name : 'firstOne' , InstanceId : '0' } ,
100
+ { name : 'secondOne' , InstanceId : '1' } ,
101
+ { name : 'firstOne' , InstanceId : '2' } ,
102
+ ]
103
+
104
+ const childNodes = await testNode . getChildren ( )
105
+ assert . strictEqual ( childNodes . length , instances . length , 'Unexpected child count' )
106
+ } )
82
107
} )
0 commit comments