blob: 8e9fc4e301277b34bd05b7965dedc3a962f0786e (
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ::Ci::Runners::BulkDeleteRunnersService, '#execute' do
subject(:execute) { described_class.new(**service_args).execute }
let(:service_args) { { runners: runners_arg } }
let(:runners_arg) {}
context 'with runners specified' do
let!(:instance_runner) { create(:ci_runner) }
let!(:group_runner) { create(:ci_runner, :group) }
let!(:project_runner) { create(:ci_runner, :project) }
shared_examples 'a service deleting runners in bulk' do
it 'destroys runners', :aggregate_failures do
expect { subject }.to change { Ci::Runner.count }.by(-2)
is_expected.to be_success
expect(execute.payload).to eq({ deleted_count: 2, deleted_ids: [instance_runner.id, project_runner.id] })
expect(instance_runner[:errors]).to be_nil
expect(project_runner[:errors]).to be_nil
expect { project_runner.runner_projects.first.reload }.to raise_error(ActiveRecord::RecordNotFound)
expect { group_runner.reload }.not_to raise_error
expect { instance_runner.reload }.to raise_error(ActiveRecord::RecordNotFound)
expect { project_runner.reload }.to raise_error(ActiveRecord::RecordNotFound)
end
context 'with some runners already deleted' do
before do
instance_runner.destroy!
end
let(:runners_arg) { [instance_runner.id, project_runner.id] }
it 'destroys runners and returns only deleted runners', :aggregate_failures do
expect { subject }.to change { Ci::Runner.count }.by(-1)
is_expected.to be_success
expect(execute.payload).to eq({ deleted_count: 1, deleted_ids: [project_runner.id] })
expect(instance_runner[:errors]).to be_nil
expect(project_runner[:errors]).to be_nil
expect { project_runner.reload }.to raise_error(ActiveRecord::RecordNotFound)
end
end
context 'with too many runners specified' do
before do
stub_const("#{described_class}::RUNNER_LIMIT", 1)
end
it 'deletes only first RUNNER_LIMIT runners' do
expect { subject }.to change { Ci::Runner.count }.by(-1)
is_expected.to be_success
expect(execute.payload).to eq({ deleted_count: 1, deleted_ids: [instance_runner.id] })
end
end
end
context 'with runners specified as relation' do
let(:runners_arg) { Ci::Runner.not_group_type }
include_examples 'a service deleting runners in bulk'
end
context 'with runners specified as array of IDs' do
let(:runners_arg) { Ci::Runner.not_group_type.ids }
include_examples 'a service deleting runners in bulk'
end
context 'with no arguments specified' do
let(:runners_arg) { nil }
it 'returns 0 deleted runners' do
is_expected.to be_success
expect(execute.payload).to eq({ deleted_count: 0, deleted_ids: [] })
end
end
end
end
|