Sha256: 36846ff8db61d81e7fb80fed88339ea3bad3a396c98448a792d5a9c45cc64c34

Contents?: true

Size: 1.74 KB

Versions: 28

Compression:

Stored size: 1.74 KB

Contents

# typed: false
require "spec_helper"

describe Kuby::Docker::TimestampTag do
  context '.try_parse' do
    let(:tag_str) { '20200810165134' }

    it 'creates a new timestamp tag' do
      tag = described_class.try_parse(tag_str)
      expect(tag).to be_a(described_class)
    end

    it 'correctly parses the timestamp contained in the tag' do
      time = described_class.try_parse(tag_str).time
      expect([time.year, time.month, time.day, time.hour, time.min, time.sec]).to(
        eq([2020, 8, 10, 16, 51, 34])
      )
    end

    context 'with an invalid tag' do
      let(:tag_str) { 'abc123' }

      it 'returns nil' do
        expect(described_class.try_parse(tag_str)).to eq(nil)
      end
    end
  end

  context '#to_s' do
    it 'serializes the tag as a timestamp' do
      tag = described_class.new(Time.new(2020, 8, 10, 16, 51, 34))
      expect(tag.to_s).to eq('20200810165134')
    end
  end

  context 'comparison' do
    it 'ensures tags can be compared by their timestamp values' do
      seed_time = Time.now
      times = [seed_time, seed_time + 5, seed_time + 10, seed_time + 15].shuffle
      tags = times.map { |t| described_class.new(t) }
      expect(tags.sort.map(&:time)).to eq(times.sort)
    end
  end

  context 'equality' do
    it 'ensures tags with equal times are considered equal' do
      time = Time.now
      tag1 = described_class.new(time)
      tag2 = described_class.new(time)
      expect(tag1).to eq(tag2)
      expect(tag1.hash).to eq(tag2.hash)
    end

    it 'ensures tags with inequal times are not considered equal' do
      time = Time.now
      tag1 = described_class.new(time)
      tag2 = described_class.new(time + 5)
      expect(tag1).to_not eq(tag2)
      expect(tag1.hash).to_not eq(tag2.hash)
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
kuby-core-0.20.2 spec/docker/timestamp_tag_spec.rb
kuby-core-0.20.1 spec/docker/timestamp_tag_spec.rb
kuby-core-0.20.0 spec/docker/timestamp_tag_spec.rb
kuby-core-0.19.0 spec/docker/timestamp_tag_spec.rb
kuby-core-0.18.0 spec/docker/timestamp_tag_spec.rb
kuby-core-0.17.0 spec/docker/timestamp_tag_spec.rb
kuby-core-0.16.1 spec/docker/timestamp_tag_spec.rb
kuby-core-0.16.0 spec/docker/timestamp_tag_spec.rb
kuby-core-0.15.0 spec/docker/timestamp_tag_spec.rb
kuby-core-0.14.0 spec/docker/timestamp_tag_spec.rb
kuby-core-0.13.0 spec/docker/timestamp_tag_spec.rb
kuby-core-0.12.0 spec/docker/timestamp_tag_spec.rb
kuby-core-0.11.16 spec/docker/timestamp_tag_spec.rb
kuby-core-0.11.15 spec/docker/timestamp_tag_spec.rb
kuby-core-0.11.14 spec/docker/timestamp_tag_spec.rb
kuby-core-0.11.13 spec/docker/timestamp_tag_spec.rb
kuby-core-0.11.12 spec/docker/timestamp_tag_spec.rb
kuby-core-0.11.11 spec/docker/timestamp_tag_spec.rb
kuby-core-0.11.10 spec/docker/timestamp_tag_spec.rb
kuby-core-0.11.9 spec/docker/timestamp_tag_spec.rb