@@ -170,6 +170,102 @@ Deno.test("Correctly transforms the events from a 2-tier nested stack with 1 non
170170 assertEquals ( outputs , expectedOutputs ) ;
171171} ) ;
172172
173+ Deno . test ( "Correctly transforms the events from a freshly created stack" , async ( ) => {
174+ //ARRANGE
175+ const inputs : IInputs = {
176+ stackName : "rootStackName" ,
177+ dependencies : {
178+ cloudformationClientAdapter : {
179+ getEventsFromMostRecentDeploy ( { stackName } ) {
180+ switch ( stackName ) {
181+ case "rootStackName" :
182+ return Promise . resolve ( {
183+ stackEvents : [
184+ createStackEvent ( {
185+ resourceIdPerCloudformation : "rootStackName" ,
186+ resourceIdPerTheServiceItsFrom :
187+ "arn:aws:cloudformation:us-east-1:000000000000:stack/rootStackName/00aa00a0-a00a-00aa-0a00-00a0a0a00000" ,
188+ resourceStatus : "CREATE_COMPLETE" ,
189+ resourceType : "AWS::CloudFormation::Stack" ,
190+ timestamp : new Date ( "2022-04-11T00:00:30.000Z" ) ,
191+ } ) ,
192+ createStackEvent ( {
193+ resourceIdPerCloudformation : "TheEcsCluster" ,
194+ resourceIdPerTheServiceItsFrom : "TheClusterName" ,
195+ resourceStatus : "CREATE_COMPLETE" ,
196+ resourceType : "AWS::ECS::Cluster" ,
197+ timestamp : new Date ( "2022-04-11T00:00:15.000Z" ) ,
198+ } ) ,
199+ createStackEvent ( {
200+ resourceIdPerCloudformation : "TheEcsCluster" ,
201+ resourceIdPerTheServiceItsFrom : "TheClusterName" ,
202+ resourceStatus : "CREATE_IN_PROGRESS" ,
203+ resourceType : "AWS::ECS::Cluster" ,
204+ timestamp : new Date ( "2022-04-11T00:00:10.000Z" ) ,
205+ } ) ,
206+ createStackEvent ( {
207+ resourceIdPerCloudformation : "rootStackName" ,
208+ resourceIdPerTheServiceItsFrom :
209+ "arn:aws:cloudformation:us-east-1:000000000000:stack/rootStackName/00aa00a0-a00a-00aa-0a00-00a0a0a00000" ,
210+ resourceStatus : "CREATE_IN_PROGRESS" ,
211+ resourceType : "AWS::CloudFormation::Stack" ,
212+ timestamp : new Date ( "2022-04-11T00:00:05.000Z" ) ,
213+ } ) ,
214+ createStackEvent ( {
215+ resourceIdPerCloudformation : "rootStackName" ,
216+ resourceIdPerTheServiceItsFrom :
217+ "arn:aws:cloudformation:us-east-1:000000000000:stack/rootStackName/00aa00a0-a00a-00aa-0a00-00a0a0a00000" ,
218+ resourceStatus : "REVIEW_IN_PROGRESS" ,
219+ resourceType : "AWS::CloudFormation::Stack" ,
220+ timestamp : new Date ( "2022-04-11T00:00:00.000Z" ) ,
221+ } ) ,
222+ ] ,
223+ } ) ;
224+ default :
225+ throw new Error ( `${ stackName } not found in the mock's setup` ) ;
226+ }
227+ } ,
228+ } ,
229+ } ,
230+ } ;
231+
232+ //ACT
233+ const outputs = await transformStackEventDataIntoTracingData ( inputs ) ;
234+
235+ //ASSERT
236+ const spanDataByConstructedId = new Map < string , ISpanData > ( ) ;
237+
238+ const rootConstructedId =
239+ "rootStackName-arn:aws:cloudformation:us-east-1:000000000000:stack/rootStackName/00aa00a0-a00a-00aa-0a00-00a0a0a00000-AWS::CloudFormation::Stack" ;
240+
241+ spanDataByConstructedId . set (
242+ "rootStackName-arn:aws:cloudformation:us-east-1:000000000000:stack/rootStackName/00aa00a0-a00a-00aa-0a00-00a0a0a00000-AWS::CloudFormation::Stack" ,
243+ {
244+ childSpanIds : new Set < string > ( [ "TheEcsCluster-TheClusterName-AWS::ECS::Cluster" ] ) ,
245+ name : "rootStackName" ,
246+ startInstant : new Date ( "2022-04-11T00:00:05.000Z" ) ,
247+ endInstant : new Date ( "2022-04-11T00:00:30.000Z" ) ,
248+ } ,
249+ ) ;
250+
251+ spanDataByConstructedId . set (
252+ "TheEcsCluster-TheClusterName-AWS::ECS::Cluster" ,
253+ {
254+ childSpanIds : new Set < string > ( ) ,
255+ name : "TheEcsCluster" ,
256+ startInstant : new Date ( "2022-04-11T00:00:10.000Z" ) ,
257+ endInstant : new Date ( "2022-04-11T00:00:15.000Z" ) ,
258+ } ,
259+ ) ;
260+
261+ const expectedOutputs : ITracingData = {
262+ spanDataByConstructedId,
263+ rootConstructedId,
264+ } ;
265+
266+ assertEquals ( outputs , expectedOutputs ) ;
267+ } ) ;
268+
173269function createStackEvent (
174270 partialStackEvent : Partial < IAdaptedStackEvent > ,
175271) : IAdaptedStackEvent {
0 commit comments