Sha256: 466ab3e86410bfd97a1dc399a4e425b6e372ede41ddd01e1c5a91f37474a3adc

Contents?: true

Size: 1.88 KB

Versions: 1

Compression:

Stored size: 1.88 KB

Contents

# encoding: utf-8
require "logstash/devutils/rspec/spec_helper"
require "logstash/outputs/swift/time_rotation_policy"
require "logstash/outputs/swift/temporary_file"

describe LogStash::Outputs::Swift::TimeRotationPolicy do
  subject { described_class.new(max_time) }

  let(:max_time) { 1 }
  let(:temporary_directory) {  Stud::Temporary.directory }
  let(:temporary_file) { Stud::Temporary.file }
  let(:name) { "foobar" }
  let(:content) { "hello" * 1000 }
  let(:file) { LogStash::Outputs::Swift::TemporaryFile.new(name, temporary_file, temporary_directory) }

  it "raises an exception if the `file_time` is set to 0" do
    expect { described_class.new(0) }.to raise_error(LogStash::ConfigurationError, /`time_file` need to be greather than 0/)
  end

  it "raises an exception if the `file_time` is < 0" do
    expect { described_class.new(-100) }.to raise_error(LogStash::ConfigurationError, /`time_file` need to be greather than 0/)
  end

  context "when the size of the file is superior to 0" do
    before :each do
      file.write(content)
      file.fsync
    end

    it "returns true if the file old enough" do
      allow(file).to receive(:ctime).and_return(Time.now - (max_time * 2 * 60))
      expect(subject.rotate?(file)).to be_truthy
    end

    it "returns false is not old enough" do
      expect(subject.rotate?(file)).to be_falsey
    end
  end

  context "When the size of the file is 0" do
    it "returns false if the file old enough" do
      allow(file).to receive(:ctime).and_return(Time.now - (max_time * 2 * 60))
      expect(subject.rotate?(file)).to be_falsey
    end

    it "returns false is not old enough" do
      expect(subject.rotate?(file)).to be_falsey
    end
  end

  context "#needs_periodic?" do
    it "return false" do
      expect(subject.needs_periodic?).to be_truthy
    end
  end

  it "convert minute into seconds" do
    expect(subject.time_file).to eq(60)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
logstash-output-swift-0.1 spec/outputs/swift/time_rotation_policy_spec.rb