@@ -195,6 +195,12 @@ type FixtureState = {
195195 ruleId : string ;
196196} ;
197197
198+ type FixtureResources = {
199+ gatewayId ?: string ;
200+ targetIds : string [ ] ;
201+ ruleId ?: string ;
202+ } ;
203+
198204function createFixtureCore ( ) : CoreClient {
199205 const { createControlClient, createDataClient, createIamClient } = fixtureFactories ( FIXTURES ) ;
200206 return new CoreClient ( {
@@ -220,7 +226,7 @@ class GatewayDeleteFixture {
220226 private readonly control = createControlClient ( { region : "us-east-1" } ) ;
221227 private readonly iam = createIamClient ( { region : "us-east-1" } ) ;
222228
223- async setup ( ) : Promise < FixtureState > {
229+ async setup ( resources : FixtureResources ) : Promise < FixtureState > {
224230 await this . ignoreMissing ( ( ) =>
225231 this . iam . send ( new DeleteRolePolicyCommand ( { RoleName : ROLE_NAME , PolicyName : POLICY_NAME } ) ) ,
226232 ) ;
@@ -254,6 +260,7 @@ class GatewayDeleteFixture {
254260 if ( ! gateway . gatewayId || ! gateway . gatewayArn ) {
255261 throw new Error ( "CreateGateway did not return fixture identifiers" ) ;
256262 }
263+ resources . gatewayId = gateway . gatewayId ;
257264 await this . waitUntil (
258265 ( ) => this . control . send ( new GetGatewayCommand ( { gatewayIdentifier : gateway . gatewayId } ) ) ,
259266 ( response ) => response . status === "READY" ,
@@ -295,6 +302,11 @@ class GatewayDeleteFixture {
295302 } ,
296303 } ) ,
297304 ) ;
305+ if ( ! target . targetId ) {
306+ throw new Error ( "CreateGatewayTarget did not return the fixture Target ID" ) ;
307+ }
308+ resources . targetIds . push ( target . targetId ) ;
309+
298310 const connector = await this . control . send (
299311 new CreateGatewayTargetCommand ( {
300312 gatewayIdentifier : gateway . gatewayId ,
@@ -315,9 +327,10 @@ class GatewayDeleteFixture {
315327 credentialProviderConfigurations : [ { credentialProviderType : "GATEWAY_IAM_ROLE" } ] ,
316328 } ) ,
317329 ) ;
318- if ( ! target . targetId || ! connector . targetId ) {
319- throw new Error ( "CreateGatewayTarget did not return fixture identifiers " ) ;
330+ if ( ! connector . targetId ) {
331+ throw new Error ( "CreateGatewayTarget did not return the fixture Connector ID " ) ;
320332 }
333+ resources . targetIds . push ( connector . targetId ) ;
321334 await Promise . all (
322335 [ target . targetId , connector . targetId ] . map ( ( targetId ) =>
323336 this . waitUntil (
@@ -349,6 +362,7 @@ class GatewayDeleteFixture {
349362 } ) ,
350363 ) ;
351364 if ( ! rule . ruleId ) throw new Error ( "CreateGatewayRule did not return the fixture rule ID" ) ;
365+ resources . ruleId = rule . ruleId ;
352366 await this . waitUntil (
353367 ( ) =>
354368 this . control . send (
@@ -377,47 +391,53 @@ class GatewayDeleteFixture {
377391 await this . waitUntilMissing ( operation ) ;
378392 }
379393
380- async cleanup ( state : FixtureState ) : Promise < void > {
381- await this . ignoreMissing ( ( ) =>
382- this . control . send (
383- new DeleteGatewayRuleCommand ( {
384- gatewayIdentifier : state . gatewayId ,
385- ruleId : state . ruleId ,
386- } ) ,
387- ) ,
388- ) ;
389- await this . waitUntilMissing ( ( ) =>
390- this . control . send (
391- new GetGatewayRuleCommand ( {
392- gatewayIdentifier : state . gatewayId ,
393- ruleId : state . ruleId ,
394- } ) ,
395- ) ,
396- ) ;
397- for ( const targetId of [ state . targetId , state . connectorId ] ) {
394+ async cleanup ( resources : FixtureResources ) : Promise < void > {
395+ if ( resources . gatewayId && resources . ruleId ) {
398396 await this . ignoreMissing ( ( ) =>
399397 this . control . send (
400- new DeleteGatewayTargetCommand ( {
401- gatewayIdentifier : state . gatewayId ,
402- targetId ,
398+ new DeleteGatewayRuleCommand ( {
399+ gatewayIdentifier : resources . gatewayId ,
400+ ruleId : resources . ruleId ,
403401 } ) ,
404402 ) ,
405403 ) ;
406404 await this . waitUntilMissing ( ( ) =>
407405 this . control . send (
408- new GetGatewayTargetCommand ( {
409- gatewayIdentifier : state . gatewayId ,
410- targetId ,
406+ new GetGatewayRuleCommand ( {
407+ gatewayIdentifier : resources . gatewayId ,
408+ ruleId : resources . ruleId ,
411409 } ) ,
412410 ) ,
413411 ) ;
414412 }
415- await this . ignoreMissing ( ( ) =>
416- this . control . send ( new DeleteGatewayCommand ( { gatewayIdentifier : state . gatewayId } ) ) ,
417- ) ;
418- await this . waitUntilMissing ( ( ) =>
419- this . control . send ( new GetGatewayCommand ( { gatewayIdentifier : state . gatewayId } ) ) ,
420- ) ;
413+
414+ if ( resources . gatewayId ) {
415+ for ( const targetId of resources . targetIds ) {
416+ await this . ignoreMissing ( ( ) =>
417+ this . control . send (
418+ new DeleteGatewayTargetCommand ( {
419+ gatewayIdentifier : resources . gatewayId ,
420+ targetId,
421+ } ) ,
422+ ) ,
423+ ) ;
424+ await this . waitUntilMissing ( ( ) =>
425+ this . control . send (
426+ new GetGatewayTargetCommand ( {
427+ gatewayIdentifier : resources . gatewayId ,
428+ targetId,
429+ } ) ,
430+ ) ,
431+ ) ;
432+ }
433+ await this . ignoreMissing ( ( ) =>
434+ this . control . send ( new DeleteGatewayCommand ( { gatewayIdentifier : resources . gatewayId } ) ) ,
435+ ) ;
436+ await this . waitUntilMissing ( ( ) =>
437+ this . control . send ( new GetGatewayCommand ( { gatewayIdentifier : resources . gatewayId } ) ) ,
438+ ) ;
439+ }
440+
421441 await this . ignoreMissing ( ( ) =>
422442 this . iam . send (
423443 new DeleteRolePolicyCommand ( {
@@ -469,11 +489,13 @@ test(
469489 "deletes a Rule, Target, Connector, and Gateway through the real Core" ,
470490 async ( ) => {
471491 const fixture = new GatewayDeleteFixture ( ) ;
472- const state = isRecording ( )
473- ? await fixture . setup ( )
474- : ( JSON . parse ( readFileSync ( RESOURCE_STATE , "utf8" ) ) as FixtureState ) ;
492+ const resources : FixtureResources = { targetIds : [ ] } ;
475493
476494 try {
495+ const state = isRecording ( )
496+ ? await fixture . setup ( resources )
497+ : ( JSON . parse ( readFileSync ( RESOURCE_STATE , "utf8" ) ) as FixtureState ) ;
498+
477499 const ruleStdout = await runFixture ( [
478500 "gateway" ,
479501 "rule" ,
@@ -543,7 +565,7 @@ test(
543565 ) ,
544566 ) ;
545567 } finally {
546- if ( isRecording ( ) ) await fixture . cleanup ( state ) ;
568+ if ( isRecording ( ) ) await fixture . cleanup ( resources ) ;
547569 }
548570 } ,
549571 FLOW_TIMEOUT ,
0 commit comments