diff options
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/ci/build/step_spec.rb | 52 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/job_spec.rb | 31 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/yaml_processor_spec.rb | 42 | ||||
-rw-r--r-- | spec/lib/gitlab/hook_data/issuable_builder_spec.rb | 18 |
4 files changed, 121 insertions, 22 deletions
diff --git a/spec/lib/gitlab/ci/build/step_spec.rb b/spec/lib/gitlab/ci/build/step_spec.rb index 84e6e0e177f..9c1a8cf5e91 100644 --- a/spec/lib/gitlab/ci/build/step_spec.rb +++ b/spec/lib/gitlab/ci/build/step_spec.rb @@ -4,39 +4,49 @@ require 'spec_helper' describe Gitlab::Ci::Build::Step do describe '#from_commands' do - shared_examples 'has correct script' do - subject { described_class.from_commands(job) } + subject { described_class.from_commands(job) } - before do - job.run! - end + before do + job.run! + end + shared_examples 'has correct script' do it 'fabricates an object' do expect(subject.name).to eq(:script) expect(subject.script).to eq(script) - expect(subject.timeout).to eq(job.metadata_timeout) expect(subject.when).to eq('on_success') expect(subject.allow_failure).to be_falsey end end context 'when script option is specified' do - it_behaves_like 'has correct script' do - let(:job) { create(:ci_build, :no_options, options: { script: ["ls -la\necho aaa", "date"] }) } - let(:script) { ["ls -la\necho aaa", 'date'] } - end + let(:job) { create(:ci_build, :no_options, options: { script: ["ls -la\necho aaa", "date"] }) } + let(:script) { ["ls -la\necho aaa", 'date'] } + + it_behaves_like 'has correct script' end context 'when before and script option is specified' do - it_behaves_like 'has correct script' do - let(:job) do - create(:ci_build, options: { - before_script: ["ls -la\necho aaa"], - script: ["date"] - }) - end - - let(:script) { ["ls -la\necho aaa", 'date'] } + let(:job) do + create(:ci_build, options: { + before_script: ["ls -la\necho aaa"], + script: ["date"] + }) + end + + let(:script) { ["ls -la\necho aaa", 'date'] } + + it_behaves_like 'has correct script' + end + + context 'when timeout option is specified in seconds' do + let(:job) { create(:ci_build, options: { job_timeout: 3, script: ["ls -la\necho aaa", 'date'] }) } + let(:script) { ["ls -la\necho aaa", 'date'] } + + it_behaves_like 'has correct script' + + it 'has job level timeout' do + expect(subject.timeout).to eq(3) end end end @@ -57,12 +67,12 @@ describe Gitlab::Ci::Build::Step do end context 'when after_script is not empty' do - let(:job) { create(:ci_build, options: { script: ['bash'], after_script: ['ls -la', 'date'] }) } + let(:job) { create(:ci_build, options: { job_timeout: 60, script: ['bash'], after_script: ['ls -la', 'date'] }) } it 'fabricates an object' do expect(subject.name).to eq(:after_script) expect(subject.script).to eq(['ls -la', 'date']) - expect(subject.timeout).to eq(job.metadata_timeout) + expect(subject.timeout).to eq(60) expect(subject.when).to eq('always') expect(subject.allow_failure).to be_truthy end diff --git a/spec/lib/gitlab/ci/config/entry/job_spec.rb b/spec/lib/gitlab/ci/config/entry/job_spec.rb index 1853efde350..1c4887e87c4 100644 --- a/spec/lib/gitlab/ci/config/entry/job_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/job_spec.rb @@ -417,6 +417,37 @@ describe Gitlab::Ci::Config::Entry::Job do end end end + + context 'when timeout value is not correct' do + context 'when it is higher than instance wide timeout' do + let(:config) { { timeout: '3 months' } } + + it 'returns error about value too high' do + expect(entry).not_to be_valid + expect(entry.errors) + .to include "job timeout should not exceed the limit" + end + end + + context 'when it is not a duration' do + let(:config) { { timeout: 100 } } + + it 'returns error about wrong value' do + expect(entry).not_to be_valid + expect(entry.errors).to include 'job timeout should be a duration' + end + end + end + + context 'when timeout value is correct' do + let(:config) { { script: 'echo', timeout: '1m 1s' } } + + it 'returns correct timeout' do + expect(entry).to be_valid + expect(entry.errors).to be_empty + expect(entry.timeout).to eq('1m 1s') + end + end end end diff --git a/spec/lib/gitlab/ci/yaml_processor_spec.rb b/spec/lib/gitlab/ci/yaml_processor_spec.rb index 9d9a9ecda33..8f2f23f6110 100644 --- a/spec/lib/gitlab/ci/yaml_processor_spec.rb +++ b/spec/lib/gitlab/ci/yaml_processor_spec.rb @@ -1134,6 +1134,48 @@ module Gitlab end end + describe "Timeout" do + let(:config) do + { + deploy_to_production: { + stage: 'deploy', + script: 'test' + } + } + end + + let(:processor) { Gitlab::Ci::YamlProcessor.new(YAML.dump(config)) } + let(:builds) { processor.stage_builds_attributes('deploy') } + + context 'when no timeout was provided' do + it 'does not include job_timeout' do + expect(builds.size).to eq(1) + expect(builds.first[:options]).not_to include(:job_timeout) + end + end + + context 'when an invalid timeout was provided' do + before do + config[:deploy_to_production][:timeout] = 'not-a-number' + end + + it 'raises an error for invalid number' do + expect { builds }.to raise_error('jobs:deploy_to_production timeout should be a duration') + end + end + + context 'when some valid timeout was provided' do + before do + config[:deploy_to_production][:timeout] = '1m 3s' + end + + it 'returns provided timeout value' do + expect(builds.size).to eq(1) + expect(builds.first[:options]).to include(job_timeout: 63) + end + end + end + describe "Dependencies" do let(:config) do { diff --git a/spec/lib/gitlab/hook_data/issuable_builder_spec.rb b/spec/lib/gitlab/hook_data/issuable_builder_spec.rb index 569d5dcc757..97a89b319ea 100644 --- a/spec/lib/gitlab/hook_data/issuable_builder_spec.rb +++ b/spec/lib/gitlab/hook_data/issuable_builder_spec.rb @@ -42,7 +42,15 @@ describe Gitlab::HookData::IssuableBuilder do [{ id: 1, title: 'foo' }], [{ id: 1, title: 'foo' }, { id: 2, title: 'bar' }] ], - total_time_spent: [1, 2] + total_time_spent: [1, 2], + assignees: [ + [], + [{ + name: "Foo Bar", + username: "foobar", + avatar_url: "http://www.example.com/my-avatar.jpg" + }] + ] } end let(:data) { builder.build(user: user, changes: changes) } @@ -58,6 +66,14 @@ describe Gitlab::HookData::IssuableBuilder do total_time_spent: { previous: 1, current: 2 + }, + assignees: { + previous: [], + current: [{ + name: "Foo Bar", + username: "foobar", + avatar_url: "http://www.example.com/my-avatar.jpg" + }] } })) end |