forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(integ-tests): add
IntegTest
to group test cases (aws#20015)
Add a new construct, `IntegTest` that contains a list of `IntegTestCase`s. This new construct is now responsible for starting the synthesis of the manifests. Previously, it was `IntegTestCase` that did this. But this results in the last `IntegTestCase` to be synthesized to override all other test cases. ---- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
1 parent
f804f23
commit c39e7be
Showing
6 changed files
with
132 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { IntegManifest, Manifest } from '@aws-cdk/cloud-assembly-schema'; | ||
import { ISynthesisSession } from '@aws-cdk/core'; | ||
import { IntegManifestWriter } from './manifest-writer'; | ||
import { IntegTestCase } from './test-case'; | ||
|
||
const emptyManifest: IntegManifest = { | ||
version: '', | ||
testCases: { }, | ||
}; | ||
|
||
export class IntegManifestSynthesizer { | ||
constructor(private readonly testCases: IntegTestCase[]) {} | ||
|
||
synthesize(session: ISynthesisSession) { | ||
const manifest = this.testCases | ||
.map(tc => tc.manifest) | ||
.reduce(mergeManifests, emptyManifest); | ||
|
||
const snapshotDir = session.assembly.outdir; | ||
|
||
IntegManifestWriter.write(manifest, snapshotDir); | ||
} | ||
} | ||
|
||
function mergeManifests(m1: IntegManifest, m2: IntegManifest): IntegManifest { | ||
return { | ||
version: Manifest.version(), | ||
testCases: { ...m1.testCases, ...m2.testCases }, | ||
}; | ||
} |
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
45 changes: 45 additions & 0 deletions
45
packages/@aws-cdk/integ-tests/test/manifest-synthesizer.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,45 @@ | ||
import * as fs from 'fs'; | ||
import * as os from 'os'; | ||
import * as path from 'path'; | ||
import { App, Stack } from '@aws-cdk/core'; | ||
import { CloudAssemblyBuilder } from '@aws-cdk/cx-api'; | ||
import { IntegTestCase } from '../lib'; | ||
import { IntegManifestSynthesizer } from '../lib/manifest-synthesizer'; | ||
import { IntegManifestWriter } from '../lib/manifest-writer'; | ||
|
||
describe(IntegManifestSynthesizer, () => { | ||
it('synthesizes a multiple manifests', () => { | ||
const write = jest.spyOn(IntegManifestWriter, 'write'); | ||
|
||
const app = new App(); | ||
const stack = new Stack(app, 'stack'); | ||
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'cdk-test')); | ||
const assembly = new CloudAssemblyBuilder(tmpDir); | ||
|
||
const synthesizer = new IntegManifestSynthesizer([ | ||
new IntegTestCase(stack, 'case1', { | ||
stacks: [new Stack(app, 'stack-under-test-1')], | ||
}), | ||
new IntegTestCase(stack, 'case2', { | ||
stacks: [new Stack(app, 'stack-under-test-2')], | ||
}), | ||
]); | ||
|
||
synthesizer.synthesize({ | ||
assembly, | ||
outdir: 'asdas', | ||
}); | ||
|
||
expect(write).toHaveBeenCalledWith({ | ||
version: '17.0.0', | ||
testCases: { | ||
case1: { | ||
stacks: ['stack-under-test-1'], | ||
}, | ||
case2: { | ||
stacks: ['stack-under-test-2'], | ||
}, | ||
}, | ||
}, tmpDir); | ||
}); | ||
}); |