@@ -7,7 +7,7 @@ import * as assert from 'assert'
7
7
import { AsyncCollection } from '../../../shared/utilities/asyncCollection'
8
8
import { toCollection } from '../../../shared/utilities/asyncCollection'
9
9
import { intoCollection } from '../../../shared/utilities/collectionUtils'
10
- import { Ec2Client } from '../../../shared/clients/ec2Client'
10
+ import { Ec2Client , instanceHasName } from '../../../shared/clients/ec2Client'
11
11
import { EC2 } from 'aws-sdk'
12
12
13
13
describe ( 'extractInstancesFromReservations' , function ( ) {
@@ -93,9 +93,49 @@ describe('extractInstancesFromReservations', function () {
93
93
actualResult
94
94
)
95
95
} )
96
+
97
+ it ( 'can process results without complete Tag field.' , async function ( ) {
98
+ const testReservationsList : EC2 . ReservationList = [
99
+ {
100
+ Instances : [
101
+ {
102
+ InstanceId : 'id1' ,
103
+ Tags : [ { Key : 'Name' , Value : 'name1' } ] ,
104
+ } ,
105
+ {
106
+ InstanceId : 'id2' ,
107
+ } ,
108
+ ] ,
109
+ } ,
110
+ {
111
+ Instances : [
112
+ {
113
+ InstanceId : 'id3' ,
114
+ Tags : [ { Key : 'Name' , Value : 'name3' } ] ,
115
+ } ,
116
+ {
117
+ InstanceId : 'id4' ,
118
+ Tags : [ ] ,
119
+ } ,
120
+ ] ,
121
+ } ,
122
+ ]
123
+
124
+ const actualResult = await client . getInstancesFromReservations ( intoCollection ( [ testReservationsList ] ) ) . promise ( )
125
+
126
+ assert . deepStrictEqual (
127
+ [
128
+ { InstanceId : 'id1' , name : 'name1' , Tags : [ { Key : 'Name' , Value : 'name1' } ] } ,
129
+ { InstanceId : 'id2' } ,
130
+ { InstanceId : 'id3' , name : 'name3' , Tags : [ { Key : 'Name' , Value : 'name3' } ] } ,
131
+ { InstanceId : 'id4' , Tags : [ ] } ,
132
+ ] ,
133
+ actualResult
134
+ )
135
+ } )
96
136
} )
97
137
98
- describe ( 'getSingleInstanceFilter ' , function ( ) {
138
+ describe ( 'getInstancesFilter ' , function ( ) {
99
139
const client = new Ec2Client ( '' )
100
140
101
141
it ( 'returns proper filter when given instanceId' , function ( ) {
@@ -122,3 +162,26 @@ describe('getSingleInstanceFilter', function () {
122
162
assert . deepStrictEqual ( expectedFilters2 , actualFilters2 )
123
163
} )
124
164
} )
165
+
166
+ describe ( 'instanceHasName' , function ( ) {
167
+ it ( 'returns whether or not there is name attached to instance' , function ( ) {
168
+ const instances = [
169
+ { InstanceId : 'id1' , Tags : [ ] } ,
170
+ { InstanceId : 'id2' , name : 'name2' , Tags : [ { Key : 'Name' , Value : 'name2' } ] } ,
171
+ { InstanceId : 'id3' , Tags : [ { Key : 'NotName' , Value : 'notAName' } ] } ,
172
+ {
173
+ InstanceId : 'id4' ,
174
+ name : 'name4' ,
175
+ Tags : [
176
+ { Key : 'Name' , Value : 'name4' } ,
177
+ { Key : 'anotherKey' , Value : 'Another Key' } ,
178
+ ] ,
179
+ } ,
180
+ ]
181
+
182
+ assert . deepStrictEqual ( false , instanceHasName ( instances [ 0 ] ) )
183
+ assert . deepStrictEqual ( true , instanceHasName ( instances [ 1 ] ) )
184
+ assert . deepStrictEqual ( false , instanceHasName ( instances [ 2 ] ) )
185
+ assert . deepStrictEqual ( true , instanceHasName ( instances [ 3 ] ) )
186
+ } )
187
+ } )
0 commit comments