1
- import { expect , haveResource } from '@aws-cdk/assert' ;
1
+ import { countResources , expect , haveResource } from '@aws-cdk/assert' ;
2
2
import ec2 = require( '@aws-cdk/aws-ec2' ) ;
3
3
import elbv2 = require( '@aws-cdk/aws-elasticloadbalancingv2' ) ;
4
4
import cdk = require( '@aws-cdk/cdk' ) ;
@@ -18,7 +18,7 @@ export = {
18
18
name : 'service' ,
19
19
} ) ;
20
20
21
- service . registerIpInstance ( {
21
+ service . registerIpInstance ( 'IpInstance' , {
22
22
ipv4 : '10.0.0.0' ,
23
23
ipv6 : '0:0:0:0:0:ffff:a00:0' ,
24
24
port : 443
@@ -56,7 +56,7 @@ export = {
56
56
dnsRecordType : servicediscovery . DnsRecordType . A_AAAA
57
57
} ) ;
58
58
59
- service . registerIpInstance ( {
59
+ service . registerIpInstance ( 'IpInstance' , {
60
60
ipv4 : '54.239.25.192' ,
61
61
ipv6 : '0:0:0:0:0:ffff:a00:0' ,
62
62
port : 443
@@ -96,7 +96,7 @@ export = {
96
96
dnsRecordType : servicediscovery . DnsRecordType . A_AAAA
97
97
} ) ;
98
98
99
- service . registerIpInstance ( {
99
+ service . registerIpInstance ( 'IpInstance' , {
100
100
ipv4 : '10.0.0.0' ,
101
101
ipv6 : '0:0:0:0:0:ffff:a00:0' ,
102
102
port : 443
@@ -136,7 +136,7 @@ export = {
136
136
137
137
// THEN
138
138
test . throws ( ( ) => {
139
- service . registerIpInstance ( {
139
+ service . registerIpInstance ( 'IpInstance' , {
140
140
instanceId : 'id' ,
141
141
} ) ;
142
142
} , / A ` p o r t ` m u s t b e s p e c i f i e d f o r a s e r v i c e u s i n g a ` S R V ` r e c o r d ./ ) ;
@@ -159,7 +159,7 @@ export = {
159
159
160
160
// THEN
161
161
test . throws ( ( ) => {
162
- service . registerIpInstance ( {
162
+ service . registerIpInstance ( 'IpInstance' , {
163
163
port : 3306
164
164
} ) ;
165
165
} , / A t l e a s t ` i p v 4 ` o r ` i p v 6 ` m u s t b e s p e c i f i e d f o r a s e r v i c e u s i n g a ` S R V ` r e c o r d ./ ) ;
@@ -182,7 +182,7 @@ export = {
182
182
183
183
// THEN
184
184
test . throws ( ( ) => {
185
- service . registerIpInstance ( {
185
+ service . registerIpInstance ( 'IpInstance' , {
186
186
port : 3306
187
187
} ) ;
188
188
} , / A n ` i p v 4 ` m u s t b e s p e c i f i e d f o r a s e r v i c e u s i n g a ` A ` r e c o r d ./ ) ;
@@ -205,7 +205,7 @@ export = {
205
205
206
206
// THEN
207
207
test . throws ( ( ) => {
208
- service . registerIpInstance ( {
208
+ service . registerIpInstance ( 'IpInstance' , {
209
209
port : 3306
210
210
} ) ;
211
211
} , / A n ` i p v 6 ` m u s t b e s p e c i f i e d f o r a s e r v i c e u s i n g a ` A A A A ` r e c o r d ./ ) ;
@@ -228,7 +228,7 @@ export = {
228
228
229
229
// THEN
230
230
test . throws ( ( ) => {
231
- service . registerIpInstance ( {
231
+ service . registerIpInstance ( 'IpInstance' , {
232
232
port : 3306
233
233
} ) ;
234
234
} , / S e r v i c e m u s t s u p p o r t ` A ` , ` A A A A ` o r ` S R V ` r e c o r d s t o r e g i s t e r t h i s i n s t a n c e t y p e ./ ) ;
@@ -338,7 +338,7 @@ export = {
338
338
dnsRecordType : servicediscovery . DnsRecordType . CNAME
339
339
} ) ;
340
340
341
- service . registerCnameInstance ( {
341
+ service . registerCnameInstance ( 'CnameInstance' , {
342
342
instanceCname : 'foo.com' ,
343
343
customAttributes : { dogs : 'good' }
344
344
} ) ;
@@ -375,7 +375,7 @@ export = {
375
375
376
376
// THEN
377
377
test . throws ( ( ) => {
378
- service . registerCnameInstance ( {
378
+ service . registerCnameInstance ( 'CnameInstance' , {
379
379
instanceCname : 'foo.com' ,
380
380
} ) ;
381
381
} , / N a m e s p a c e a s s o c i a t e d w i t h S e r v i c e m u s t b e a D N S N a m e s p a c e / ) ;
@@ -393,7 +393,7 @@ export = {
393
393
394
394
const service = namespace . createService ( 'MyService' ) ;
395
395
396
- service . registerNonIpInstance ( {
396
+ service . registerNonIpInstance ( 'NonIpInstance' , {
397
397
customAttributes : { dogs : 'good' }
398
398
} ) ;
399
399
@@ -426,7 +426,7 @@ export = {
426
426
427
427
// THEN
428
428
test . throws ( ( ) => {
429
- service . registerNonIpInstance ( {
429
+ service . registerNonIpInstance ( 'NonIpInstance' , {
430
430
instanceId : 'nonIp' ,
431
431
} ) ;
432
432
} , / T h i s t y p e o f i n s t a n c e c a n o n l y b e r e g i s t e r e d f o r H T T P n a m e s p a c e s ./ ) ;
@@ -446,7 +446,7 @@ export = {
446
446
447
447
// THEN
448
448
test . throws ( ( ) => {
449
- service . registerNonIpInstance ( {
449
+ service . registerNonIpInstance ( 'NonIpInstance' , {
450
450
instanceId : 'nonIp' ,
451
451
} ) ;
452
452
} , / Y o u m u s t s p e c i f y a t l e a s t o n e c u s t o m a t t r i b u t e f o r t h i s i n s t a n c e t y p e ./ ) ;
@@ -466,12 +466,37 @@ export = {
466
466
467
467
// THEN
468
468
test . throws ( ( ) => {
469
- service . registerNonIpInstance ( {
469
+ service . registerNonIpInstance ( 'NonIpInstance' , {
470
470
instanceId : 'nonIp' ,
471
471
customAttributes : { }
472
472
} ) ;
473
473
} , / Y o u m u s t s p e c i f y a t l e a s t o n e c u s t o m a t t r i b u t e f o r t h i s i n s t a n c e t y p e ./ ) ;
474
474
475
475
test . done ( ) ;
476
476
} ,
477
+
478
+ 'Register multiple instances on the same service' ( test : Test ) {
479
+ // GIVEN
480
+ const stack = new cdk . Stack ( ) ;
481
+
482
+ const namespace = new servicediscovery . PublicDnsNamespace ( stack , 'MyNamespace' , {
483
+ name : 'public' ,
484
+ } ) ;
485
+
486
+ const service = namespace . createService ( 'MyService' ) ;
487
+
488
+ // WHEN
489
+ service . registerIpInstance ( 'First' , {
490
+ ipv4 : '10.0.0.0'
491
+ } ) ;
492
+
493
+ service . registerIpInstance ( 'Second' , {
494
+ ipv4 : '10.0.0.1'
495
+ } ) ;
496
+
497
+ // THEN
498
+ expect ( stack ) . to ( countResources ( 'AWS::ServiceDiscovery::Instance' , 2 ) ) ;
499
+
500
+ test . done ( ) ;
501
+ }
477
502
} ;
0 commit comments