diff options
author | Dino Maric <dino.onex@gmail.com> | 2017-07-31 17:09:12 +0200 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2017-07-31 10:09:12 -0500 |
commit | 3f4a7218a4a4923a0e7ce1b2eb0d2888ce30da58 (patch) | |
tree | c0bbdc0f980bdb58f79f622642b387b3998af9da /test | |
parent | 6c68524b69e1bfb28f0d1aa5967fd602ed1b7ed7 (diff) | |
download | rails-3f4a7218a4a4923a0e7ce1b2eb0d2888ce30da58.tar.gz rails-3f4a7218a4a4923a0e7ce1b2eb0d2888ce30da58.tar.bz2 rails-3f4a7218a4a4923a0e7ce1b2eb0d2888ce30da58.zip |
Azure Storage support (#36)
* Microsoft Azure storage support
* Add support for Microsoft Azure Storage
* Comply with the new headers implementation
Diffstat (limited to 'test')
-rw-r--r-- | test/controllers/direct_uploads_controller_test.rb | 34 | ||||
-rw-r--r-- | test/service/azure_service_test.rb | 14 | ||||
-rw-r--r-- | test/service/configurations-example.yml | 7 |
3 files changed, 55 insertions, 0 deletions
diff --git a/test/controllers/direct_uploads_controller_test.rb b/test/controllers/direct_uploads_controller_test.rb index 7ffa77ea73..7185bf2737 100644 --- a/test/controllers/direct_uploads_controller_test.rb +++ b/test/controllers/direct_uploads_controller_test.rb @@ -67,6 +67,40 @@ else puts "Skipping GCS Direct Upload tests because no GCS configuration was supplied" end +if SERVICE_CONFIGURATIONS[:azure] + class ActiveStorage::AzureDirectUploadsControllerTest < ActionDispatch::IntegrationTest + setup do + @config = SERVICE_CONFIGURATIONS[:azure] + + @old_service = ActiveStorage::Blob.service + ActiveStorage::Blob.service = ActiveStorage::Service.configure(:azure, SERVICE_CONFIGURATIONS) + end + + teardown do + ActiveStorage::Blob.service = @old_service + end + + test "creating new direct upload" do + checksum = Digest::MD5.base64digest("Hello") + + post rails_direct_uploads_url, params: { blob: { + filename: "hello.txt", byte_size: 6, checksum: checksum, content_type: "text/plain" } } + + @response.parsed_body.tap do |details| + assert_equal ActiveStorage::Blob.find(details["id"]), ActiveStorage::Blob.find_signed(details["signed_id"]) + assert_equal "hello.txt", details["filename"] + assert_equal 6, details["byte_size"] + assert_equal checksum, details["checksum"] + assert_equal "text/plain", details["content_type"] + assert_match %r{#{@config[:storage_account_name]}\.blob\.core\.windows\.net/#{@config[:container]}}, details["direct_upload"]["url"] + assert_equal({ "Content-Type" => "text/plain", "Content-MD5" => checksum, "x-ms-blob-type" => "BlockBlob" }, details["direct_upload"]["headers"]) + end + end + end +else + puts "Skipping Azure Direct Upload tests because no Azure configuration was supplied" +end + class ActiveStorage::DiskDirectUploadsControllerTest < ActionDispatch::IntegrationTest test "creating new direct upload" do checksum = Digest::MD5.base64digest("Hello") diff --git a/test/service/azure_service_test.rb b/test/service/azure_service_test.rb new file mode 100644 index 0000000000..0ddbac83e7 --- /dev/null +++ b/test/service/azure_service_test.rb @@ -0,0 +1,14 @@ +require "service/shared_service_tests" +require "httparty" +require "uri" + +if SERVICE_CONFIGURATIONS[:azure] + class ActiveStorage::Service::AzureServiceTest < ActiveSupport::TestCase + SERVICE = ActiveStorage::Service.configure(:azure, SERVICE_CONFIGURATIONS) + + include ActiveStorage::Service::SharedServiceTests + end + +else + puts "Skipping Azure Storage Service tests because no Azure configuration was supplied" +end diff --git a/test/service/configurations-example.yml b/test/service/configurations-example.yml index 8bcc57f05a..68f6ae4224 100644 --- a/test/service/configurations-example.yml +++ b/test/service/configurations-example.yml @@ -22,3 +22,10 @@ gcs: } project: bucket: + +azure: + service: Azure + path: "" + storage_account_name: "" + storage_access_key: "" + container: "" |