blob: 780307360939f2310a33cd1ffac53bf999cd76f5 (
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
60
61
62
63
64
65
66
67
68
|
# frozen_string_literal: true
require 'spec_helper'
require_migration!
RSpec.describe ChangePublicProjectsCostFactor, :migration do
# This is a workaround to force the migration to run against the
# `gitlab_ci` schema. Otherwise it only runs against `gitlab_main`.
around do |example| # rubocop: disable Style/MultilineIfModifier
with_reestablished_active_record_base do
reconfigure_db_connection(name: :ci)
example.run
end
end if Gitlab::Database.has_config?(:ci)
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
|