Skip to content

Commit

Permalink
chore(servicecatalog): cleanup unit tests for TagOptions (#18672)
Browse files Browse the repository at this point in the history
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*
  • Loading branch information
arcrank committed Jan 27, 2022
1 parent 2eeaebc commit 554645d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 58 deletions.
38 changes: 0 additions & 38 deletions packages/@aws-cdk/aws-servicecatalog/test/portfolio.test.ts
Expand Up @@ -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, {
Expand Down
20 changes: 0 additions & 20 deletions packages/@aws-cdk/aws-servicecatalog/test/product.test.ts
Expand Up @@ -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);
});
});
});
31 changes: 31 additions & 0 deletions packages/@aws-cdk/aws-servicecatalog/test/tag-option.test.ts
Expand Up @@ -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');
Expand Down

0 comments on commit 554645d

Please sign in to comment.