Skip to content

Commit

Permalink
mid work
Browse files Browse the repository at this point in the history
  • Loading branch information
iliapolo committed Sep 30, 2024
1 parent 12e2c98 commit e3ad0cd
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2259,3 +2259,34 @@ integTest(
expect(noticesUnacknowledged).toEqual(noticesUnacknowledgedAlias);
}),
);

integTest('cdk notices for bootstrap', withDefaultFixture(async (fixture) => {

const cache = {
expiration: 4125963264000, // year 2100 so we never overwrite the cache
notices: [{
title: 'Bootstrap stack outdated',
issueNumber: 16600,
overview: 'Your environments "{resolve:ENVIRONMENTS}" are running an outdated bootstrap stack.',
components: [{
name: 'bootstrap',
version: '<2000',
}],
schemaVersion: '1',
}],
};

const cdkCacheDir = path.join(fixture.integTestDir, 'cache');
await fs.mkdir(cdkCacheDir);
await fs.writeFile(path.join(cdkCacheDir, 'notices.json'), JSON.stringify(cache));

const output = await fixture.cdkDeploy('test-2', {
verbose: false,
modEnv: {
CDK_HOME: fixture.integTestDir,
},
});

expect(output).toContain('Your environments \"aws://');

}));
16 changes: 12 additions & 4 deletions packages/aws-cdk/lib/notices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ export class Notices {
private readonly includeAcknowlegded: boolean;

private data: Set<Notice> = new Set();
private readonly bootstrappedEnvironments: Set<BootstrappedEnvironment> = new Set();

// sets don't deduplicate interfaces, so we use a map.
private readonly bootstrappedEnvironments: Map<string, BootstrappedEnvironment> = new Map();

private constructor(props: NoticesProps) {
this.configuration = props.configuration;
Expand All @@ -228,8 +230,14 @@ export class Notices {
* Add a bootstrap information to filter on. Can have multiple values
* in case of multi-environment deployments.
*/
public addBootstrappedEnvironment(info: BootstrappedEnvironment) {
this.bootstrappedEnvironments.add(info);
public addBootstrappedEnvironment(bootstrapped: BootstrappedEnvironment) {
const key = [
bootstrapped.bootstrapStackVersion,
bootstrapped.environment.account,
bootstrapped.environment.region,
bootstrapped.environment.name,
].join(':');
this.bootstrappedEnvironments.set(key, bootstrapped);
}

/**
Expand Down Expand Up @@ -267,7 +275,7 @@ export class Notices {
data: Array.from(this.data),
cliVersion: versionNumber(),
outDir: this.configuration.settings.get(['output']) ?? 'cdk.out',
bootstrappedEnvironments: Array.from(this.bootstrappedEnvironments),
bootstrappedEnvironments: Array.from(this.bootstrappedEnvironments.values()),
});

if (filteredNotices.length > 0) {
Expand Down
31 changes: 30 additions & 1 deletion packages/aws-cdk/test/notices.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,6 @@ describe(Notices, () => {
test('can add multiple values', async () => {
const notices = Notices.create({ configuration: new Configuration() });
notices.addBootstrappedEnvironment({ bootstrapStackVersion: 10, environment: { account: 'account', region: 'region', name: 'env' } });
notices.addBootstrappedEnvironment({ bootstrapStackVersion: 10, environment: { account: 'account', region: 'region', name: 'env' } });
notices.addBootstrappedEnvironment({ bootstrapStackVersion: 11, environment: { account: 'account', region: 'region', name: 'env' } });

await notices.refresh({
Expand All @@ -544,6 +543,36 @@ describe(Notices, () => {

});

test('deduplicates', async () => {
const notices = Notices.create({ configuration: new Configuration() });
notices.addBootstrappedEnvironment({ bootstrapStackVersion: 10, environment: { account: 'account', region: 'region', name: 'env' } });
notices.addBootstrappedEnvironment({ bootstrapStackVersion: 10, environment: { account: 'account', region: 'region', name: 'env' } });

// mock cli version number
jest.spyOn(version, 'versionNumber').mockImplementation(() => '1.0.0');

notices.display();

const filter = jest.spyOn(NoticesFilter, 'filter');
notices.display();

expect(filter).toHaveBeenCalledTimes(1);
expect(filter).toHaveBeenCalledWith({
bootstrappedEnvironments: [{
bootstrapStackVersion: 10,
environment: {
account: 'account',
region: 'region',
name: 'env',
},
}],
cliVersion: '1.0.0',
data: [],
outDir: 'cdk.out',
});

});

});

describe('refresh', () => {
Expand Down

0 comments on commit e3ad0cd

Please sign in to comment.