Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/tests/functional/gamelift/test_upload_build.py
2634 views
1
# Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License"). You
4
# may not use this file except in compliance with the License. A copy of
5
# the License is located at
6
#
7
# http://aws.amazon.com/apache2.0/
8
#
9
# or in the "license" file accompanying this file. This file is
10
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
# ANY KIND, either express or implied. See the License for the specific
12
# language governing permissions and limitations under the License.
13
import os
14
from awscli.testutils import BaseAWSCommandParamsTest, FileCreator, mock
15
16
17
class TestUploadBuild(BaseAWSCommandParamsTest):
18
19
prefix = 'gamelift upload-build'
20
21
def setUp(self):
22
super().setUp()
23
self.files = FileCreator()
24
25
def tearDown(self):
26
super().tearDown()
27
self.files.remove_all()
28
29
def test_upload_build(self):
30
self.files.create_file('tmpfile', 'Some contents')
31
cmdline = self.prefix
32
cmdline += ' --name mybuild --build-version myversion'
33
cmdline += f' --build-root {self.files.rootdir}'
34
35
self.parsed_responses = [
36
{'Build': {'BuildId': 'myid'}},
37
{'StorageLocation': {
38
'Bucket': 'mybucket',
39
'Key': 'mykey'},
40
'UploadCredentials': {
41
'AccessKeyId': 'myaccesskey',
42
'SecretAccessKey': 'mysecretkey',
43
'SessionToken': 'mytoken'}},
44
{}
45
]
46
47
stdout, stderr, rc = self.run_cmd(cmdline, expected_rc=0)
48
49
# First the build is created.
50
self.assertEqual(len(self.operations_called), 3)
51
self.assertEqual(self.operations_called[0][0].name, 'CreateBuild')
52
self.assertEqual(
53
self.operations_called[0][1],
54
{'Name': 'mybuild', 'Version': 'myversion'}
55
)
56
57
# Second the credentials are requested.
58
self.assertEqual(
59
self.operations_called[1][0].name, 'RequestUploadCredentials')
60
self.assertEqual(
61
self.operations_called[1][1], {'BuildId': 'myid'})
62
63
# The build is then uploaded to S3.
64
self.assertEqual(self.operations_called[2][0].name, 'PutObject')
65
self.assertEqual(
66
self.operations_called[2][1],
67
{'Body': mock.ANY, 'Bucket': 'mybucket', 'Key': 'mykey'}
68
)
69
70
# Check the output of the command.
71
self.assertIn(
72
f'Successfully uploaded {self.files.rootdir} to AWS GameLift',
73
stdout)
74
self.assertIn('Build ID: myid', stdout)
75
76
def test_upload_build_with_operating_system_param(self):
77
self.files.create_file('tmpfile', 'Some contents')
78
cmdline = self.prefix
79
cmdline += ' --name mybuild --build-version myversion'
80
cmdline += f' --build-root {self.files.rootdir}'
81
cmdline += ' --operating-system WINDOWS_2012'
82
83
self.parsed_responses = [
84
{'Build': {'BuildId': 'myid'}},
85
{'StorageLocation': {
86
'Bucket': 'mybucket',
87
'Key': 'mykey'},
88
'UploadCredentials': {
89
'AccessKeyId': 'myaccesskey',
90
'SecretAccessKey': 'mysecretkey',
91
'SessionToken': 'mytoken'}},
92
{}
93
]
94
95
stdout, stderr, rc = self.run_cmd(cmdline, expected_rc=0)
96
97
# First the build is created.
98
self.assertEqual(len(self.operations_called), 3)
99
self.assertEqual(self.operations_called[0][0].name, 'CreateBuild')
100
self.assertEqual(
101
self.operations_called[0][1],
102
{'Name': 'mybuild', 'Version': 'myversion',
103
'OperatingSystem': 'WINDOWS_2012'}
104
)
105
106
# Second the credentials are requested.
107
self.assertEqual(
108
self.operations_called[1][0].name, 'RequestUploadCredentials')
109
self.assertEqual(
110
self.operations_called[1][1], {'BuildId': 'myid'})
111
112
# The build is then uploaded to S3.
113
self.assertEqual(self.operations_called[2][0].name, 'PutObject')
114
self.assertEqual(
115
self.operations_called[2][1],
116
{'Body': mock.ANY, 'Bucket': 'mybucket', 'Key': 'mykey'}
117
)
118
119
# Check the output of the command.
120
self.assertIn(
121
f'Successfully uploaded {self.files.rootdir} to AWS GameLift',
122
stdout)
123
self.assertIn('Build ID: myid', stdout)
124
125
def test_upload_build_with_empty_directory(self):
126
cmdline = self.prefix
127
cmdline += ' --name mybuild --build-version myversion'
128
cmdline += f' --build-root {self.files.rootdir}'
129
130
self.parsed_responses = [
131
{'Build': {'BuildId': 'myid'}},
132
{'StorageLocation': {
133
'Bucket': 'mybucket',
134
'Key': 'mykey'},
135
'UploadCredentials': {
136
'AccessKeyId': 'myaccesskey',
137
'SecretAccessKey': 'mysecretkey',
138
'SessionToken': 'mytoken'}},
139
{}
140
]
141
142
stdout, stderr, rc = self.run_cmd(cmdline, expected_rc=255)
143
144
self.assertIn(
145
f'Fail to upload {self.files.rootdir}. '
146
'The build root directory is empty or does not exist.\n',
147
stderr)
148
149
def test_upload_build_with_nonexistent_directory(self):
150
dir_not_exist = os.path.join(self.files.rootdir, 'does_not_exist')
151
152
cmdline = self.prefix
153
cmdline += ' --name mybuild --build-version myversion'
154
cmdline += f' --build-root {dir_not_exist}'
155
156
self.parsed_responses = [
157
{'Build': {'BuildId': 'myid'}},
158
{'StorageLocation': {
159
'Bucket': 'mybucket',
160
'Key': 'mykey'},
161
'UploadCredentials': {
162
'AccessKeyId': 'myaccesskey',
163
'SecretAccessKey': 'mysecretkey',
164
'SessionToken': 'mytoken'}},
165
{}
166
]
167
168
stdout, stderr, rc = self.run_cmd(cmdline, expected_rc=255)
169
170
self.assertIn(
171
f'Fail to upload {dir_not_exist}. '
172
'The build root directory is empty or does not exist.\n',
173
stderr)
174
175
def test_upload_build_with_nonprovided_directory(self):
176
cmdline = self.prefix
177
cmdline += ' --name mybuild --build-version myversion'
178
cmdline += ' --build-root {}'.format('""')
179
180
self.parsed_responses = [
181
{'Build': {'BuildId': 'myid'}},
182
{'StorageLocation': {
183
'Bucket': 'mybucket',
184
'Key': 'mykey'},
185
'UploadCredentials': {
186
'AccessKeyId': 'myaccesskey',
187
'SecretAccessKey': 'mysecretkey',
188
'SessionToken': 'mytoken'}},
189
{}
190
]
191
192
stdout, stderr, rc = self.run_cmd(cmdline, expected_rc=255)
193
194
self.assertIn(
195
'Fail to upload {}. '
196
'The build root directory is empty or does not exist.\n'.format('""'),
197
stderr)
198
199
def test_upload_build_with_server_sdk_version_param(self):
200
self.files.create_file('tmpfile', 'Some contents')
201
cmdline = self.prefix
202
cmdline += ' --name mybuild --build-version myversion'
203
cmdline += f' --build-root {self.files.rootdir}'
204
cmdline += ' --server-sdk-version 4.0.2'
205
206
self.parsed_responses = [
207
{'Build': {'BuildId': 'myid'}},
208
{'StorageLocation': {
209
'Bucket': 'mybucket',
210
'Key': 'mykey'},
211
'UploadCredentials': {
212
'AccessKeyId': 'myaccesskey',
213
'SecretAccessKey': 'mysecretkey',
214
'SessionToken': 'mytoken'}},
215
{}
216
]
217
218
stdout, stderr, rc = self.run_cmd(cmdline, expected_rc=0)
219
220
# First the build is created.
221
self.assertEqual(len(self.operations_called), 3)
222
self.assertEqual(self.operations_called[0][0].name, 'CreateBuild')
223
self.assertEqual(
224
self.operations_called[0][1],
225
{'Name': 'mybuild', 'Version': 'myversion',
226
'ServerSdkVersion': '4.0.2'}
227
)
228
229
# Second the credentials are requested.
230
self.assertEqual(
231
self.operations_called[1][0].name, 'RequestUploadCredentials')
232
self.assertEqual(
233
self.operations_called[1][1], {'BuildId': 'myid'})
234
235
# The build is then uploaded to S3.
236
self.assertEqual(self.operations_called[2][0].name, 'PutObject')
237
self.assertEqual(
238
self.operations_called[2][1],
239
{'Body': mock.ANY, 'Bucket': 'mybucket', 'Key': 'mykey'}
240
)
241
242
# Check the output of the command.
243
self.assertIn(
244
f'Successfully uploaded {self.files.rootdir} to AWS GameLift',
245
stdout)
246
self.assertIn('Build ID: myid', stdout)
247
248
def test_upload_build_with_tags_param(self):
249
self.files.create_file('tmpfile', 'Some contents')
250
251
expected_tags = [
252
{'Key': 'Key1', 'Value': 'Value1'},
253
{'Key': 'Key2', 'Value': 'Value2'}
254
]
255
256
cmdline = self.prefix
257
cmdline += ' --name mybuild --build-version myversion'
258
cmdline += f' --build-root {self.files.rootdir}'
259
cmdline += ' --tags'
260
for tag in expected_tags:
261
cmdline += ' {}={}'.format(tag['Key'], tag['Value'])
262
263
self.parsed_responses = [
264
{'Build': {'BuildId': 'myid'}},
265
{'StorageLocation': {
266
'Bucket': 'mybucket',
267
'Key': 'mykey'},
268
'UploadCredentials': {
269
'AccessKeyId': 'myaccesskey',
270
'SecretAccessKey': 'mysecretkey',
271
'SessionToken': 'mytoken'}},
272
{}
273
]
274
275
stdout, stderr, rc = self.run_cmd(cmdline, expected_rc=0)
276
277
# First the build is created.
278
self.assertEqual(len(self.operations_called), 3)
279
self.assertEqual(self.operations_called[0][0].name, 'CreateBuild')
280
self.assertEqual(
281
self.operations_called[0][1],
282
{'Name': 'mybuild', 'Version': 'myversion',
283
'Tags': expected_tags}
284
)
285
286
# Second the credentials are requested.
287
self.assertEqual(
288
self.operations_called[1][0].name, 'RequestUploadCredentials')
289
self.assertEqual(
290
self.operations_called[1][1], {'BuildId': 'myid'})
291
292
# The build is then uploaded to S3.
293
self.assertEqual(self.operations_called[2][0].name, 'PutObject')
294
self.assertEqual(
295
self.operations_called[2][1],
296
{'Body': mock.ANY, 'Bucket': 'mybucket', 'Key': 'mykey'}
297
)
298
299
# Check the output of the command.
300
self.assertIn(
301
f'Successfully uploaded {self.files.rootdir} to AWS GameLift',
302
stdout)
303
self.assertIn('Build ID: myid', stdout)
304
305