Skip to content

Commit

Permalink
fix(aws-servicecatalog): Allow users to use nested directories in the…
Browse files Browse the repository at this point in the history
… ProductStackHistory
  • Loading branch information
wanjacki committed Jun 9, 2022
1 parent c2e6d89 commit bf59c10
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class ProductStackHistory extends Construct {
public _writeTemplateToSnapshot(cfn: string) {
const productStackSnapshotDirectory = this.props.directory || DEFAULT_PRODUCT_STACK_SNAPSHOT_DIRECTORY;
if (!fs.existsSync(productStackSnapshotDirectory)) {
fs.mkdirSync(productStackSnapshotDirectory);
fs.mkdirSync(productStackSnapshotDirectory, { recursive: true });
}
const templateFileKey = `${Names.uniqueId(this)}.${this.props.productStack.artifactId}.${this.props.currentVersionName}.product.template.json`;
const templateFilePath = path.join(productStackSnapshotDirectory, templateFileKey);
Expand Down
30 changes: 30 additions & 0 deletions packages/@aws-cdk/aws-servicecatalog/test/product.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,36 @@ describe('Product', () => {
expect(snapshotExists).toBe(true);
}),

test('product test from product stack history with nested directory', () => {
const productStack = new servicecatalog.ProductStack(stack, 'ProductStack');

const productStackHistory = new ProductStackHistory(stack, 'MyProductStackHistory', {
productStack: productStack,
currentVersionName: 'v1',
currentVersionLocked: false,
directory: 'nested-directory/nested',
});

new sns.Topic(productStack, 'SNSTopicProductStack');

new servicecatalog.CloudFormationProduct(stack, 'MyProduct', {
productName: 'testProduct',
owner: 'testOwner',
productVersions: [
productStackHistory.currentVersion(),
],
});

const assembly = app.synth();
expect(assembly.artifacts.length).toEqual(2);
expect(assembly.stacks[0].assets.length).toBe(1);
expect(assembly.stacks[0].assets[0].path).toEqual('StackProductStack190B56DE.product.template.json');

const expectedTemplateFileKey = 'StackMyProductStackHistory8F05371C.StackProductStack190B56DE.v1.product.template.json';
const snapshotExists = fs.existsSync(path.join('nested-directory/nested', expectedTemplateFileKey));
expect(snapshotExists).toBe(true);
}),

test('fails product test from product stack when template changes and locked', () => {
const productStack = new servicecatalog.ProductStack(stack, 'ProductStack');

Expand Down

0 comments on commit bf59c10

Please sign in to comment.