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

106 lines
2.9 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::Ci::Build::Step do
2017-08-17 22:00:37 +05:30
describe '#from_commands' do
2019-12-04 20:38:33 +05:30
subject { described_class.from_commands(job) }
2017-09-10 17:25:29 +05:30
2019-12-04 20:38:33 +05:30
before do
job.run!
end
2018-05-09 12:01:36 +05:30
2019-12-04 20:38:33 +05:30
shared_examples 'has correct script' do
2017-09-10 17:25:29 +05:30
it 'fabricates an object' do
expect(subject.name).to eq(:script)
expect(subject.script).to eq(script)
expect(subject.when).to eq('on_success')
expect(subject.allow_failure).to be_falsey
end
end
context 'when script option is specified' do
2019-12-04 20:38:33 +05:30
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'
2017-09-10 17:25:29 +05:30
end
context 'when before and script option is specified' do
2019-12-04 20:38:33 +05:30
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)
2017-09-10 17:25:29 +05:30
end
2017-08-17 22:00:37 +05:30
end
end
2020-06-23 00:09:42 +05:30
describe '#from_release' do
subject { described_class.from_release(job) }
before do
job.run!
end
context 'with release' do
let(:job) { create(:ci_build, :release_options) }
it 'returns the release-cli command line' do
2021-06-08 01:23:25 +05:30
expect(subject.script).to eq(["release-cli create --name \"Release $CI_COMMIT_SHA\" --description \"Created using the release-cli $EXTRA_DESCRIPTION\" --tag-name \"release-$CI_COMMIT_SHA\" --ref \"$CI_COMMIT_SHA\" --assets-link \"{\\\"name\\\":\\\"asset1\\\",\\\"url\\\":\\\"https://example.com/assets/1\\\"}\""])
2020-06-23 00:09:42 +05:30
end
end
context 'when release is empty' do
let(:job) { create(:ci_build) }
it 'does not fabricate an object' do
is_expected.to be_nil
end
end
end
2017-08-17 22:00:37 +05:30
describe '#from_after_script' do
2017-09-10 17:25:29 +05:30
let(:job) { create(:ci_build) }
2017-08-17 22:00:37 +05:30
subject { described_class.from_after_script(job) }
2018-05-09 12:01:36 +05:30
before do
job.run!
end
2017-08-17 22:00:37 +05:30
context 'when after_script is empty' do
2020-06-23 00:09:42 +05:30
it 'does not fabricate an object' do
2017-08-17 22:00:37 +05:30
is_expected.to be_nil
end
end
context 'when after_script is not empty' do
2019-12-04 20:38:33 +05:30
let(:job) { create(:ci_build, options: { job_timeout: 60, script: ['bash'], after_script: ['ls -la', 'date'] }) }
2017-08-17 22:00:37 +05:30
it 'fabricates an object' do
expect(subject.name).to eq(:after_script)
expect(subject.script).to eq(['ls -la', 'date'])
2019-12-04 20:38:33 +05:30
expect(subject.timeout).to eq(60)
2017-08-17 22:00:37 +05:30
expect(subject.when).to eq('always')
expect(subject.allow_failure).to be_truthy
end
end
end
end