Welcome to mirror list, hosted at ThFree Co, Russian Federation.

expire_in_parser_spec.rb « artifacts « build « ci « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 889878cf3ef08e00ef45bbdc775d15f1d0d08411 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Ci::Build::Artifacts::ExpireInParser do
  describe '.validate_duration', :request_store do
    subject { described_class.validate_duration(value) }

    context 'with never' do
      let(:value) { 'never' }

      it { is_expected.to be_truthy }
    end

    context 'with never value camelized' do
      let(:value) { 'Never' }

      it { is_expected.to be_truthy }
    end

    context 'with a duration' do
      let(:value) { '1 Day' }
      let(:other_value) { '30 seconds' }

      it { is_expected.to be_truthy }

      it 'caches data' do
        expect(ChronicDuration).to receive(:parse).with(value).once.and_call_original
        expect(ChronicDuration).to receive(:parse).with(other_value).once.and_call_original

        2.times do
          expect(described_class.validate_duration(value)).to eq(86400)
          expect(described_class.validate_duration(other_value)).to eq(30)
        end
      end
    end

    context 'without a duration' do
      let(:value) { 'something' }

      it { is_expected.to be_falsy }

      it 'caches data' do
        expect(ChronicDuration).to receive(:parse).with(value).once.and_call_original

        2.times do
          expect(described_class.validate_duration(value)).to be_falsey
        end
      end
    end
  end

  describe '#seconds_from_now' do
    subject { described_class.new(value).seconds_from_now }

    context 'with never' do
      let(:value) { 'never' }

      it { is_expected.to be_nil }
    end

    context 'with an empty string' do
      let(:value) { '' }

      it { is_expected.to be_nil }
    end

    context 'with a duration' do
      let(:value) { '1 day' }

      it { is_expected.to be_like_time(1.day.from_now) }
    end
  end
end