|
| 1 | +import cxapi = require('@aws-cdk/cx-api'); |
| 2 | +import { Test } from 'nodeunit'; |
| 3 | +import { FileAssetPackaging, Stack } from '../lib'; |
| 4 | +import { toCloudFormation } from './util'; |
| 5 | + |
| 6 | +export = { |
| 7 | + 'addFileAsset correctly sets metadata and creates S3 parameters'(test: Test) { |
| 8 | + // GIVEN |
| 9 | + const stack = new Stack(); |
| 10 | + |
| 11 | + // WHEN |
| 12 | + stack.addFileAsset({ |
| 13 | + fileName: 'file-name', |
| 14 | + packaging: FileAssetPackaging.ZIP_DIRECTORY, |
| 15 | + sourceHash: 'source-hash' |
| 16 | + }); |
| 17 | + |
| 18 | + // THEN |
| 19 | + const assetMetadata = stack.node.metadata.find(({ type }) => type === cxapi.ASSET_METADATA); |
| 20 | + |
| 21 | + test.equal(assetMetadata && assetMetadata.data.path, 'file-name'); |
| 22 | + test.equal(assetMetadata && assetMetadata.data.id, 'source-hash'); |
| 23 | + test.equal(assetMetadata && assetMetadata.data.packaging, FileAssetPackaging.ZIP_DIRECTORY); |
| 24 | + test.equal(assetMetadata && assetMetadata.data.sourceHash, 'source-hash'); |
| 25 | + |
| 26 | + test.deepEqual(toCloudFormation(stack), { |
| 27 | + Parameters: { |
| 28 | + AssetParameterssourcehashS3BucketE6E91E3E: { |
| 29 | + Type: 'String', |
| 30 | + Description: 'S3 bucket for asset "source-hash"' |
| 31 | + }, |
| 32 | + AssetParameterssourcehashS3VersionKeyAC4157C3: { |
| 33 | + Type: 'String', |
| 34 | + Description: 'S3 key for asset version "source-hash"' |
| 35 | + }, |
| 36 | + AssetParameterssourcehashArtifactHashADBAE418: { |
| 37 | + Type: 'String', |
| 38 | + Description: 'Artifact hash for asset "source-hash"' |
| 39 | + } |
| 40 | + } |
| 41 | + }); |
| 42 | + |
| 43 | + test.done(); |
| 44 | + |
| 45 | + }, |
| 46 | + |
| 47 | + 'addDockerImageAsset correctly sets metadata and creates an ECR parameter'(test: Test) { |
| 48 | + // GIVEN |
| 49 | + const stack = new Stack(); |
| 50 | + |
| 51 | + // WHEN |
| 52 | + stack.addDockerImageAsset({ |
| 53 | + sourceHash: 'source-hash', |
| 54 | + directoryName: 'directory-name', |
| 55 | + repositoryName: 'repository-name' |
| 56 | + }); |
| 57 | + |
| 58 | + // THEN |
| 59 | + const assetMetadata = stack.node.metadata.find(({ type }) => type === cxapi.ASSET_METADATA); |
| 60 | + |
| 61 | + test.equal(assetMetadata && assetMetadata.data.packaging, 'container-image'); |
| 62 | + test.equal(assetMetadata && assetMetadata.data.path, 'directory-name'); |
| 63 | + test.equal(assetMetadata && assetMetadata.data.sourceHash, 'source-hash'); |
| 64 | + test.equal(assetMetadata && assetMetadata.data.repositoryName, 'repository-name'); |
| 65 | + |
| 66 | + test.deepEqual(toCloudFormation(stack), { |
| 67 | + Parameters: { |
| 68 | + AssetParameterssourcehashImageName3B572B12: { |
| 69 | + Type: 'String', |
| 70 | + Description: 'ECR repository name and tag for asset "source-hash"' |
| 71 | + } |
| 72 | + } |
| 73 | + }); |
| 74 | + |
| 75 | + test.done(); |
| 76 | + }, |
| 77 | +}; |
0 commit comments