Skip to content

Commit

Permalink
Add feedback from Luca
Browse files Browse the repository at this point in the history
  • Loading branch information
msambol committed Oct 12, 2023
1 parent 710a904 commit b627be0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
6 changes: 2 additions & 4 deletions packages/aws-cdk-lib/region-info/lib/fact.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { AWS_REGIONS } from './aws-entities';

/**
* A database of regional information.
*/
Expand All @@ -10,7 +8,7 @@ export class Fact {
*/
public static get regions(): string[] {
// Return by copy to ensure no modifications can be made to the undelying constant.
return Array.from(AWS_REGIONS);
return Array.from(Object.keys(this.database));
}

/**
Expand All @@ -37,7 +35,7 @@ export class Fact {
const foundFact = this.find(region, name);

if (!foundFact) {
throw new Error(`No fact ${name} could be found for region: ${region} and name: ${name}. Regions is a fixed list and defined in aws-entities.ts as AWS_REGIONS.`);
throw new Error(`No fact ${name} could be found for region: ${region} and name: ${name}.`);
}

return foundFact;
Expand Down
15 changes: 15 additions & 0 deletions packages/aws-cdk-lib/region-info/test/fact.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,19 @@ describe('register', () => {
// Cleanup
Fact.unregister(region, name);
});

test('registering a fact with a new region adds the region', () => {
// GIVEN
const region = 'us-unreleased-1';
const name = FactName.PARTITION;
const value = 'nebraska';

// WHEN
expect(Fact.find(region, name)).not.toBe(value);
expect(() => Fact.register({ region, name, value })).not.toThrowError();

// THEN
expect(Fact.regions.includes('us-unreleased-1')).toBeTruthy();
expect(Fact.find(region, name)).toBe('nebraska');
});
});

0 comments on commit b627be0

Please sign in to comment.