11import * as child_process from 'child_process' ;
2+ import * as crypto from 'crypto' ;
23import * as path from 'path' ;
34import { nodeunitShim , Test } from 'nodeunit-shim' ;
45import * as sinon from 'sinon' ;
@@ -46,11 +47,10 @@ nodeunitShim({
4647 } ,
4748
4849 'bundling with image from asset' ( test : Test ) {
49- const imageId = 'sha256:abcdef123456' ;
5050 const spawnSyncStub = sinon . stub ( child_process , 'spawnSync' ) . returns ( {
5151 status : 0 ,
5252 stderr : Buffer . from ( 'stderr' ) ,
53- stdout : Buffer . from ( imageId ) ,
53+ stdout : Buffer . from ( 'stdout' ) ,
5454 pid : 123 ,
5555 output : [ 'stdout' , 'stderr' ] ,
5656 signal : null ,
@@ -67,33 +67,27 @@ nodeunitShim({
6767 } ) ;
6868 image . run ( ) ;
6969
70+ const tagHash = crypto . createHash ( 'sha256' ) . update ( JSON . stringify ( {
71+ path : 'docker-path' ,
72+ buildArgs : {
73+ TEST_ARG : 'cdk-test' ,
74+ } ,
75+ } ) ) . digest ( 'hex' ) ;
76+ const tag = `cdk-${ tagHash } ` ;
77+
7078 test . ok ( spawnSyncStub . firstCall . calledWith ( 'docker' , [
71- 'build' , '-q' ,
79+ 'build' , '-t' , tag ,
7280 '--build-arg' , 'TEST_ARG=cdk-test' ,
7381 'docker-path' ,
7482 ] ) ) ;
7583
7684 test . ok ( spawnSyncStub . secondCall . calledWith ( 'docker' , [
7785 'run' , '--rm' ,
78- imageId ,
86+ tag ,
7987 ] ) ) ;
8088 test . done ( ) ;
8189 } ,
8290
83- 'throws if image id cannot be extracted from build output' ( test : Test ) {
84- sinon . stub ( child_process , 'spawnSync' ) . returns ( {
85- status : 0 ,
86- stderr : Buffer . from ( 'stderr' ) ,
87- stdout : Buffer . from ( 'stdout' ) ,
88- pid : 123 ,
89- output : [ 'stdout' , 'stderr' ] ,
90- signal : null ,
91- } ) ;
92-
93- test . throws ( ( ) => BundlingDockerImage . fromAsset ( 'docker-path' ) , / F a i l e d t o e x t r a c t i m a g e I D f r o m D o c k e r b u i l d o u t p u t / ) ;
94- test . done ( ) ;
95- } ,
96-
9791 'throws in case of spawnSync error' ( test : Test ) {
9892 sinon . stub ( child_process , 'spawnSync' ) . returns ( {
9993 status : 0 ,
@@ -133,11 +127,10 @@ nodeunitShim({
133127 } ,
134128
135129 'BundlerDockerImage json is the bundler image if building an image' ( test : Test ) {
136- const imageId = 'sha256:abcdef123456' ;
137130 sinon . stub ( child_process , 'spawnSync' ) . returns ( {
138131 status : 0 ,
139132 stderr : Buffer . from ( 'stderr' ) ,
140- stdout : Buffer . from ( imageId ) ,
133+ stdout : Buffer . from ( 'stdout' ) ,
141134 pid : 123 ,
142135 output : [ 'stdout' , 'stderr' ] ,
143136 signal : null ,
@@ -148,7 +141,11 @@ nodeunitShim({
148141
149142 const image = BundlingDockerImage . fromAsset ( 'docker-path' ) ;
150143
151- test . equals ( image . image , imageId ) ;
144+ const tagHash = crypto . createHash ( 'sha256' ) . update ( JSON . stringify ( {
145+ path : 'docker-path' ,
146+ } ) ) . digest ( 'hex' ) ;
147+
148+ test . equals ( image . image , `cdk-${ tagHash } ` ) ;
152149 test . equals ( image . toJSON ( ) , imageHash ) ;
153150 test . ok ( fingerprintStub . calledWith ( 'docker-path' , sinon . match ( { extraHash : JSON . stringify ( { } ) } ) ) ) ;
154151 test . done ( ) ;
0 commit comments