Sha256: fbd6ff151105f988c8ccd2f70f80da838de415846de5e25678c4f7776e5b84f7

Contents?: true

Size: 1.35 KB

Versions: 7

Compression:

Stored size: 1.35 KB

Contents

# encoding: utf-8
require "logstash/devutils/rspec/spec_helper"
require "logstash/outputs/s3/write_bucket_permission_validator"
require "aws-sdk"

describe LogStash::Outputs::S3::WriteBucketPermissionValidator do
  let(:logger) { spy(:logger ) }
  let(:bucket_name) { "foobar" }
  let(:obj) { double("s3_object") }
  let(:client) { Aws::S3::Client.new(stub_responses: true) }
  let(:bucket) { Aws::S3::Bucket.new(bucket_name, :client => client) }
  let(:upload_options) { {} }

  subject { described_class.new(logger) }

  before do
    expect(bucket).to receive(:object).with(any_args).and_return(obj)
  end

  context "when permissions are sufficient" do
    it "returns true" do
      expect(obj).to receive(:upload_file).with(any_args).and_return(true)
      expect(obj).to receive(:delete).and_return(true)
      expect(subject.valid?(bucket, upload_options)).to be_truthy
    end

    it "hides delete errors" do
      expect(obj).to receive(:upload_file).with(any_args).and_return(true)
      expect(obj).to receive(:delete).and_raise(StandardError)
      expect(subject.valid?(bucket, upload_options)).to be_truthy
    end
  end

  context "when permission aren't sufficient" do
    it "returns false" do
      expect(obj).to receive(:upload_file).with(any_args).and_raise(StandardError)
      expect(subject.valid?(bucket, upload_options)).to be_falsey
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
logstash-output-s3-4.1.4 spec/outputs/s3/write_bucket_permission_validator_spec.rb
logstash-output-s3-4.1.3 spec/outputs/s3/write_bucket_permission_validator_spec.rb
logstash-output-s3-4.1.2 spec/outputs/s3/write_bucket_permission_validator_spec.rb
logstash-output-s3-4.1.1 spec/outputs/s3/write_bucket_permission_validator_spec.rb
logstash-output-s3-4.1.0 spec/outputs/s3/write_bucket_permission_validator_spec.rb
logstash-output-s3-4.0.13 spec/outputs/s3/write_bucket_permission_validator_spec.rb
logstash-output-s3-4.0.12 spec/outputs/s3/write_bucket_permission_validator_spec.rb