Sha256: 515f62de88a3f573399eb3446994e8fb8a2486bd0b24db1fb66872289f2ccd44

Contents?: true

Size: 1.27 KB

Versions: 43

Compression:

Stored size: 1.27 KB

Contents

# encoding: utf-8
require "logstash/devutils/rspec/spec_helper"
require "logstash/outputs/s3/temporary_file"
require "stud/temporary"
require "fileutils"
require "securerandom"

describe LogStash::Outputs::S3::TemporaryFile do
  let(:content) { "hello world" }
  let(:key) { "foo" }
  let(:uuid) { SecureRandom.uuid }
  let(:temporary_file) { ::File.open(::File.join(temporary_directory, uuid, key), "w+") }
  let(:temporary_directory) {  Stud::Temporary.directory }

  before :each do
    FileUtils.mkdir_p(::File.join(temporary_directory, uuid))
  end

  subject { described_class.new(key, temporary_file, temporary_directory) }

  it "returns the key of the file" do
    expect(subject.key).to eq(key)
  end

  it "saves content to a file" do
    subject.write(content)
    subject.close
    expect(File.read(subject.path).strip).to eq(content)
  end

  it "deletes a file" do
    expect(File.exist?(subject.path)).to be_truthy
    subject.delete!
    expect(File.exist?(subject.path)).to be_falsey
  end

  it "successfully delete a file already closed" do
    subject.close
    expect(File.exist?(subject.path)).to be_truthy
    subject.delete!
    expect(File.exist?(subject.path)).to be_falsey
  end

  it "returns the creation time" do
    expect(subject.ctime).to be < Time.now + 0.5
  end
end

Version data entries

43 entries across 43 versions & 2 rubygems

Version Path
logstash-integration-aws-7.1.8-java spec/outputs/s3/temporary_file_spec.rb
logstash-integration-aws-7.1.7-java spec/outputs/s3/temporary_file_spec.rb
logstash-integration-aws-7.1.6-java spec/outputs/s3/temporary_file_spec.rb
logstash-integration-aws-7.1.5-java spec/outputs/s3/temporary_file_spec.rb
logstash-integration-aws-7.1.4-java spec/outputs/s3/temporary_file_spec.rb
logstash-integration-aws-7.1.3-java spec/outputs/s3/temporary_file_spec.rb
logstash-integration-aws-7.1.2-java spec/outputs/s3/temporary_file_spec.rb
logstash-integration-aws-7.1.1-java spec/outputs/s3/temporary_file_spec.rb
logstash-integration-aws-7.1.0 spec/outputs/s3/temporary_file_spec.rb
logstash-integration-aws-7.0.1 spec/outputs/s3/temporary_file_spec.rb
logstash-output-s3-4.4.1 spec/outputs/s3/temporary_file_spec.rb
logstash-integration-aws-7.0.0 spec/outputs/s3/temporary_file_spec.rb
logstash-output-s3-4.4.0 spec/outputs/s3/temporary_file_spec.rb
logstash-output-s3-4.3.7 spec/outputs/s3/temporary_file_spec.rb
logstash-output-s3-4.3.6 spec/outputs/s3/temporary_file_spec.rb
logstash-integration-aws-0.1.0.pre spec/outputs/s3/temporary_file_spec.rb
logstash-output-s3-4.3.5 spec/outputs/s3/temporary_file_spec.rb
logstash-output-s3-4.3.4 spec/outputs/s3/temporary_file_spec.rb
logstash-output-s3-4.3.3 spec/outputs/s3/temporary_file_spec.rb
logstash-output-s3-4.3.2 spec/outputs/s3/temporary_file_spec.rb