Skip to content

Commit

Permalink
chore(glue, ivs, msk, servicecatalog): explicit feature flags to prod…
Browse files Browse the repository at this point in the history
…uce a consistent template during tests (aws#15960)

In v1, the default value of the `@aws-cdk/core:newStyleStackSynthesis` flag is `false`. As a consequence, `Template.fromStack()` generates, by default, a template without the rule and parameter related to bootstrap versions. In v2,  the default value of this flag is `true`. So this test fails in the v2 branch. By explicitly setting the flag to `false`, we ensure that the tests passes on both v1 and v2, regardless of the default values.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
madeline-k authored Aug 9, 2021
1 parent 6dc9d3e commit d3df03a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 31 deletions.
22 changes: 12 additions & 10 deletions packages/@aws-cdk/aws-glue/test/database.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import { Template } from '@aws-cdk/assertions';
import { Stack } from '@aws-cdk/core';
import { App, Stack } from '@aws-cdk/core';
import * as glue from '../lib';

test('default database does not create a bucket', () => {
const stack = new Stack();
let stack: Stack;

beforeEach( () => {
const app = new App({
context: {
'@aws-cdk/core:newStyleStackSynthesis': false,
},
});
stack = new Stack(app);
});

test('default database does not create a bucket', () => {
new glue.Database(stack, 'Database', {
databaseName: 'test_database',
});
Expand All @@ -28,8 +37,6 @@ test('default database does not create a bucket', () => {
});

test('explicit locationURI', () => {
const stack = new Stack();

new glue.Database(stack, 'Database', {
databaseName: 'test_database',
locationUri: 's3://my-uri/',
Expand All @@ -55,9 +62,6 @@ test('explicit locationURI', () => {
});

test('fromDatabase', () => {
// GIVEN
const stack = new Stack();

// WHEN
const database = glue.Database.fromDatabaseArn(stack, 'import', 'arn:aws:glue:us-east-1:123456789012:database/db1');

Expand All @@ -72,7 +76,6 @@ test('fromDatabase', () => {
});

test('locationUri length must be >= 1', () => {
const stack = new Stack();
expect(() =>
new glue.Database(stack, 'Database', {
databaseName: 'test_database',
Expand All @@ -82,7 +85,6 @@ test('locationUri length must be >= 1', () => {
});

test('locationUri length must be <= 1024', () => {
const stack = new Stack();
expect(() =>
new glue.Database(stack, 'Database', {
databaseName: 'test_database',
Expand Down
31 changes: 12 additions & 19 deletions packages/@aws-cdk/aws-ivs/test/ivs.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Template } from '@aws-cdk/assertions';
import { Stack } from '@aws-cdk/core';
import { App, Stack } from '@aws-cdk/core';
import * as ivs from '../lib';

const publicKey = `-----BEGIN PUBLIC KEY-----
Expand All @@ -8,8 +8,18 @@ Yfo83eX0GJCKxJ8fr09h9LP9HDGof8/bo66P+SGHeAARGF/O9WPAQVUgSlm/KMFX
EPtPtOm1s0GR9k1ydU5hkI++f9CoZ5lM
-----END PUBLIC KEY-----`;

let stack: Stack;

beforeEach( () => {
const app = new App({
context: {
'@aws-cdk/core:newStyleStackSynthesis': false,
},
});
stack = new Stack(app);
});

test('channel default properties', () => {
const stack = new Stack();
new ivs.Channel(stack, 'Channel');

Template.fromStack(stack).templateMatches({
Expand All @@ -22,7 +32,6 @@ test('channel default properties', () => {
});

test('channel name', () => {
const stack = new Stack();
new ivs.Channel(stack, 'Channel', {
name: 'CarrotsAreTasty',
});
Expand All @@ -40,7 +49,6 @@ test('channel name', () => {
});

test('channel is authorized', () => {
const stack = new Stack();
new ivs.Channel(stack, 'Channel', {
authorized: true,
});
Expand All @@ -58,7 +66,6 @@ test('channel is authorized', () => {
});

test('channel type', () => {
const stack = new Stack();
new ivs.Channel(stack, 'Channel', {
type: ivs.ChannelType.BASIC,
});
Expand All @@ -76,7 +83,6 @@ test('channel type', () => {
});

test('channel latency mode', () => {
const stack = new Stack();
new ivs.Channel(stack, 'Channel', {
latencyMode: ivs.LatencyMode.NORMAL,
});
Expand All @@ -94,22 +100,18 @@ test('channel latency mode', () => {
});

test('channel from arn', () => {
const stack = new Stack();
const channel = ivs.Channel.fromChannelArn(stack, 'Channel', 'arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh');

expect(stack.resolve(channel.channelArn)).toBe('arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh');
});

test('channel invalid name throws validation error', () => {
const stack = new Stack();

expect(() => new ivs.Channel(stack, 'Channel', {
name: 'Would you like a carrot?',
})).toThrow('name must contain only numbers, letters, hyphens and underscores, got: \'Would you like a carrot?\'');
});

test('playback key pair mandatory properties', () => {
const stack = new Stack();
new ivs.PlaybackKeyPair(stack, 'PlaybackKeyPair', {
publicKeyMaterial: publicKey,
});
Expand All @@ -127,7 +129,6 @@ test('playback key pair mandatory properties', () => {
});

test('playback key pair name', () => {
const stack = new Stack();
new ivs.PlaybackKeyPair(stack, 'PlaybackKeyPair', {
publicKeyMaterial: publicKey,
name: 'CarrotsAreNutritious',
Expand All @@ -147,16 +148,13 @@ test('playback key pair name', () => {
});

test('playback key pair invalid name throws validation error', () => {
const stack = new Stack();

expect(() => new ivs.PlaybackKeyPair(stack, 'PlaybackKeyPair', {
publicKeyMaterial: 'Carrots Are Orange',
name: 'Would you like a carrot?',
})).toThrow('name must contain only numbers, letters, hyphens and underscores, got: \'Would you like a carrot?\'');
});

test('stream key mandatory properties', () => {
const stack = new Stack();
new ivs.StreamKey(stack, 'StreamKey', {
channel: ivs.Channel.fromChannelArn(stack, 'ChannelRef', 'arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh'),
});
Expand All @@ -174,7 +172,6 @@ test('stream key mandatory properties', () => {
});

test('channel and stream key.. at the same time', () => {
const stack = new Stack();
const channel = new ivs.Channel(stack, 'Channel');
channel.addStreamKey('StreamKey');

Expand All @@ -194,7 +191,6 @@ test('channel and stream key.. at the same time', () => {
});

test('stream key from channel reference', () => {
const stack = new Stack();
const channel = ivs.Channel.fromChannelArn(stack, 'Channel', 'arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh');
channel.addStreamKey('StreamKey');

Expand All @@ -211,20 +207,17 @@ test('stream key from channel reference', () => {
});

test('channel from invalid channel arn throws error', () => {
const stack = new Stack();
expect(() => ivs.Channel.fromChannelArn(stack, 'ChannelRef', 'this is an invalid arn, in fact, it is a carrot 🥕'))
.toThrow('ARNs must start with \"arn:\" and have at least 6 components: this is an invalid arn, in fact, it is a carrot 🥕');
});

test('channel from invalid channel arn service throws error', () => {
const stack = new Stack();
expect(
() => ivs.Channel.fromChannelArn(stack, 'ChannelRef', 'arn:aws:ec2:us-west-2:123456789012:instance/abcdABCDefgh'))
.toThrow('Invalid service, expected \'ivs\', got \'ec2\'');
});

test('channel from invalid channel arn resource throws error', () => {
const stack = new Stack();
expect(
() => ivs.Channel.fromChannelArn(stack, 'ChannelRef', 'arn:aws:ivs:us-west-2:123456789012:stream-key/abcdABCDefgh'))
.toThrow('Invalid resource, expected \'channel\', got \'stream-key\'');
Expand Down
7 changes: 6 additions & 1 deletion packages/@aws-cdk/aws-msk/test/cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ describe('MSK Cluster', () => {
let vpc: ec2.IVpc;

beforeEach(() => {
stack = new core.Stack();
const app = new core.App({
context: {
'@aws-cdk/core:newStyleStackSynthesis': false,
},
});
stack = new core.Stack(app);
vpc = new ec2.Vpc(stack, 'Vpc');
});

Expand Down
7 changes: 6 additions & 1 deletion packages/@aws-cdk/aws-servicecatalog/test/portfolio.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ describe('Portfolio', () => {
let stack: cdk.Stack;

beforeEach(() => {
stack = new cdk.Stack();
const app = new cdk.App({
context: {
'@aws-cdk/core:newStyleStackSynthesis': false,
},
});
stack = new cdk.Stack(app);
});

describe('portfolio creation and importing', () => {
Expand Down

0 comments on commit d3df03a

Please sign in to comment.