1
1
import cxapi = require( '@aws-cdk/cx-api' ) ;
2
2
import { Test } from 'nodeunit' ;
3
+ import sinon = require( 'sinon' ) ;
3
4
import { ToolkitInfo } from '../lib' ;
4
5
import { prepareContainerAsset } from '../lib/docker' ;
6
+ import os = require( '../lib/os' ) ;
5
7
import { MockSDK } from './util/mock-sdk' ;
6
8
7
9
export = {
@@ -51,4 +53,48 @@ export = {
51
53
52
54
test . done ( ) ;
53
55
} ,
54
- } ;
56
+
57
+ async 'passes the correct args to docker build' ( test : Test ) {
58
+ // GIVEN
59
+ const toolkit = new ToolkitInfo ( {
60
+ sdk : new MockSDK ( ) ,
61
+ bucketName : 'BUCKET_NAME' ,
62
+ bucketEndpoint : 'BUCKET_ENDPOINT' ,
63
+ environment : { name : 'env' , account : '1234' , region : 'abc' }
64
+ } ) ;
65
+
66
+ const prepareEcrRepositoryStub = sinon . stub ( toolkit , 'prepareEcrRepository' ) . resolves ( {
67
+ repositoryUri : 'uri' ,
68
+ repositoryName : 'name'
69
+ } ) ;
70
+
71
+ const shellStub = sinon . stub ( os , 'shell' ) . rejects ( 'STOPTEST' ) ;
72
+
73
+ // WHEN
74
+ const asset : cxapi . ContainerImageAssetMetadataEntry = {
75
+ id : 'assetId' ,
76
+ imageNameParameter : 'MyParameter' ,
77
+ packaging : 'container-image' ,
78
+ path : '/foo' ,
79
+ repositoryName : 'some-name' ,
80
+ buildArgs : {
81
+ a : 'b' ,
82
+ c : 'd'
83
+ }
84
+ } ;
85
+
86
+ try {
87
+ await prepareContainerAsset ( asset , toolkit , false ) ;
88
+ } catch ( e ) {
89
+ if ( ! / S T O P T E S T / . test ( e . toString ( ) ) ) { throw e ; }
90
+ }
91
+
92
+ // THEN
93
+ const command = [ 'docker' , 'build' , '--build-arg a=b' , '--build-arg c=d' , '--quiet' , '/foo' ] ;
94
+ test . ok ( shellStub . calledWith ( command ) ) ;
95
+
96
+ prepareEcrRepositoryStub . restore ( ) ;
97
+ shellStub . restore ( ) ;
98
+ test . done ( ) ;
99
+ }
100
+ } ;
0 commit comments