Welcome to mirror list, hosted at ThFree Co, Russian Federation.

change_public_projects_cost_factor_spec.rb « migrations « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 656c8a45c57a42b1a0c87590b815d6f82223e366 (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
48
49
50
51
52
53
54
55
56
57
58
59
# frozen_string_literal: true

require 'spec_helper'
require_migration!

RSpec.describe ChangePublicProjectsCostFactor, migration: :gitlab_ci, feature_category: :runner do
  let(:runners) { table(:ci_runners) }

  let!(:shared_1) { runners.create!(runner_type: 1, public_projects_minutes_cost_factor: 0) }
  let!(:shared_2) { runners.create!(runner_type: 1, public_projects_minutes_cost_factor: 0) }
  let!(:shared_3) { runners.create!(runner_type: 1, public_projects_minutes_cost_factor: 1) }
  let!(:group_1)  { runners.create!(runner_type: 2, public_projects_minutes_cost_factor: 0) }

  describe '#up' do
    context 'when on SaaS' do
      before do
        allow(Gitlab).to receive(:com?).and_return(true)
      end

      it 'updates the cost factor from 0 only for shared runners', :aggregate_failures do
        migrate!

        expect(shared_1.reload.public_projects_minutes_cost_factor).to eq(0.008)
        expect(shared_2.reload.public_projects_minutes_cost_factor).to eq(0.008)
        expect(shared_3.reload.public_projects_minutes_cost_factor).to eq(1)
        expect(group_1.reload.public_projects_minutes_cost_factor).to eq(0)
      end
    end

    context 'when on self-managed', :aggregate_failures do
      it 'skips the migration' do
        migrate!

        expect(shared_1.public_projects_minutes_cost_factor).to eq(0)
        expect(shared_2.public_projects_minutes_cost_factor).to eq(0)
        expect(shared_3.public_projects_minutes_cost_factor).to eq(1)
        expect(group_1.public_projects_minutes_cost_factor).to eq(0)
      end
    end
  end

  describe '#down' do
    context 'when on SaaS' do
      before do
        allow(Gitlab).to receive(:com?).and_return(true)
      end

      it 'resets the cost factor to 0 only for shared runners that were updated', :aggregate_failures do
        migrate!
        schema_migrate_down!

        expect(shared_1.public_projects_minutes_cost_factor).to eq(0)
        expect(shared_2.public_projects_minutes_cost_factor).to eq(0)
        expect(shared_3.public_projects_minutes_cost_factor).to eq(1)
        expect(group_1.public_projects_minutes_cost_factor).to eq(0)
      end
    end
  end
end