@@ -117,4 +117,65 @@ describe('aliased port', () => {
117
117
} ,
118
118
} ) ;
119
119
} ) ;
120
+
121
+ test ( 'when enabling service connect on a client service' , ( ) => {
122
+ serviceDescription . add ( new Container ( {
123
+ cpu : 256 ,
124
+ memoryMiB : 512 ,
125
+ trafficPort : 80 ,
126
+ image : ecs . ContainerImage . fromRegistry ( 'nathanpeck/name' ) ,
127
+ } ) ) ;
128
+
129
+ environment . addDefaultCloudMapNamespace ( {
130
+ name : environment . id ,
131
+ } ) ;
132
+
133
+ const svc = new Service ( stack , 'my-service' , {
134
+ environment,
135
+ serviceDescription,
136
+ } ) ;
137
+ svc . enableServiceConnect ( ) ;
138
+
139
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ECS::Service' , {
140
+ ServiceConnectConfiguration : {
141
+ Enabled : true ,
142
+ Namespace : 'production' ,
143
+ } ,
144
+ } ) ;
145
+ } ) ;
146
+
147
+ test ( 'cannot enable service connect on a cluster with no namespace' , ( ) => {
148
+ serviceDescription . add ( new Container ( {
149
+ cpu : 256 ,
150
+ memoryMiB : 512 ,
151
+ trafficPort : 80 ,
152
+ image : ecs . ContainerImage . fromRegistry ( 'nathanpeck/name' ) ,
153
+ } ) ) ;
154
+ const svc = new Service ( stack , 'my-service' , {
155
+ environment,
156
+ serviceDescription,
157
+ } ) ;
158
+
159
+ expect ( ( ) => {
160
+ svc . enableServiceConnect ( ) ;
161
+ } ) . toThrow ( 'Environment must have a default CloudMap namespace to enable Service Connect.' ) ;
162
+ } ) ;
163
+
164
+ test ( 'cannot add two Aliased Port extensions' , ( ) => {
165
+ serviceDescription . add ( new Container ( {
166
+ cpu : 256 ,
167
+ memoryMiB : 512 ,
168
+ trafficPort : 80 ,
169
+ image : ecs . ContainerImage . fromRegistry ( 'nathanpeck/name' ) ,
170
+ } ) ) ;
171
+ serviceDescription . add ( new AliasedPortExtension ( {
172
+ alias : 'name' ,
173
+ } ) ) ;
174
+ expect ( ( ) => {
175
+ serviceDescription . add ( new AliasedPortExtension ( {
176
+ alias : 'name2' ,
177
+ aliasPort : 8080 ,
178
+ } ) ) ;
179
+ } ) . toThrow ( 'An extension called aliasedPort has already been added' ) ;
180
+ } ) ;
120
181
} ) ;
0 commit comments