normalizer_spec.rb 1.17 KB
Newer Older
Matija Čupić's avatar
Matija Čupić committed
1
2
3
4
require 'fast_spec_helper'

describe Gitlab::Ci::Config::Normalizer do
  let(:job_name) { :rspec }
5
  let(:job_config) { { script: 'rspec', parallel: 5, name: 'rspec' } }
Matija Čupić's avatar
Matija Čupić committed
6
7
8
9
10
11
12
13
14
15
  let(:config) { { job_name => job_config } }

  describe '.normalize_jobs' do
    subject { described_class.normalize_jobs(config) }

    it 'does not have original job' do
      is_expected.not_to include(job_name)
    end

    it 'has parallelized jobs' do
16
      job_names = described_class.send(:parallelize_job_names, job_name, 5).map { |job_name, index| job_name.to_sym }
Matija Čupić's avatar
Matija Čupić committed
17
18
19
20

      is_expected.to include(*job_names)
    end

21
22
23
24
    it 'sets job instance in options' do
      expect(subject.values).to all(include(:instance))
    end

Matija Čupić's avatar
Matija Čupić committed
25
26
    it 'parallelizes jobs with original config' do
      original_config = config[job_name].except(:name)
27
      configs = subject.values.map { |config| config.except(:name, :instance) }
Matija Čupić's avatar
Matija Čupić committed
28
29
30
31
32
33
34
35
36

      expect(configs).to all(eq(original_config))
    end
  end

  describe '.parallelize_job_names' do
    subject { described_class.send(:parallelize_job_names, job_name, 5) }

    it 'returns parallelized names' do
37
      expect(subject.map(&:first)).to all(match(%r{#{job_name} \d+/\d+}))
Matija Čupić's avatar
Matija Čupić committed
38
39
40
    end
  end
end