-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
107 changed files
with
1,775 additions
and
912 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import * as cxschema from '@aws-cdk/cloud-assembly-schema'; | ||
import * as cxapi from '@aws-cdk/cx-api'; | ||
|
||
export function mkStack(template: any): cxapi.CloudFormationStackArtifact { | ||
const assembly = new cxapi.CloudAssemblyBuilder(); | ||
assembly.addArtifact('test', { | ||
type: cxschema.ArtifactType.AWS_CLOUDFORMATION_STACK, | ||
environment: cxapi.EnvironmentUtils.format('123456789012', 'bermuda-triangle-1'), | ||
properties: { | ||
templateFile: 'template.json', | ||
}, | ||
}); | ||
|
||
fs.writeFileSync(path.join(assembly.outdir, 'template.json'), JSON.stringify(template)); | ||
return assembly.buildAssembly().getStackByName('test'); | ||
} | ||
|
||
export function mkResource(props: any): cxapi.CloudFormationStackArtifact { | ||
return mkStack({ | ||
Resources: { | ||
SomeResource: { | ||
Type: 'Some::Resource', | ||
Properties: props, | ||
}, | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 144 additions & 0 deletions
144
packages/@aws-cdk/assert-internal/test/match-template.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
import { MatchStyle } from '../lib'; | ||
import { mkStack } from './cloud-artifact'; | ||
import '../jest'; | ||
|
||
describe('matchTemplate', () => { | ||
describe('exact match', () => { | ||
test('match on resources', () => { | ||
const stack = mkStack({ | ||
Resources: { | ||
FooResource: { Type: 'Foo::Bar' }, | ||
}, | ||
}); | ||
|
||
expect(stack).toMatchTemplate({ | ||
Resources: { | ||
FooResource: { Type: 'Foo::Bar' }, | ||
}, | ||
}, MatchStyle.EXACT); | ||
|
||
expect(stack).not.toMatchTemplate({ | ||
Resources: { | ||
FooResource: { Type: 'Foo::Baz' }, | ||
}, | ||
}, MatchStyle.EXACT); | ||
}); | ||
|
||
test('match on parameters', () => { | ||
const stack = mkStack({ | ||
Parameters: { | ||
FooParameter: { Type: 'String' }, | ||
}, | ||
}); | ||
expect(stack).toMatchTemplate({ | ||
Parameters: { | ||
FooParameter: { Type: 'String' }, | ||
}, | ||
}, MatchStyle.EXACT); | ||
|
||
expect(stack).not.toMatchTemplate({ | ||
Parameters: { | ||
BarParameter: { Type: 'String' }, | ||
}, | ||
}, MatchStyle.EXACT); | ||
}); | ||
|
||
test('match on outputs', () => { | ||
const stack = mkStack({ | ||
Outputs: { | ||
FooOutput: { Value: 'Foo' }, | ||
}, | ||
}); | ||
|
||
expect(stack).toMatchTemplate({ | ||
Outputs: { | ||
FooOutput: { Value: 'Foo' }, | ||
}, | ||
}, MatchStyle.EXACT); | ||
|
||
expect(stack).not.toMatchTemplate({ | ||
Outputs: { | ||
BarOutput: { Value: 'Bar' }, | ||
}, | ||
}, MatchStyle.EXACT); | ||
|
||
expect(stack).not.toMatchTemplate({ | ||
Outputs: { | ||
FooOutput: { Value: 'Bar' }, | ||
}, | ||
}, MatchStyle.EXACT); | ||
}); | ||
}); | ||
|
||
describe('superset match', () => { | ||
test('match on resources', () => { | ||
const stack = mkStack({ | ||
Resources: { | ||
FooResource: { | ||
Type: 'Foo::Bar', | ||
}, | ||
BazResource: { | ||
Type: 'Foo::Baz', | ||
}, | ||
}, | ||
}); | ||
expect(stack).toMatchTemplate({ | ||
Resources: { | ||
FooResource: { | ||
Type: 'Foo::Bar', | ||
}, | ||
}, | ||
}, MatchStyle.SUPERSET); | ||
}); | ||
|
||
test('match on parameters', () => { | ||
const stack = mkStack({ | ||
Parameters: { | ||
FooParameter: { Type: 'String' }, | ||
BarParameter: { Type: 'String' }, | ||
}, | ||
}); | ||
expect(stack).toMatchTemplate({ | ||
Parameters: { | ||
FooParameter: { Type: 'String' }, | ||
}, | ||
}, MatchStyle.SUPERSET); | ||
|
||
expect(stack).not.toMatchTemplate({ | ||
Parameters: { | ||
FooParameter: { Type: 'String' }, | ||
BarParameter: { Type: 'Number' }, | ||
}, | ||
}, MatchStyle.SUPERSET); | ||
}); | ||
|
||
test('match on outputs', () => { | ||
const stack = mkStack({ | ||
Outputs: { | ||
FooOutput: { Value: 'Foo' }, | ||
BarOutput: { Value: 'Bar' }, | ||
}, | ||
}); | ||
|
||
expect(stack).toMatchTemplate({ | ||
Outputs: { | ||
FooOutput: { Value: 'Foo' }, | ||
}, | ||
}, MatchStyle.SUPERSET); | ||
|
||
expect(stack).not.toMatchTemplate({ | ||
Outputs: { | ||
FooOutput: { Value: 'Foo' }, | ||
BarOutput: { Value: 'Baz' }, | ||
}, | ||
}, MatchStyle.SUPERSET); | ||
|
||
expect(stack).not.toMatchTemplate({ | ||
Outputs: { | ||
FooOutput: { Value: 'Bar' }, | ||
BazOutput: { Value: 'Bar' }, | ||
}, | ||
}, MatchStyle.SUPERSET); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.