Sha256: 2806684da473d92437d7ce3f6b8026ff08f9f857297c5bb9c4e90d6bfe2ce2dc

Contents?: true

Size: 1.42 KB

Versions: 8

Compression:

Stored size: 1.42 KB

Contents

# encoding: utf-8

require "spec_helper"

describe LogStash::Timestamp do
  context "constructors" do
    # Via JRuby 9k time see logstash/issues/7463
    # JRuby 9k now uses Java 8 Time with nanosecond precision but
    # our Timestamp use Joda with millisecond precision
    # expected: 2017-06-15 10:34:08.389999999 +0000
    #      got: 2017-06-15 10:34:08.389000000 +0000
    # we may need to use `be_within(0.000999999).of()` in other places too
    it "should work" do
      t = LogStash::Timestamp.new
      expect(t.time.to_i).to be_within(2).of Time.now.to_i

      t = LogStash::Timestamp.now
      expect(t.time.to_i).to be_within(2).of Time.now.to_i

      now = DateTime.now.to_time.utc
      t = LogStash::Timestamp.new(now)
      expect(t.time.to_f).to be_within(0.000999999).of(now.to_f)

      t = LogStash::Timestamp.at(now.to_i)
      expect(t.time.to_i).to eq(now.to_i)
    end

    it "should have consistent behaviour across == and .eql?" do
      its_xmas = Time.utc(2015, 12, 25, 0, 0, 0)
      expect(LogStash::Timestamp.new(its_xmas)).to eql(LogStash::Timestamp.new(its_xmas))
      expect(LogStash::Timestamp.new(its_xmas)).to be ==(LogStash::Timestamp.new(its_xmas))
    end

    it "should raise exception on invalid format" do
      expect{LogStash::Timestamp.new("foobar")}.to raise_error
    end

    it "compares to any type" do
      t = LogStash::Timestamp.new
      expect(t == '-').to be_falsey
    end

  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
logstash-core-6.3.2-java spec/logstash/timestamp_spec.rb
logstash-core-6.3.1-java spec/logstash/timestamp_spec.rb
logstash-core-6.3.0-java spec/logstash/timestamp_spec.rb
logstash-core-6.2.4-java spec/logstash/timestamp_spec.rb
logstash-core-6.2.3-java spec/logstash/timestamp_spec.rb
logstash-core-6.2.2-java spec/logstash/timestamp_spec.rb
logstash-core-6.2.1-java spec/logstash/timestamp_spec.rb
logstash-core-6.2.0-java spec/logstash/timestamp_spec.rb