Sha256: bcf39f6b9a2295ed09c4520fa1a03bd7117eafd6ec83cecfa24bd59bc8ee776e

Contents?: true

Size: 1.27 KB

Versions: 7

Compression:

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

  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)).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

7 entries across 7 versions & 1 rubygems

Version Path
logstash-output-s3-4.0.11 spec/outputs/s3/write_bucket_permission_validator_spec.rb
logstash-output-s3-4.0.10 spec/outputs/s3/write_bucket_permission_validator_spec.rb
logstash-output-s3-4.0.9 spec/outputs/s3/write_bucket_permission_validator_spec.rb
logstash-output-s3-4.0.8 spec/outputs/s3/write_bucket_permission_validator_spec.rb
logstash-output-s3-4.0.7 spec/outputs/s3/write_bucket_permission_validator_spec.rb
logstash-output-s3-4.0.6 spec/outputs/s3/write_bucket_permission_validator_spec.rb
logstash-output-s3-4.0.5 spec/outputs/s3/write_bucket_permission_validator_spec.rb