@@ -81,22 +81,25 @@ const expectedOptions = {
8181} ;
8282
8383const describeData = {
84- StackName : 'myStack' ,
85- StackStatus : 'CREATE_COMPLETE' ,
86- Outputs : [
87- {
88- OutputKey : 'AssetsBucket' ,
89- OutputValue : 'abc-123456789'
90- } ,
91- {
92- OutputKey : 'CloudFrontDistribution' ,
93- OutputValue : 'EFG123456789'
94- }
95- ]
84+ Stacks : [ {
85+ StackName : 'myStack' ,
86+ StackStatus : 'CREATE_COMPLETE' ,
87+ Outputs : [
88+ {
89+ OutputKey : 'AssetsBucket' ,
90+ OutputValue : 'abc-123456789'
91+ } ,
92+ {
93+ OutputKey : 'CloudFrontDistribution' ,
94+ OutputValue : 'EFG123456789'
95+ }
96+ ]
97+ } ]
9698} ;
9799
98100describe ( 'Cloudformation client' , function ( ) {
99101 let client ;
102+ let logger ;
100103
101104 beforeEach ( function ( ) {
102105 client = new CfnClient ( options ) ;
@@ -115,6 +118,15 @@ describe('Cloudformation client', function() {
115118 sinon . stub ( client . awsClient , 'validateTemplate' ) . returns ( {
116119 promise : sinon . fake . resolves ( )
117120 } ) ;
121+
122+ // minimal logger interface
123+ logger = {
124+ log : sinon . fake ( ) ,
125+ error : sinon . fake ( ) ,
126+ debug : sinon . fake ( )
127+ } ;
128+
129+ client . logger = logger ;
118130 } ) ;
119131
120132 afterEach ( function ( ) {
@@ -134,6 +146,7 @@ describe('Cloudformation client', function() {
134146
135147 expect ( constructor ) . to . always . have . been . calledWithNew ;
136148 expect ( constructor ) . to . have . been . calledWith ( {
149+ apiVersion : '2010-05-15' ,
137150 accessKeyId : 'abc' ,
138151 secretAccessKey : 'def' ,
139152 region : 'us-east-1'
@@ -148,7 +161,12 @@ describe('Cloudformation client', function() {
148161
149162 it ( 'it waits for stackCreateComplete' , function ( ) {
150163 return expect ( callFn ( ) ) . to . be . fulfilled
151- . then ( ( ) => expect ( client . awsClient . waitFor ) . to . have . been . calledWith ( 'stackCreateComplete' , { StackName : 'myStack' } ) ) ;
164+ . then ( ( ) => {
165+ expect ( client . awsClient . waitFor ) . to . have . been . calledWith ( 'stackCreateComplete' , { StackName : 'myStack' } ) ;
166+ expect ( logger . debug ) . to . have . been . calledWith ( `Creating new CloudFormation stack 'myStack'...` ) ;
167+ expect ( logger . log ) . to . have . been . calledWith ( `New CloudFormation stack 'myStack' has been created!` ) ;
168+ expect ( logger . debug ) . to . have . been . calledBefore ( logger . log ) ;
169+ } ) ;
152170 } ) ;
153171
154172 it ( 'rejects when createStack fails' , function ( ) {
@@ -168,7 +186,12 @@ describe('Cloudformation client', function() {
168186
169187 it ( 'it waits for stackUpdateComplete' , function ( ) {
170188 return expect ( callFn ( ) ) . to . be . fulfilled
171- . then ( ( ) => expect ( client . awsClient . waitFor ) . to . have . been . calledWith ( 'stackUpdateComplete' , { StackName : 'myStack' } ) ) ;
189+ . then ( ( ) => {
190+ expect ( client . awsClient . waitFor ) . to . have . been . calledWith ( 'stackUpdateComplete' , { StackName : 'myStack' } ) ;
191+ expect ( logger . debug ) . to . have . been . calledWith ( `Updating CloudFormation stack 'myStack'...` ) ;
192+ expect ( logger . log ) . to . have . been . calledWith ( `CloudFormation stack 'myStack' has been updated!` ) ;
193+ expect ( logger . debug ) . to . have . been . calledBefore ( logger . log ) ;
194+ } ) ;
172195 } ) ;
173196
174197 it ( 'rejects when updateStack fails' , function ( ) {
@@ -185,7 +208,10 @@ describe('Cloudformation client', function() {
185208 } ) ;
186209
187210 return expect ( callFn ( ) ) . to . be . fulfilled
188- . then ( ( ) => expect ( client . awsClient . waitFor ) . to . not . have . been . called ) ;
211+ . then ( ( ) => {
212+ expect ( client . awsClient . waitFor ) . to . not . have . been . called ;
213+ expect ( logger . debug ) . to . have . been . calledWith ( `No updates are to be performed to CloudFormation stack 'myStack'` ) ;
214+ } ) ;
189215 } ) ;
190216 }
191217
@@ -258,6 +284,16 @@ describe('Cloudformation client', function() {
258284 CloudFrontDistribution : 'EFG123456789'
259285 } ) ;
260286 } ) ;
287+
288+ it ( 'returns empty hash when no outputs are found' , function ( ) {
289+ let emptyDescribeData = JSON . parse ( JSON . stringify ( describeData ) ) ;
290+ delete emptyDescribeData . Stacks [ 0 ] . Outputs ;
291+ client . awsClient . describeStacks . returns ( {
292+ promise : sinon . fake . resolves ( emptyDescribeData )
293+ } ) ;
294+
295+ return expect ( client . fetchOutputs ( ) ) . to . eventually . deep . equal ( { } ) ;
296+ } ) ;
261297 } ) ;
262298
263299} ) ;
0 commit comments