2018-11-02 09:20:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-11-01 10:24:29 -04:00
|
|
|
require 'fast_spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::Ci::Config::Normalizer do
|
|
|
|
let(:job_name) { :rspec }
|
2018-11-01 11:17:08 -04:00
|
|
|
let(:job_config) { { script: 'rspec', parallel: 5, name: 'rspec' } }
|
2018-11-01 10:24:29 -04:00
|
|
|
let(:config) { { job_name => job_config } }
|
|
|
|
|
|
|
|
describe '.normalize_jobs' do
|
2018-11-06 12:35:44 -05:00
|
|
|
subject { described_class.new(config).normalize_jobs }
|
2018-11-01 10:24:29 -04:00
|
|
|
|
|
|
|
it 'does not have original job' do
|
|
|
|
is_expected.not_to include(job_name)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has parallelized jobs' do
|
2018-11-06 12:23:45 -05:00
|
|
|
job_names = [:"rspec 1/5", :"rspec 2/5", :"rspec 3/5", :"rspec 4/5", :"rspec 5/5"]
|
2018-11-01 10:24:29 -04:00
|
|
|
|
|
|
|
is_expected.to include(*job_names)
|
|
|
|
end
|
|
|
|
|
2018-11-01 11:17:08 -04:00
|
|
|
it 'sets job instance in options' do
|
|
|
|
expect(subject.values).to all(include(:instance))
|
|
|
|
end
|
|
|
|
|
2018-11-01 10:24:29 -04:00
|
|
|
it 'parallelizes jobs with original config' do
|
|
|
|
original_config = config[job_name].except(:name)
|
2018-11-01 11:17:08 -04:00
|
|
|
configs = subject.values.map { |config| config.except(:name, :instance) }
|
2018-11-01 10:24:29 -04:00
|
|
|
|
|
|
|
expect(configs).to all(eq(original_config))
|
|
|
|
end
|
2018-11-05 09:53:37 -05:00
|
|
|
|
2018-11-06 12:56:06 -05:00
|
|
|
context 'when there is a job with a slash in it' do
|
|
|
|
let(:job_name) { :"rspec 35/2" }
|
|
|
|
|
|
|
|
it 'properly parallelizes job names' do
|
|
|
|
job_names = [:"rspec 35/2 1/5", :"rspec 35/2 2/5", :"rspec 35/2 3/5", :"rspec 35/2 4/5", :"rspec 35/2 5/5"]
|
|
|
|
|
|
|
|
is_expected.to include(*job_names)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-05 09:53:37 -05:00
|
|
|
context 'when jobs depend on parallelized jobs' do
|
|
|
|
let(:config) { { job_name => job_config, other_job: { script: 'echo 1', dependencies: [job_name.to_s] } } }
|
|
|
|
|
|
|
|
it 'parallelizes dependencies' do
|
2018-11-06 12:23:45 -05:00
|
|
|
job_names = ["rspec 1/5", "rspec 2/5", "rspec 3/5", "rspec 4/5", "rspec 5/5"]
|
2018-11-05 09:53:37 -05:00
|
|
|
|
|
|
|
expect(subject[:other_job][:dependencies]).to include(*job_names)
|
|
|
|
end
|
2018-11-06 12:56:06 -05:00
|
|
|
|
|
|
|
it 'does not include original job name in dependencies' do
|
|
|
|
expect(subject[:other_job][:dependencies]).not_to include(job_name)
|
|
|
|
end
|
2018-11-05 09:53:37 -05:00
|
|
|
end
|
2018-11-01 10:24:29 -04:00
|
|
|
end
|
|
|
|
end
|