1
1
import { expect , haveResource , SynthUtils } from '@aws-cdk/assert' ;
2
2
import iam = require( '@aws-cdk/aws-iam' ) ;
3
- import cdk = require ( '@aws-cdk/core' ) ;
3
+ import { App , Lazy , Stack } from '@aws-cdk/core' ;
4
4
import fs = require( 'fs' ) ;
5
5
import { Test } from 'nodeunit' ;
6
6
import path = require( 'path' ) ;
@@ -11,7 +11,7 @@ import { DockerImageAsset } from '../lib';
11
11
export = {
12
12
'test instantiating Asset Image' ( test : Test ) {
13
13
// GIVEN
14
- const stack = new cdk . Stack ( ) ;
14
+ const stack = new Stack ( ) ;
15
15
16
16
// WHEN
17
17
new DockerImageAsset ( stack , 'Image' , {
@@ -31,7 +31,7 @@ export = {
31
31
32
32
'with build args' ( test : Test ) {
33
33
// GIVEN
34
- const stack = new cdk . Stack ( ) ;
34
+ const stack = new Stack ( ) ;
35
35
36
36
// WHEN
37
37
const asset = new DockerImageAsset ( stack , 'Image' , {
@@ -49,7 +49,7 @@ export = {
49
49
50
50
'asset.repository.grantPull can be used to grant a principal permissions to use the image' ( test : Test ) {
51
51
// GIVEN
52
- const stack = new cdk . Stack ( ) ;
52
+ const stack = new Stack ( ) ;
53
53
const user = new iam . User ( stack , 'MyUser' ) ;
54
54
const asset = new DockerImageAsset ( stack , 'Image' , {
55
55
directory : path . join ( __dirname , 'demo-image' )
@@ -106,7 +106,7 @@ export = {
106
106
107
107
'asset.repository.addToResourcePolicy can be used to modify the ECR resource policy via the adoption custom resource' ( test : Test ) {
108
108
// GIVEN
109
- const stack = new cdk . Stack ( ) ;
109
+ const stack = new Stack ( ) ;
110
110
const asset = new DockerImageAsset ( stack , 'Image' , {
111
111
directory : path . join ( __dirname , 'demo-image' )
112
112
} ) ;
@@ -141,7 +141,7 @@ export = {
141
141
142
142
'fails if the directory does not exist' ( test : Test ) {
143
143
// GIVEN
144
- const stack = new cdk . Stack ( ) ;
144
+ const stack = new Stack ( ) ;
145
145
146
146
// THEN
147
147
test . throws ( ( ) => {
@@ -154,7 +154,7 @@ export = {
154
154
155
155
'fails if the directory does not contain a Dockerfile' ( test : Test ) {
156
156
// GIVEN
157
- const stack = new cdk . Stack ( ) ;
157
+ const stack = new Stack ( ) ;
158
158
159
159
// THEN
160
160
test . throws ( ( ) => {
@@ -166,8 +166,8 @@ export = {
166
166
} ,
167
167
168
168
'docker directory is staged if asset staging is enabled' ( test : Test ) {
169
- const app = new cdk . App ( ) ;
170
- const stack = new cdk . Stack ( app , 'stack' ) ;
169
+ const app = new App ( ) ;
170
+ const stack = new Stack ( app , 'stack' ) ;
171
171
172
172
new DockerImageAsset ( stack , 'MyAsset' , {
173
173
directory : path . join ( __dirname , 'demo-image' )
@@ -177,6 +177,26 @@ export = {
177
177
178
178
test . ok ( fs . existsSync ( path . join ( session . directory , 'asset.1a17a141505ac69144931fe263d130f4612251caa4bbbdaf68a44ed0f405439c/Dockerfile' ) ) ) ;
179
179
test . ok ( fs . existsSync ( path . join ( session . directory , 'asset.1a17a141505ac69144931fe263d130f4612251caa4bbbdaf68a44ed0f405439c/index.py' ) ) ) ;
180
+ test . done ( ) ;
181
+ } ,
182
+
183
+ 'fails if using tokens in build args keys or values' ( test : Test ) {
184
+ // GIVEN
185
+ const stack = new Stack ( ) ;
186
+ const token = Lazy . stringValue ( { produce : ( ) => 'foo' } ) ;
187
+ const expected = / C a n n o t u s e t o k e n s i n k e y s o r v a l u e s o f " b u i l d A r g s " s i n c e t h e y a r e n e e d e d b e f o r e d e p l o y m e n t / ;
188
+
189
+ // THEN
190
+ test . throws ( ( ) => new DockerImageAsset ( stack , 'MyAsset1' , {
191
+ directory : path . join ( __dirname , 'demo-image' ) ,
192
+ buildArgs : { [ token ] : 'value' }
193
+ } ) , expected ) ;
194
+
195
+ test . throws ( ( ) => new DockerImageAsset ( stack , 'MyAsset2' , {
196
+ directory : path . join ( __dirname , 'demo-image' ) ,
197
+ buildArgs : { key : token }
198
+ } ) , expected ) ;
199
+
180
200
test . done ( ) ;
181
201
}
182
202
} ;
0 commit comments