diff options
Diffstat (limited to 'spec/models/project_spec.rb')
-rw-r--r-- | spec/models/project_spec.rb | 136 |
1 files changed, 129 insertions, 7 deletions
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 01132e18745..b964a18e148 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -1629,6 +1629,8 @@ RSpec.describe Project, factory_default: :keep do end describe '#any_active_runners?' do + subject { project.any_active_runners? } + context 'shared runners' do let(:project) { create(:project, shared_runners_enabled: shared_runners_enabled) } let(:specific_runner) { create(:ci_runner, :project, projects: [project]) } @@ -1638,19 +1640,19 @@ RSpec.describe Project, factory_default: :keep do let(:shared_runners_enabled) { false } it 'has no runners available' do - expect(project.any_active_runners?).to be_falsey + is_expected.to be_falsey end it 'has a specific runner' do specific_runner - expect(project.any_active_runners?).to be_truthy + is_expected.to be_truthy end it 'has a shared runner, but they are prohibited to use' do shared_runner - expect(project.any_active_runners?).to be_falsey + is_expected.to be_falsey end it 'checks the presence of specific runner' do @@ -1672,7 +1674,7 @@ RSpec.describe Project, factory_default: :keep do it 'has a shared runner' do shared_runner - expect(project.any_active_runners?).to be_truthy + is_expected.to be_truthy end it 'checks the presence of shared runner' do @@ -1698,13 +1700,13 @@ RSpec.describe Project, factory_default: :keep do let(:group_runners_enabled) { false } it 'has no runners available' do - expect(project.any_active_runners?).to be_falsey + is_expected.to be_falsey end it 'has a group runner, but they are prohibited to use' do group_runner - expect(project.any_active_runners?).to be_falsey + is_expected.to be_falsey end end @@ -1714,7 +1716,7 @@ RSpec.describe Project, factory_default: :keep do it 'has a group runner' do group_runner - expect(project.any_active_runners?).to be_truthy + is_expected.to be_truthy end it 'checks the presence of group runner' do @@ -1732,6 +1734,126 @@ RSpec.describe Project, factory_default: :keep do end end + describe '#any_online_runners?' do + subject { project.any_online_runners? } + + context 'shared runners' do + let(:project) { create(:project, shared_runners_enabled: shared_runners_enabled) } + let(:specific_runner) { create(:ci_runner, :project, :online, projects: [project]) } + let(:shared_runner) { create(:ci_runner, :instance, :online) } + let(:offline_runner) { create(:ci_runner, :instance) } + + context 'for shared runners disabled' do + let(:shared_runners_enabled) { false } + + it 'has no runners available' do + is_expected.to be_falsey + end + + it 'has a specific runner' do + specific_runner + + is_expected.to be_truthy + end + + it 'has a shared runner, but they are prohibited to use' do + shared_runner + + is_expected.to be_falsey + end + + it 'checks the presence of specific runner' do + specific_runner + + expect(project.any_online_runners? { |runner| runner == specific_runner }).to be_truthy + end + + it 'returns false if match cannot be found' do + specific_runner + + expect(project.any_online_runners? { false }).to be_falsey + end + + it 'returns false if runner is offline' do + offline_runner + + is_expected.to be_falsey + end + end + + context 'for shared runners enabled' do + let(:shared_runners_enabled) { true } + + it 'has a shared runner' do + shared_runner + + is_expected.to be_truthy + end + + it 'checks the presence of shared runner' do + shared_runner + + expect(project.any_online_runners? { |runner| runner == shared_runner }).to be_truthy + end + + it 'returns false if match cannot be found' do + shared_runner + + expect(project.any_online_runners? { false }).to be_falsey + end + end + end + + context 'group runners' do + let(:project) { create(:project, group_runners_enabled: group_runners_enabled) } + let(:group) { create(:group, projects: [project]) } + let(:group_runner) { create(:ci_runner, :group, :online, groups: [group]) } + let(:offline_runner) { create(:ci_runner, :group, groups: [group]) } + + context 'for group runners disabled' do + let(:group_runners_enabled) { false } + + it 'has no runners available' do + is_expected.to be_falsey + end + + it 'has a group runner, but they are prohibited to use' do + group_runner + + is_expected.to be_falsey + end + end + + context 'for group runners enabled' do + let(:group_runners_enabled) { true } + + it 'has a group runner' do + group_runner + + is_expected.to be_truthy + end + + it 'has an offline group runner' do + offline_runner + + is_expected.to be_falsey + end + + it 'checks the presence of group runner' do + group_runner + + expect(project.any_online_runners? { |runner| runner == group_runner }).to be_truthy + end + + it 'returns false if match cannot be found' do + group_runner + + expect(project.any_online_runners? { false }).to be_falsey + end + end + end + end + describe '#shared_runners' do let!(:runner) { create(:ci_runner, :instance) } |