@@ -84,6 +84,50 @@ export function withCdkApp(
8484 } ;
8585}
8686
87+ export function withCdkMigrateApp < A extends TestContext > ( language : string , block : ( context : TestFixture ) => Promise < void > ) {
88+ return async ( context : A ) => {
89+ const stackName = `cdk-migrate-${ language } -integ-${ context . randomString } ` ;
90+ const integTestDir = path . join ( os . tmpdir ( ) , `cdk-migrate-${ language } -integ-${ context . randomString } ` ) ;
91+
92+ context . output . write ( ` Stack name: ${ stackName } \n` ) ;
93+ context . output . write ( ` Test directory: ${ integTestDir } \n` ) ;
94+
95+ const awsClients = await AwsClients . default ( context . output ) ;
96+ fs . mkdirSync ( integTestDir ) ;
97+ const fixture = new TestFixture (
98+ integTestDir ,
99+ stackName ,
100+ context . output ,
101+ awsClients ,
102+ context . randomString ,
103+ ) ;
104+
105+ await fixture . cdkMigrate ( language , stackName ) ;
106+
107+ const testFixture = new TestFixture (
108+ path . join ( integTestDir , stackName ) ,
109+ stackName ,
110+ context . output ,
111+ awsClients ,
112+ context . randomString ,
113+ ) ;
114+
115+ let success = true ;
116+ try {
117+ await block ( testFixture ) ;
118+ } catch ( e ) {
119+ success = false ;
120+ throw e ;
121+ } finally {
122+ if ( process . env . INTEG_NO_CLEAN ) {
123+ context . log ( `Left test directory in '${ integTestDir } ' ($INTEG_NO_CLEAN)` ) ;
124+ } else {
125+ await fixture . dispose ( success ) ;
126+ }
127+ }
128+ } ;
129+ }
130+
87131export function withMonolithicCfnIncludeCdkApp < A extends TestContext > ( block : ( context : TestFixture ) => Promise < void > ) {
88132 return async ( context : A ) => {
89133 const uberPackage = process . env . UBERPACKAGE ;
@@ -141,6 +185,10 @@ export function withDefaultFixture(block: (context: TestFixture) => Promise<void
141185 return withAws ( withTimeout ( DEFAULT_TEST_TIMEOUT_S , withCdkApp ( block ) ) ) ;
142186}
143187
188+ export function withCDKMigrateFixture ( language : string , block : ( content : TestFixture ) => Promise < void > ) {
189+ return withAws ( withTimeout ( DEFAULT_TEST_TIMEOUT_S , withCdkMigrateApp ( language , block ) ) ) ;
190+ }
191+
144192export interface DisableBootstrapContext {
145193 /**
146194 * Whether to disable creating the default bootstrap
@@ -270,7 +318,7 @@ export class TestFixture extends ShellHelper {
270318 this . output . write ( `${ s } \n` ) ;
271319 }
272320
273- public async cdkDeploy ( stackNames : string | string [ ] , options : CdkCliOptions = { } ) {
321+ public async cdkDeploy ( stackNames : string | string [ ] , options : CdkCliOptions = { } , skipStackRename ?: boolean ) {
274322 stackNames = typeof stackNames === 'string' ? [ stackNames ] : stackNames ;
275323
276324 const neverRequireApproval = options . neverRequireApproval ?? true ;
@@ -280,7 +328,7 @@ export class TestFixture extends ShellHelper {
280328 ...( options . options ?? [ ] ) ,
281329 // use events because bar renders bad in tests
282330 '--progress' , 'events' ,
283- ...this . fullStackName ( stackNames ) ] , options ) ;
331+ ...( skipStackRename ? stackNames : this . fullStackName ( stackNames ) ) ] , options ) ;
284332 }
285333
286334 public async cdkSynth ( options : CdkCliOptions = { } ) {
@@ -379,6 +427,19 @@ export class TestFixture extends ShellHelper {
379427 } ) ;
380428 }
381429
430+ public async cdkMigrate ( language : string , stackName : string , inputPath ?: string , options ?: CdkCliOptions ) {
431+ return this . cdk ( [
432+ 'migrate' ,
433+ '--language' ,
434+ language ,
435+ '--stack-name' ,
436+ stackName ,
437+ '--from-path' ,
438+ inputPath ?? path . join ( __dirname , '..' , 'resources' , 'templates' , 'sqs-template.json' ) . toString ( ) ,
439+ ...( options ?. options ?? [ ] ) ,
440+ ] , options ) ;
441+ }
442+
382443 public async cdk ( args : string [ ] , options : CdkCliOptions = { } ) {
383444 const verbose = options . verbose ?? true ;
384445
0 commit comments