Sha256: 7a0f9943b2a3a780f62628b658bab4849c8fadd3d788ad3f5288516adba4553a

Contents?: true

Size: 1.23 KB

Versions: 4

Compression:

Stored size: 1.23 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(: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) }

  subject { described_class }

  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)).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)).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)).to be_falsey
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
logstash-output-s3-4.0.3 spec/outputs/s3/write_bucket_permission_validator_spec.rb
logstash-output-s3-4.0.2 spec/outputs/s3/write_bucket_permission_validator_spec.rb
logstash-output-s3-4.0.1 spec/outputs/s3/write_bucket_permission_validator_spec.rb
logstash-output-s3-4.0.0 spec/outputs/s3/write_bucket_permission_validator_spec.rb