@@ -436,34 +436,45 @@ describe('notices configuration tests', () => {
436436 } ) ;
437437} ) ;
438438
439- describe ( 'gc command validation tests' , ( ) => {
439+ describe ( 'gc command warning tests' , ( ) => {
440440 beforeEach ( ( ) => {
441441 jest . clearAllMocks ( ) ;
442442 } ) ;
443443
444- /**
445- * Tests that the gc does not support roleArn
446- */
447- test ( 'should throw error when --role-arn is provided with gc command' , async ( ) => {
448- // Mock configuration to include 'gc' in unstable features
444+ test ( 'should warn when --role-arn is used with gc command' , async ( ) => {
445+ const mockWarn = jest . fn ( ) ;
449446 const mockConfig = {
447+ settings : { get : ( key : string [ ] ) => key [ 0 ] === 'unstable' ? [ 'gc' ] : [ ] } ,
448+ context : { get : ( ) => [ ] } ,
450449 loadConfigFiles : jest . fn ( ) . mockResolvedValue ( undefined ) ,
451- settings : {
452- get : jest . fn ( ) . mockImplementation ( ( key : string [ ] ) => {
453- if ( key [ 0 ] === 'unstable' ) return [ 'gc' ] ;
454- return undefined ;
455- } ) ,
456- } ,
457- context : {
458- get : jest . fn ( ) . mockReturnValue ( [ ] ) ,
459- } ,
460450 } ;
461-
451+
462452 ( Configuration as any ) . mockImplementation ( ( ) => mockConfig ) ;
463453 Configuration . fromArgsAndFiles = jest . fn ( ) . mockImplementation ( ( ) => mockConfig ) ;
464- // Expects an error to be thrown when roleArn is used with gc
465- await expect ( exec ( [ 'gc' , '--role-arn' , 'arn:aws:iam::123456789012:role/TestRole' , '--unstable=gc' ] ) )
466- . rejects
467- . toThrow ( 'The --role-arn option is not supported for the gc command' ) ;
454+ jest . spyOn ( cdkToolkitModule . CdkToolkit . prototype , 'garbageCollect' ) . mockResolvedValue ( ) ;
455+ jest . spyOn ( CliIoHost , 'instance' ) . mockReturnValue ( {
456+ defaults : {
457+ warn : mockWarn ,
458+ debug : jest . fn ( ) ,
459+ info : jest . fn ( ) ,
460+ error : jest . fn ( ) ,
461+ trace : jest . fn ( )
462+ } ,
463+ noticesDestination : 'stderr' ,
464+ notify : jest . fn ( ) ,
465+ asIoHelper : ( ) => ( {
466+ defaults : {
467+ warn : mockWarn ,
468+ debug : jest . fn ( ) ,
469+ info : jest . fn ( ) ,
470+ error : jest . fn ( ) ,
471+ trace : jest . fn ( )
472+ }
473+ } ) ,
474+ startTelemetry : jest . fn ( ) . mockResolvedValue ( undefined )
475+ } as any ) ;
476+
477+ await exec ( [ 'gc' , '--role-arn' , 'test-role' , '--unstable=gc' ] ) ;
478+ expect ( mockWarn ) . toHaveBeenCalledWith ( 'The --role-arn option is not supported for the gc command and will be ignored.' ) ;
468479 } ) ;
469480} ) ;
0 commit comments