From 554645d1ca4d4223a0ab9490ea5cf5c0f201ed3a Mon Sep 17 00:00:00 2001 From: arcrank Date: Thu, 27 Jan 2022 18:15:45 -0500 Subject: [PATCH] chore(servicecatalog): cleanup unit tests for TagOptions (#18672) We implemented TagOptions as a full construct, and created its own unit test suite. We are moving some of the basic validation tests out of the other resources unit tests, and then the cross resource association tests as well. The only TagOption tests that remain in portfolio/product are for testing the association and adding as a prop, validation and multi resource tests will be in the `tag-option` test suite. The removed validation tests are already in the `tag-option` test suite. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- .../aws-servicecatalog/test/portfolio.test.ts | 38 ------------------- .../aws-servicecatalog/test/product.test.ts | 20 ---------- .../test/tag-option.test.ts | 31 +++++++++++++++ 3 files changed, 31 insertions(+), 58 deletions(-) diff --git a/packages/@aws-cdk/aws-servicecatalog/test/portfolio.test.ts b/packages/@aws-cdk/aws-servicecatalog/test/portfolio.test.ts index 74406931a069f..e53062e0a6752 100644 --- a/packages/@aws-cdk/aws-servicecatalog/test/portfolio.test.ts +++ b/packages/@aws-cdk/aws-servicecatalog/test/portfolio.test.ts @@ -350,44 +350,6 @@ describe('portfolio associations and product constraints', () => { Template.fromStack(stack).resourceCountIs('AWS::ServiceCatalog::TagOptionAssociation', 3); }), - test('fails to create and then add tag options with invalid minimum key length', () => { - expect(() => { - const tagOptions = new servicecatalog.TagOptions(stack, 'TagOptions', { - allowedValuesForTags: { - '': ['value1', 'value2'], - 'key2': ['value1'], - }, - }); - - portfolio.associateTagOptions(tagOptions); - }).toThrowError(/Invalid TagOption key for resource/); - }); - - test('fails to create and then add tag options with invalid maxium key length', () => { - expect(() => { - const tagOptions = new servicecatalog.TagOptions(stack, 'TagOptions', { - allowedValuesForTags: { - ['key1'.repeat(1000)]: ['value1', 'value2'], - key2: ['value1'], - }, - }); - - portfolio.associateTagOptions(tagOptions); - }).toThrowError(/Invalid TagOption key for resource/); - }), - - test('fails to create and then add tag options with invalid value length', () => { - expect(() => { - const tagOptions = new servicecatalog.TagOptions(stack, 'TagOptions', { - allowedValuesForTags: { - key1: ['value1'.repeat(1000), 'value2'], - key2: ['value1'], - }, - }); - portfolio.associateTagOptions(tagOptions); - }).toThrowError(/Invalid TagOption value for resource/); - }), - test('add tag update constraint', () => { portfolio.addProduct(product); portfolio.constrainTagUpdates(product, { diff --git a/packages/@aws-cdk/aws-servicecatalog/test/product.test.ts b/packages/@aws-cdk/aws-servicecatalog/test/product.test.ts index 691ae9d14d9f1..d27e18a1c3358 100644 --- a/packages/@aws-cdk/aws-servicecatalog/test/product.test.ts +++ b/packages/@aws-cdk/aws-servicecatalog/test/product.test.ts @@ -338,26 +338,6 @@ describe('Product', () => { Template.fromStack(stack).resourceCountIs('AWS::ServiceCatalog::TagOption', 3); //Generates a resource for each unique key-value pair Template.fromStack(stack).resourceCountIs('AWS::ServiceCatalog::TagOptionAssociation', 3); - }), - - test('adding tag options to portfolio and product creates unique tag options and enumerated associations', () => { - const tagOptions = new servicecatalog.TagOptions(stack, 'TagOptions', { - allowedValuesForTags: { - key1: ['value1', 'value2'], - key2: ['value1'], - }, - }); - - const portfolio = new servicecatalog.Portfolio(stack, 'MyPortfolio', { - displayName: 'testPortfolio', - providerName: 'testProvider', - }); - - portfolio.associateTagOptions(tagOptions); - product.associateTagOptions(tagOptions); - - Template.fromStack(stack).resourceCountIs('AWS::ServiceCatalog::TagOption', 3); //Generates a resource for each unique key-value pair - Template.fromStack(stack).resourceCountIs('AWS::ServiceCatalog::TagOptionAssociation', 6); }); }); }); diff --git a/packages/@aws-cdk/aws-servicecatalog/test/tag-option.test.ts b/packages/@aws-cdk/aws-servicecatalog/test/tag-option.test.ts index 67f601ed6e521..54e0464da467e 100644 --- a/packages/@aws-cdk/aws-servicecatalog/test/tag-option.test.ts +++ b/packages/@aws-cdk/aws-servicecatalog/test/tag-option.test.ts @@ -133,6 +133,37 @@ describe('TagOptions', () => { Template.fromStack(stack).hasResource('AWS::ServiceCatalog::TagOptionAssociation', 10); }), + test('adding tag options to portfolio and product creates unique tag options and enumerated associations', () => { + const tagOptions = new servicecatalog.TagOptions(stack, 'TagOptions', { + allowedValuesForTags: { + key1: ['value1', 'value2'], + key2: ['value1'], + }, + }); + + const portfolio = new servicecatalog.Portfolio(stack, 'MyPortfolio', { + displayName: 'testPortfolio', + providerName: 'testProvider', + }); + + const product = new servicecatalog.CloudFormationProduct(stack, 'MyProduct', { + productName: 'testProduct', + owner: 'testOwner', + productVersions: [ + { + cloudFormationTemplate: servicecatalog.CloudFormationTemplate.fromUrl('https://awsdocs.s3.amazonaws.com/servicecatalog/development-environment.template'), + }, + ], + tagOptions: tagOptions, + }); + + portfolio.associateTagOptions(tagOptions); + product.associateTagOptions(tagOptions); + + Template.fromStack(stack).resourceCountIs('AWS::ServiceCatalog::TagOption', 3); //Generates a resource for each unique key-value pair + Template.fromStack(stack).resourceCountIs('AWS::ServiceCatalog::TagOptionAssociation', 6); + }); + test('create and associate tag options in another stack', () => { const tagOptionsStack = new cdk.Stack(app, 'TagOptionsStack'); const productStack = new cdk.Stack(app, 'ProductStack');