summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/ci/pipeline/chain/assign_partition_spec.rb
blob: 15df5b2f68c14fa83b724d8d3411d98fed5ac755 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Ci::Pipeline::Chain::AssignPartition do
  let_it_be(:project) { create(:project) }
  let_it_be(:user) { create(:user) }

  let(:command) do
    Gitlab::Ci::Pipeline::Chain::Command.new(project: project, current_user: user)
  end

  let(:pipeline) { build(:ci_pipeline, project: project) }
  let(:step) { described_class.new(pipeline, command) }
  let(:current_partition_id) { 123 }

  describe '#perform!' do
    before do
      allow(Ci::Pipeline).to receive(:current_partition_value) { current_partition_id }
    end

    subject { step.perform! }

    it 'assigns partition_id to pipeline' do
      expect { subject }.to change(pipeline, :partition_id).to(current_partition_id)
    end

    context 'with parent-child pipelines' do
      let(:bridge) do
        instance_double(Ci::Bridge,
          triggers_child_pipeline?: true,
          parent_pipeline: instance_double(Ci::Pipeline, partition_id: 125))
      end

      let(:command) do
        Gitlab::Ci::Pipeline::Chain::Command.new(
          project: project,
          current_user: user,
          bridge: bridge)
      end

      it 'assigns partition_id to pipeline' do
        expect { subject }.to change(pipeline, :partition_id).to(125)
      end
    end
  end
end