Sha256: 851e153931a8bf24121ddf9317eba8fc3bcc642a817f96b728f167f8f0d46923

Contents?: true

Size: 1.58 KB

Versions: 115

Compression:

Stored size: 1.58 KB

Contents

require 'test/test_helper'
require 'aws-sdk'

class AwsSdkV2CommandsTest < Test::Unit::TestCase
  def setup
    @creds = Aws::Credentials.new('123', 'abc')
    @s3    = Aws::S3::Client.new(credentials: @creds, region: 'us-east-1', endpoint: 'http://localhost:10453/')
    @resource = Aws::S3::Resource.new(client: @s3)
    @bucket = @resource.create_bucket(bucket: 'v2_bucket')

    # Delete all objects to avoid sharing state between tests
    @bucket.objects.each(&:delete)
  end

  def test_create_bucket
    bucket = @resource.create_bucket(bucket: 'v2_create_bucket')
    assert_not_nil bucket

    bucket_names = @resource.buckets.map(&:name)
    assert(bucket_names.index("v2_create_bucket") >= 0)
  end

  def test_destroy_bucket
    @bucket.delete

    begin
      @s3.head_bucket(bucket: 'v2_bucket')
      assert_fail("Shouldn't succeed here")
    rescue
    end
  end

  def test_create_object
    object = @bucket.object('key')
    object.put(body: 'test')

    assert_equal 'test', object.get.body.string
  end

  def test_delete_object
    object = @bucket.object('exists')
    object.put(body: 'test')

    assert_equal 'test', object.get.body.string

    object.delete

    assert_raise Aws::S3::Errors::NoSuchKey do
      object.get
    end
  end

  # TODO - get this test working
  #
  #def test_copy_object
  #  object = @bucket.object("key_one")
  #  object.put(body: 'asdf')

  #  # TODO: explore why 'key1' won't work but 'key_one' will
  #  object2 = @bucket.object('key_two')
  #  object2.copy_from(copy_source: 'testing_copy/key_one')

  #  assert_equal 2, @bucket.objects.count
  #end
end

Version data entries

115 entries across 115 versions & 23 rubygems

Version Path
plntr-fakes3-1.0.0.pre.28 test/aws_sdk_v2_commands_test.rb
plntr-fakes3-1.0.0.pre.27 test/aws_sdk_v2_commands_test.rb
plntr-fakes3-1.0.0.pre.26 test/aws_sdk_v2_commands_test.rb
plntr-fakes3-1.0.0.pre.25 test/aws_sdk_v2_commands_test.rb
plntr-fakes3-1.0.0.pre.24 test/aws_sdk_v2_commands_test.rb
plntr-fakes3-1.0.0.pre.23 test/aws_sdk_v2_commands_test.rb
plntr-fakes3-1.0.0.pre.22 test/aws_sdk_v2_commands_test.rb
plntr-fakes3-1.0.0.pre.21 test/aws_sdk_v2_commands_test.rb
plntr-fakes3-1.0.0.pre.20 test/aws_sdk_v2_commands_test.rb
plntr-fakes3-1.0.0.pre.19 test/aws_sdk_v2_commands_test.rb
plntr-fakes3-1.0.0.pre.18 test/aws_sdk_v2_commands_test.rb
plntr-fakes3-1.0.0.pre.17 test/aws_sdk_v2_commands_test.rb
plntr-fakes3-1.0.0.pre.16 test/aws_sdk_v2_commands_test.rb
plntr-fakes3-1.0.0.pre.15 test/aws_sdk_v2_commands_test.rb
plntr-fakes3-1.0.0.pre.14 test/aws_sdk_v2_commands_test.rb
plntr-fakes3-1.0.0.pre.13 test/aws_sdk_v2_commands_test.rb
plntr-fakes3-1.0.0.pre.12 test/aws_sdk_v2_commands_test.rb
plntr-fakes3-1.0.0.pre.12alpha2 test/aws_sdk_v2_commands_test.rb
plntr-fakes3-1.0.0.pre.12alpha1 test/aws_sdk_v2_commands_test.rb
plntr-fakes3-1.0.0.pre.11 test/aws_sdk_v2_commands_test.rb