Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support/helpers/workhorse_helpers.rb')
-rw-r--r--spec/support/helpers/workhorse_helpers.rb55
1 files changed, 47 insertions, 8 deletions
diff --git a/spec/support/helpers/workhorse_helpers.rb b/spec/support/helpers/workhorse_helpers.rb
index 40007a14b85..e0fba191deb 100644
--- a/spec/support/helpers/workhorse_helpers.rb
+++ b/spec/support/helpers/workhorse_helpers.rb
@@ -22,16 +22,40 @@ module WorkhorseHelpers
# workhorse_post_with_file will transform file_key inside params as if it was disk accelerated by workhorse
def workhorse_post_with_file(url, file_key:, params:)
+ workhorse_request_with_file(:post, url,
+ file_key: file_key,
+ params: params,
+ env: { 'CONTENT_TYPE' => 'multipart/form-data' },
+ send_rewritten_field: true
+ )
+ end
+
+ # workhorse_finalize will transform file_key inside params as if it was the finalize call of an inline object storage upload.
+ # note that based on the content of the params it can simulate a disc acceleration or an object storage upload
+ def workhorse_finalize(url, method: :post, file_key:, params:, headers: {})
+ workhorse_request_with_file(method, url,
+ file_key: file_key,
+ params: params,
+ extra_headers: headers,
+ send_rewritten_field: false
+ )
+ end
+
+ def workhorse_request_with_file(method, url, file_key:, params:, env: {}, extra_headers: {}, send_rewritten_field:)
workhorse_params = params.dup
file = workhorse_params.delete(file_key)
- workhorse_params.merge!(workhorse_disk_accelerated_file_params(file_key, file))
+ workhorse_params = workhorse_disk_accelerated_file_params(file_key, file).merge(workhorse_params)
+
+ headers = if send_rewritten_field
+ workhorse_rewritten_fields_header(file_key => file.path)
+ else
+ {}
+ end
+
+ headers.merge!(extra_headers)
- post(url,
- params: workhorse_params,
- headers: workhorse_rewritten_fields_header(file_key => file.path),
- env: { 'CONTENT_TYPE' => 'multipart/form-data' }
- )
+ process(method, url, params: workhorse_params, headers: headers, env: env)
end
private
@@ -45,9 +69,24 @@ module WorkhorseHelpers
end
def workhorse_disk_accelerated_file_params(key, file)
+ return {} unless file
+
{
"#{key}.name" => file.original_filename,
- "#{key}.path" => file.path
- }
+ "#{key}.size" => file.size
+ }.tap do |params|
+ params["#{key}.path"] = file.path if file.path
+ params["#{key}.remote_id"] = file.remote_id if file.respond_to?(:remote_id) && file.remote_id
+ end
+ end
+
+ def fog_to_uploaded_file(file)
+ filename = File.basename(file.key)
+
+ UploadedFile.new(nil,
+ filename: filename,
+ remote_id: filename,
+ size: file.content_length
+ )
end
end