Sha256: 90c9eb20004c4e41034cfa69b6029330b059dc7c801db5df9fa95cb617cc0d87

Contents?: true

Size: 1.58 KB

Versions: 1

Compression:

Stored size: 1.58 KB

Contents

require 'test_helper'
require 'tori/backend/s3'

if ENV["TORI_TEST_BUCKET"]

class TestToriBackendS3 < Test::Unit::TestCase
  BucketNotFoundError = Class.new(StandardError)
  setup do
    @backend = Tori::Backend::S3.new(bucket: ENV["TORI_TEST_BUCKET"])
    fail BucketNotFoundError, "S3 test need make s3 bucket '#{@backend.bucket}'" unless @backend.exists?

    @testfile_path = Pathname.new("test/tmp/testfile")
    FileUtils.mkdir_p "test/tmp"
    File.open(@testfile_path.to_s, 'w+'){ |f| f.write('text') }
    @backend.write("testfile", @testfile_path)
  end

  teardown do
    FileUtils.rm_rf("test/tmp")
    @backend.delete("testfile")
  end

  test "#initialize" do
    assert_instance_of Tori::Backend::S3, @backend
    assert_raise(ArgumentError){ Tori::Backend::S3.new }
  end

  test "#respond_to_missing?" do
    %i(exists? read delete).each do |m|
      assert { true == @backend.respond_to?(m) }
    end
  end

  test "#write" do
    assert_nothing_raised { @backend.write("testfile", @testfile_path) }
  end

  test "#read" do
    assert { "test" == @backend.read("testfile") }
  end

  test "#exists?" do
    assert_nothing_raised { @backend.exists?("nothingfile") }
    assert { true == @backend.exists?("testfile") }
  end

  test "#delete" do
    assert_nothing_raised { @backend.delete("testfile") }
    assert { false == @backend.exists?("testfile") }
  end

  test "#public_url" do
    assert_match %r!https?://s3-!, @backend.public_url("testfile")
    assert_match @backend.bucket, @backend.public_url("testfile")
    assert_match "testfile", @backend.public_url("testfile")
  end
end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tori-0.0.5 test/test_tori_backend_s3.rb