9
9
end
10
10
11
11
# Stub head_object to return a specific content_length
12
- def stub_s3_file_exists ( key , exists )
13
- content_length = exists ? 1 : 0
14
- allow ( client ) . to receive ( :head_object )
12
+ def stub_s3_response_for_file ( key , exists = true )
13
+ content_length = exists == true ? 1 : 0
14
+ allow ( client ) . to ( receive ( :head_object ) )
15
15
. with ( bucket : test_bucket , key : key )
16
16
. and_return ( Aws ::S3 ::Types ::HeadObjectOutput . new ( content_length : content_length ) )
17
17
end
18
18
19
19
describe 'uploading a file' do
20
20
it 'generates a prefix for the key by default' do
21
21
expected_key = '939c39398db2405e791e205778ff70f85dff620e/a8c-key1'
22
- stub_s3_file_does_not_exist ( expected_key )
22
+ stub_s3_response_for_file ( expected_key , exists : false )
23
23
24
24
with_tmp_file_path_for_file_named ( 'input_file_1' ) do |file_path |
25
25
expect ( client ) . to receive ( :put_object ) . with ( body : file_instance_of ( file_path ) , bucket : test_bucket , key : expected_key )
@@ -37,7 +37,7 @@ def stub_s3_file_exists(key, exists)
37
37
38
38
it 'generates a prefix for the key when using auto_prefix:true' do
39
39
expected_key = '8bde1a7a04300df27b52f4383dc997e5fbbff180/a8c-key2'
40
- stub_s3_file_does_not_exist ( expected_key )
40
+ stub_s3_response_for_file ( expected_key , exists : false )
41
41
42
42
with_tmp_file_path_for_file_named ( 'input_file_2' ) do |file_path |
43
43
expect ( client ) . to receive ( :put_object ) . with ( body : file_instance_of ( file_path ) , bucket : test_bucket , key : expected_key )
@@ -56,7 +56,7 @@ def stub_s3_file_exists(key, exists)
56
56
57
57
it 'uses the provided key verbatim when using auto_prefix:false' do
58
58
expected_key = 'a8c-key1'
59
- stub_s3_file_does_not_exist ( expected_key )
59
+ stub_s3_response_for_file ( expected_key , exists : false )
60
60
61
61
with_tmp_file_path do |file_path |
62
62
expect ( client ) . to receive ( :put_object ) . with ( body : file_instance_of ( file_path ) , bucket : test_bucket , key : expected_key )
@@ -75,7 +75,7 @@ def stub_s3_file_exists(key, exists)
75
75
76
76
it 'correctly appends the key if it contains subdirectories' do
77
77
expected_key = '939c39398db2405e791e205778ff70f85dff620e/subdir/a8c-key1'
78
- stub_s3_file_does_not_exist ( expected_key )
78
+ stub_s3_response_for_file ( expected_key , exists : false )
79
79
80
80
with_tmp_file_path_for_file_named ( 'input_file_1' ) do |file_path |
81
81
expect ( client ) . to receive ( :put_object ) . with ( body : file_instance_of ( file_path ) , bucket : test_bucket , key : expected_key )
@@ -93,7 +93,7 @@ def stub_s3_file_exists(key, exists)
93
93
94
94
it 'uses the filename as the key if one is not provided' do
95
95
expected_key = 'c125bd799c6aad31092b02e440a8fae25b45a2ad/test_file_1'
96
- stub_s3_file_does_not_exist ( expected_key )
96
+ stub_s3_response_for_file ( expected_key , exists : false )
97
97
98
98
with_tmp_file_path_for_file_named ( 'test_file_1' ) do |file_path |
99
99
expect ( client ) . to receive ( :put_object ) . with ( body : file_instance_of ( file_path ) , bucket : test_bucket , key : expected_key )
@@ -129,7 +129,7 @@ def stub_s3_file_exists(key, exists)
129
129
file : file_path
130
130
)
131
131
end
132
- end . to raise_error ( FastlaneCore ::Interface ::FastlaneError , 'You must provide a valid key ' )
132
+ end . to raise_error ( FastlaneCore ::Interface ::FastlaneError , 'The provided key must not be empty. Use nil instead if you want to default to the file basename ' )
133
133
end
134
134
135
135
it 'fails if local file does not exist' do
@@ -144,7 +144,7 @@ def stub_s3_file_exists(key, exists)
144
144
145
145
it 'fails if the file already exists on S3' do
146
146
expected_key = 'a62f2225bf70bfaccbc7f1ef2a397836717377de/key'
147
- stub_s3_file_exists ( expected_key )
147
+ stub_s3_response_for_file ( expected_key )
148
148
149
149
with_tmp_file_path_for_file_named ( 'key' ) do |file_path |
150
150
expect do
@@ -153,7 +153,7 @@ def stub_s3_file_exists(key, exists)
153
153
key : 'key' ,
154
154
file : file_path
155
155
)
156
- end . to raise_error ( FastlaneCore ::Interface ::FastlaneError , "File already exists at #{ expected_key } " )
156
+ end . to raise_error ( FastlaneCore ::Interface ::FastlaneError , "File already exists in S3 bucket #{ test_bucket } at #{ expected_key } " )
157
157
end
158
158
end
159
159
end
0 commit comments