@@ -28,6 +28,7 @@ const defaultTaskParameters: TaskParameters = {
28
28
bundlePrefix : '' ,
29
29
bundleKey : 'undefined' ,
30
30
description : '' ,
31
+ filesAcl : '' ,
31
32
fileExistsBehavior : '' ,
32
33
updateOutdatedInstancesOnly : false ,
33
34
ignoreApplicationStopFailures : false ,
@@ -44,6 +45,21 @@ const codeDeployDeploymentId = {
44
45
}
45
46
46
47
describe ( 'CodeDeploy Deploy Application' , ( ) => {
48
+ // Creates a simple mock that always succeeds (at least for these tests)
49
+ function createSuccessfulCodeDeploy ( ) : CodeDeploy {
50
+ const codeDeploy = new CodeDeploy ( ) as any
51
+ codeDeploy . getApplication = jest . fn ( ( ) => emptyPromise )
52
+ codeDeploy . getDeploymentGroup = jest . fn ( ( ) => emptyPromise )
53
+ codeDeploy . createDeployment = jest . fn ( ( ) => codeDeployDeploymentId )
54
+ codeDeploy . waitFor = jest . fn ( ( thing , thing2 , cb ) => {
55
+ cb ( )
56
+
57
+ return { promise : ( ) => undefined }
58
+ } )
59
+
60
+ return codeDeploy
61
+ }
62
+
47
63
// TODO https://github.com/aws/aws-vsts-tools/issues/167
48
64
beforeAll ( ( ) => {
49
65
SdkUtils . readResourcesFromRelativePath ( '../../build/src/tasks/CodeDeployDeployApplication/task.json' )
@@ -75,10 +91,7 @@ describe('CodeDeploy Deploy Application', () => {
75
91
expect . assertions ( 1 )
76
92
const taskParameters = { ...defaultTaskParameters }
77
93
taskParameters . deploymentRevisionSource = revisionSourceFromS3
78
- const codeDeploy = new CodeDeploy ( ) as any
79
- codeDeploy . getApplication = jest . fn ( ( ) => emptyPromise )
80
- codeDeploy . getDeploymentGroup = jest . fn ( ( ) => emptyPromise )
81
- const taskOperations = new TaskOperations ( codeDeploy , new S3 ( ) , taskParameters )
94
+ const taskOperations = new TaskOperations ( createSuccessfulCodeDeploy ( ) , new S3 ( ) , taskParameters )
82
95
await taskOperations . execute ( ) . catch ( err => {
83
96
expect ( `${ err } ` ) . toContain ( 'Archive with key undefined does not exist' )
84
97
} )
@@ -89,10 +102,7 @@ describe('CodeDeploy Deploy Application', () => {
89
102
const taskParameters = { ...defaultTaskParameters }
90
103
taskParameters . deploymentRevisionSource = revisionSourceFromS3
91
104
taskParameters . bundleKey = '/whatever/wahtever'
92
- const codeDeploy = new CodeDeploy ( ) as any
93
- codeDeploy . getApplication = jest . fn ( ( ) => emptyPromise )
94
- codeDeploy . getDeploymentGroup = jest . fn ( ( ) => emptyPromise )
95
- codeDeploy . createDeployment = jest . fn ( ( ) => codeDeployDeploymentId )
105
+ const codeDeploy = createSuccessfulCodeDeploy ( ) as any
96
106
// the first argument of the callback is error so pass in an "error"
97
107
codeDeploy . waitFor = jest . fn ( ( arr1 , arr2 , cb ) => cb ( new Error ( '22' ) , undefined ) )
98
108
const s3 = new S3 ( ) as any
@@ -103,44 +113,76 @@ describe('CodeDeploy Deploy Application', () => {
103
113
} )
104
114
} )
105
115
106
- test ( 'Upload needed, packages properly, succeeds' , async ( ) => {
107
- expect . assertions ( 6 )
108
- process . env . TEMP = __dirname
109
- const taskParameters = { ...defaultTaskParameters }
110
- taskParameters . deploymentRevisionSource = revisionSourceFromWorkspace
111
- taskParameters . revisionBundle = path . join ( __dirname , '../../resources/codeDeployCode' )
112
- taskParameters . applicationName = 'test'
113
- const s3 = new S3 ( ) as any
114
- s3 . upload = jest . fn ( args => {
115
- expect ( args . Bucket ) . toBe ( '' )
116
- expect ( args . Key ) . toContain ( 'test.v' )
117
- const dir = fs . readdirSync ( __dirname )
118
- for ( const file of dir ) {
119
- if ( path . extname ( file ) === '.zip' ) {
120
- const f = path . join ( __dirname , file )
121
- const zip = new AdmZip ( f )
122
- const entries = zip . getEntries ( ) . map ( it => it . entryName )
123
- expect ( entries . length ) . toBe ( 3 )
124
- expect ( entries ) . toContain ( 'test.txt' )
125
- expect ( entries ) . toContain ( 'subpath/' )
126
- expect ( entries ) . toContain ( 'subpath/abc.txt' )
127
- break
116
+ describe ( 'S3 upload needed' , ( ) => {
117
+ let parameters : TaskParameters
118
+
119
+ beforeEach ( ( ) => {
120
+ process . env . TEMP = __dirname
121
+
122
+ parameters = { ...defaultTaskParameters }
123
+ parameters . deploymentRevisionSource = revisionSourceFromWorkspace
124
+ parameters . revisionBundle = path . join ( __dirname , '../../resources/codeDeployCode' )
125
+ parameters . applicationName = 'test'
126
+ } )
127
+
128
+ test ( 'Upload needed, packages properly, succeeds' , async ( ) => {
129
+ expect . assertions ( 7 )
130
+
131
+ const s3 = new S3 ( ) as any
132
+ s3 . upload = jest . fn ( args => {
133
+ expect ( args . Bucket ) . toBe ( '' )
134
+ expect ( args . Key ) . toContain ( 'test.v' )
135
+ expect ( args . ACL ) . toBeUndefined ( )
136
+ const dir = fs . readdirSync ( __dirname )
137
+ for ( const file of dir ) {
138
+ if ( path . extname ( file ) === '.zip' ) {
139
+ const f = path . join ( __dirname , file )
140
+ const zip = new AdmZip ( f )
141
+ const entries = zip . getEntries ( ) . map ( it => it . entryName )
142
+ expect ( entries . length ) . toBe ( 3 )
143
+ expect ( entries ) . toContain ( 'test.txt' )
144
+ expect ( entries ) . toContain ( 'subpath/' )
145
+ expect ( entries ) . toContain ( 'subpath/abc.txt' )
146
+ break
147
+ }
128
148
}
129
- }
130
149
131
- return emptyPromise
150
+ return emptyPromise
151
+ } )
152
+
153
+ const taskOperations = new TaskOperations ( createSuccessfulCodeDeploy ( ) , s3 , parameters )
154
+ await taskOperations . execute ( )
132
155
} )
133
- const codeDeploy = new CodeDeploy ( ) as any
134
- codeDeploy . getApplication = jest . fn ( ( ) => emptyPromise )
135
- codeDeploy . getDeploymentGroup = jest . fn ( ( ) => emptyPromise )
136
- codeDeploy . createDeployment = jest . fn ( ( ) => codeDeployDeploymentId )
137
- codeDeploy . waitFor = jest . fn ( ( thing , thing2 , cb ) => {
138
- cb ( )
139
156
140
- return { promise : ( ) => undefined }
157
+ test ( 'Uses ACL provided by task parameters' , async ( ) => {
158
+ expect . assertions ( 1 )
159
+ parameters . filesAcl = 'bucket-owner-full-control'
160
+
161
+ const s3 = new S3 ( ) as any
162
+ s3 . upload = jest . fn ( args => {
163
+ expect ( args . ACL ) . toBe ( 'bucket-owner-full-control' )
164
+
165
+ return emptyPromise
166
+ } )
167
+
168
+ const taskOperations = new TaskOperations ( createSuccessfulCodeDeploy ( ) , s3 , parameters )
169
+ await taskOperations . execute ( )
170
+ } )
171
+
172
+ test ( 'Does not set ACL when using "none"' , async ( ) => {
173
+ expect . assertions ( 1 )
174
+ parameters . filesAcl = 'none'
175
+
176
+ const s3 = new S3 ( ) as any
177
+ s3 . upload = jest . fn ( args => {
178
+ expect ( args . ACL ) . toBeUndefined ( )
179
+
180
+ return emptyPromise
181
+ } )
182
+
183
+ const taskOperations = new TaskOperations ( createSuccessfulCodeDeploy ( ) , s3 , parameters )
184
+ await taskOperations . execute ( )
141
185
} )
142
- const taskOperations = new TaskOperations ( codeDeploy , s3 , taskParameters )
143
- await taskOperations . execute ( )
144
186
} )
145
187
146
188
test ( 'Upload not needed, succeeds' , async ( ) => {
@@ -150,16 +192,7 @@ describe('CodeDeploy Deploy Application', () => {
150
192
taskParameters . bundleKey = path . join ( __dirname , '../../resources/codeDeployCode.zip' )
151
193
const s3 = new S3 ( ) as any
152
194
s3 . headObject = jest . fn ( ( ) => emptyPromise )
153
- const codeDeploy = new CodeDeploy ( ) as any
154
- codeDeploy . getApplication = jest . fn ( ( ) => emptyPromise )
155
- codeDeploy . getDeploymentGroup = jest . fn ( ( ) => emptyPromise )
156
- codeDeploy . createDeployment = jest . fn ( ( ) => codeDeployDeploymentId )
157
- codeDeploy . waitFor = jest . fn ( ( thing , thing2 , cb ) => {
158
- cb ( )
159
-
160
- return { promise : ( ) => undefined }
161
- } )
162
- const taskOperations = new TaskOperations ( codeDeploy , s3 , taskParameters )
195
+ const taskOperations = new TaskOperations ( createSuccessfulCodeDeploy ( ) , s3 , taskParameters )
163
196
await taskOperations . execute ( )
164
197
} )
165
198
} )
0 commit comments