Sha256: 58de74d2a9c192b1b85d56a292cc2a5d3e32b7b9a7fe7f5e66efa22958f2bdc4

Contents?: true

Size: 1.88 KB

Versions: 7

Compression:

Stored size: 1.88 KB

Contents

require "service/shared_service_tests"

class ActiveStorage::Service::MirrorServiceTest < ActiveSupport::TestCase
  mirror_config = (1..3).map do |i|
    [ "mirror_#{i}",
      service: "Disk",
      root: Dir.mktmpdir("active_storage_tests_mirror_#{i}") ]
  end.to_h

  config = mirror_config.merge \
    mirror:   { service: "Mirror", primary: "primary", mirrors: mirror_config.keys },
    primary:  { service: "Disk", root: Dir.mktmpdir("active_storage_tests_primary") }

  SERVICE = ActiveStorage::Service.configure :mirror, config

  include ActiveStorage::Service::SharedServiceTests

  test "uploading to all services" do
    begin
      data = "Something else entirely!"
      key  = upload(data, to: @service)

      assert_equal data, SERVICE.primary.download(key)
      SERVICE.mirrors.each do |mirror|
        assert_equal data, mirror.download(key)
      end
    ensure
      @service.delete key
    end
  end

  test "downloading from primary service" do
    data = "Something else entirely!"
    key  = upload(data, to: SERVICE.primary)

    assert_equal data, @service.download(key)
  end

  test "deleting from all services" do
    @service.delete FIXTURE_KEY
    assert_not SERVICE.primary.exist?(FIXTURE_KEY)
    SERVICE.mirrors.each do |mirror|
      assert_not mirror.exist?(FIXTURE_KEY)
    end
  end

  test "URL generation in primary service" do
    freeze_time do
      assert_equal SERVICE.primary.url(FIXTURE_KEY, expires_in: 2.minutes, disposition: :inline, filename: "test.txt", content_type: "text/plain"),
        @service.url(FIXTURE_KEY, expires_in: 2.minutes, disposition: :inline, filename: "test.txt", content_type: "text/plain")
    end
  end

  private
    def upload(data, to:)
      SecureRandom.base58(24).tap do |key|
        io = StringIO.new(data).tap(&:read)
        @service.upload key, io, checksum: Digest::MD5.base64digest(data)
        assert io.eof?
      end
    end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
activestorage_legacy-0.2.1 test/service/mirror_service_test.rb
activestorage_legacy-0.2.0 test/service/mirror_service_test.rb
activestorage_legacy-0.1.3 test/service/mirror_service_test.rb
activestorage_legacy-0.1.2 test/service/mirror_service_test.rb
activestorage_legacy-0.1.1 test/service/mirror_service_test.rb
activestorage_legacy-0.1.1.alpha test/service/mirror_service_test.rb
activestorage_legacy-0.1 test/service/mirror_service_test.rb