debian-mirror-gitlab/spec/lib/gitlab/ci/build/duration_parser_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

75 lines
1.7 KiB
Ruby
Raw Normal View History

2020-10-24 23:57:45 +05:30
# frozen_string_literal: true
require 'spec_helper'
2022-08-13 15:12:31 +05:30
RSpec.describe Gitlab::Ci::Build::DurationParser do
2022-04-04 11:22:00 +05:30
describe '.validate_duration', :request_store do
2020-10-24 23:57:45 +05:30
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' }
2022-04-04 11:22:00 +05:30
let(:other_value) { '30 seconds' }
2020-10-24 23:57:45 +05:30
it { is_expected.to be_truthy }
2022-04-04 11:22:00 +05:30
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
2020-10-24 23:57:45 +05:30
end
context 'without a duration' do
let(:value) { 'something' }
it { is_expected.to be_falsy }
2022-04-04 11:22:00 +05:30
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
2020-10-24 23:57:45 +05:30
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