|
1 | 1 | import '@aws-cdk/assert-internal/jest';
|
| 2 | +import { join, resolve } from 'path'; |
2 | 3 | import { Role, ServicePrincipal } from '@aws-cdk/aws-iam';
|
3 |
| -import { Stack } from '@aws-cdk/core'; |
4 |
| -import { Repository, RepositoryProps } from '../lib'; |
| 4 | +import { Asset } from '@aws-cdk/aws-s3-assets'; |
| 5 | +import * as cxschema from '@aws-cdk/cloud-assembly-schema'; |
| 6 | +import { App, Stack } from '@aws-cdk/core'; |
| 7 | +import { Code, Repository, RepositoryProps } from '../lib'; |
5 | 8 |
|
6 | 9 | describe('codecommit', () => {
|
7 | 10 | describe('CodeCommit Repositories', () => {
|
@@ -66,6 +69,89 @@ describe('codecommit', () => {
|
66 | 69 |
|
67 | 70 | });
|
68 | 71 |
|
| 72 | + test('Repository can be initialized with contents from a ZIP file', () => { |
| 73 | + // GIVEN |
| 74 | + const app = new App(); |
| 75 | + const stack = new Stack(app, 'MyStack'); |
| 76 | + |
| 77 | + // WHEN |
| 78 | + new Repository(stack, 'Repository', { |
| 79 | + repositoryName: 'MyRepositoryName', |
| 80 | + code: Code.fromZipFile(join(__dirname, 'asset-test.zip')), |
| 81 | + }); |
| 82 | + |
| 83 | + // THEN |
| 84 | + const assetMetadata = app.synth().tryGetArtifact(stack.stackName)!.findMetadataByType(cxschema.ArtifactMetadataEntryType.ASSET); |
| 85 | + expect(assetMetadata).toHaveLength(1); |
| 86 | + }); |
| 87 | + |
| 88 | + test('Repository can be initialized with contents from a directory', () => { |
| 89 | + // GIVEN |
| 90 | + const app = new App(); |
| 91 | + const stack = new Stack(app, 'MyStack'); |
| 92 | + |
| 93 | + // WHEN |
| 94 | + new Repository(stack, 'Repository', { |
| 95 | + repositoryName: 'MyRepositoryName', |
| 96 | + code: Code.fromDirectory(join(__dirname, 'asset-test')), |
| 97 | + }); |
| 98 | + |
| 99 | + // THEN |
| 100 | + const assetMetadata = app.synth().tryGetArtifact(stack.stackName)!.findMetadataByType(cxschema.ArtifactMetadataEntryType.ASSET); |
| 101 | + expect(assetMetadata).toHaveLength(1); |
| 102 | + }); |
| 103 | + |
| 104 | + test('Repository can be initialized with contents from an asset', () => { |
| 105 | + // GIVEN |
| 106 | + const app = new App(); |
| 107 | + const stack = new Stack(app, 'MyStack'); |
| 108 | + |
| 109 | + const readmeAsset = new Asset(stack, 'ReadmeAsset', { |
| 110 | + path: join(__dirname, 'asset-test'), |
| 111 | + }); |
| 112 | + |
| 113 | + // WHEN |
| 114 | + new Repository(stack, 'Repository', { |
| 115 | + repositoryName: 'MyRepositoryName', |
| 116 | + code: Code.fromAsset(readmeAsset), |
| 117 | + }); |
| 118 | + |
| 119 | + // THEN |
| 120 | + const assetMetadata = app.synth().tryGetArtifact(stack.stackName)!.findMetadataByType(cxschema.ArtifactMetadataEntryType.ASSET); |
| 121 | + expect(assetMetadata).toHaveLength(1); |
| 122 | + }); |
| 123 | + |
| 124 | + test('Repository throws Error when initialized with file while expecting directory', () => { |
| 125 | + // GIVEN |
| 126 | + const app = new App(); |
| 127 | + const stack = new Stack(app, 'MyStack'); |
| 128 | + const filePath = join(__dirname, 'asset-test/test.md'); |
| 129 | + |
| 130 | + // THEN |
| 131 | + expect(() => { |
| 132 | + new Repository(stack, 'Repository', { |
| 133 | + repositoryName: 'MyRepositoryName', |
| 134 | + code: Code.fromDirectory(filePath), |
| 135 | + }); |
| 136 | + }).toThrow(`'${filePath}' needs to be a path to a directory (resolved to: '${resolve(filePath)}')`); |
| 137 | + }); |
| 138 | + |
| 139 | + test('Repository throws Error when initialized with directory while expecting file', () => { |
| 140 | + // GIVEN |
| 141 | + const app = new App(); |
| 142 | + const stack = new Stack(app, 'MyStack'); |
| 143 | + |
| 144 | + const dirPath = join(__dirname, 'asset-test/'); |
| 145 | + |
| 146 | + // THEN |
| 147 | + expect(() => { |
| 148 | + new Repository(stack, 'Repository', { |
| 149 | + repositoryName: 'MyRepositoryName', |
| 150 | + code: Code.fromZipFile(dirPath), |
| 151 | + }); |
| 152 | + }).toThrow(`'${dirPath}' needs to be a path to a ZIP file (resolved to: '${resolve(dirPath)}')`); |
| 153 | + }); |
| 154 | + |
69 | 155 | /**
|
70 | 156 | * Fix for https://github.com/aws/aws-cdk/issues/10630
|
71 | 157 | */
|
|
0 commit comments