diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/service/mirror_service_test.rb | 18 |
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 |