aboutsummaryrefslogtreecommitdiffstats
path: root/test/service
diff options
context:
space:
mode:
authorJeremy Daer <jeremydaer@gmail.com>2017-07-08 15:41:14 -0700
committerJeremy Daer <jeremydaer@gmail.com>2017-07-08 17:16:52 -0700
commit6116313da4996ef99dcb45e2b9ac90ef073caabc (patch)
tree985b02ee94c8b11938ae4a73805577f29861a8ca /test/service
parent8f125d5b7970727064895f67887a59c1cedcf273 (diff)
downloadrails-6116313da4996ef99dcb45e2b9ac90ef073caabc.tar.gz
rails-6116313da4996ef99dcb45e2b9ac90ef073caabc.tar.bz2
rails-6116313da4996ef99dcb45e2b9ac90ef073caabc.zip
Mirror: explicit primary service and list of mirrors
Pass separate primary service and list of mirrors rather than treating the first of the services list as the primary. Nice fit for keyword args, and something we've long wanted in the equivalent Basecamp file repository. Upload returns the results of the underlying service uploads rather than the io.rewind result. Rewind before uploading rather than afterward, and demonstrate that behavior with a test. Test that more than one mirror works.
Diffstat (limited to 'test/service')
-rw-r--r--test/service/mirror_service_test.rb18
1 files changed, 13 insertions, 5 deletions
diff --git a/test/service/mirror_service_test.rb b/test/service/mirror_service_test.rb
index 45535c754e..10af41c0a8 100644
--- a/test/service/mirror_service_test.rb
+++ b/test/service/mirror_service_test.rb
@@ -3,9 +3,11 @@ require "service/shared_service_tests"
class ActiveStorage::Service::MirrorServiceTest < ActiveSupport::TestCase
PRIMARY_DISK_SERVICE = ActiveStorage::Service.configure(:Disk, root: File.join(Dir.tmpdir, "active_storage"))
- SECONDARY_DISK_SERVICE = ActiveStorage::Service.configure(:Disk, root: File.join(Dir.tmpdir, "active_storage_mirror"))
+ MIRROR_SERVICES = (1..3).map do |i|
+ ActiveStorage::Service.configure(:Disk, root: File.join(Dir.tmpdir, "active_storage_mirror_#{i}"))
+ end
- SERVICE = ActiveStorage::Service.configure :Mirror, services: [ PRIMARY_DISK_SERVICE, SECONDARY_DISK_SERVICE ]
+ SERVICE = ActiveStorage::Service.configure :Mirror, primary: PRIMARY_DISK_SERVICE, mirrors: MIRROR_SERVICES
include ActiveStorage::Service::SharedServiceTests
@@ -15,7 +17,9 @@ class ActiveStorage::Service::MirrorServiceTest < ActiveSupport::TestCase
key = upload(data, to: @service)
assert_equal data, PRIMARY_DISK_SERVICE.download(key)
- assert_equal data, SECONDARY_DISK_SERVICE.download(key)
+ MIRROR_SERVICES.each do |mirror|
+ assert_equal data, mirror.download(key)
+ end
ensure
@service.delete key
end
@@ -31,7 +35,9 @@ class ActiveStorage::Service::MirrorServiceTest < ActiveSupport::TestCase
test "deleting from all services" do
@service.delete FIXTURE_KEY
assert_not PRIMARY_DISK_SERVICE.exist?(FIXTURE_KEY)
- assert_not SECONDARY_DISK_SERVICE.exist?(FIXTURE_KEY)
+ MIRROR_SERVICES.each do |mirror|
+ assert_not mirror.exist?(FIXTURE_KEY)
+ end
end
test "URL generation in primary service" do
@@ -44,7 +50,9 @@ class ActiveStorage::Service::MirrorServiceTest < ActiveSupport::TestCase
private
def upload(data, to:)
SecureRandom.base58(24).tap do |key|
- @service.upload key, StringIO.new(data), checksum: Digest::MD5.base64digest(data)
+ io = StringIO.new(data).tap(&:read)
+ @service.upload key, io, checksum: Digest::MD5.base64digest(data)
+ assert io.eof?
end
end
end