File: setup_default_service_spec.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (46 lines) | stat: -rw-r--r-- 1,403 bytes parent folder | download
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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Ci::Partitions::SetupDefaultService, feature_category: :ci_scaling do
  let(:service) { described_class.new }

  before do
    FactoryBot.rewind_sequences
  end

  describe '.execute' do
    subject(:execute) { service.execute }

    context 'when current ci_partition exists' do
      let!(:current_partition) { create(:ci_partition, :current) }

      it 'does not set up default values for ci_partitions' do
        expect(service).not_to receive(:setup_default_partitions)

        execute
      end
    end

    context 'when default ci_partitions do not exist' do
      it 'creates the default partitions', :aggregate_failures do
        expect { execute }.to change { Ci::Partition.count }.by(3)
      end
    end

    context 'when default partitions exist with incorrect statuses' do
      let(:status_active) { Ci::Partition.statuses[:active] }
      let(:status_current) { Ci::Partition.statuses[:current] }

      before do
        create_list(:ci_partition, 3)
      end

      it 'returns success and update statuses for ci_partitions', :aggregate_failures do
        expect { execute }.not_to change { Ci::Partition.count }
        expect(Ci::Partition.first.status).to eq(status_current)
        expect(Ci::Partition.last(2).pluck(:status)).to contain_exactly(status_active, status_active)
      end
    end
  end
end