debian-mirror-gitlab/spec/graphql/resolvers/ci/runners_resolver_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

162 lines
5 KiB
Ruby
Raw Normal View History

2021-06-08 01:23:25 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-03-04 22:38:38 +05:30
RSpec.describe Resolvers::Ci::RunnersResolver, feature_category: :runner_fleet do
2021-06-08 01:23:25 +05:30
include GraphqlHelpers
describe '#resolve' do
2021-11-11 11:23:49 +05:30
let(:obj) { nil }
let(:args) { {} }
2021-06-08 01:23:25 +05:30
2022-07-23 23:45:48 +05:30
subject do
resolve(described_class, obj: obj, ctx: { current_user: user }, args: args,
2022-10-11 01:57:18 +05:30
arg_style: :internal)
2022-07-23 23:45:48 +05:30
end
2021-06-08 01:23:25 +05:30
2021-11-11 11:23:49 +05:30
include_context 'runners resolver setup'
2021-06-08 01:23:25 +05:30
2021-11-11 11:23:49 +05:30
# First, we can do a couple of basic real tests to verify common cases. That ensures that the code works.
context 'when user cannot see runners' do
let(:user) { build(:user) }
2021-06-08 01:23:25 +05:30
2021-11-11 11:23:49 +05:30
it 'returns no runners' do
expect(subject.items.to_a).to eq([])
2021-06-08 01:23:25 +05:30
end
end
2021-11-11 11:23:49 +05:30
context 'when user can see runners' do
let(:obj) { nil }
2021-06-08 01:23:25 +05:30
2023-03-04 22:38:38 +05:30
context 'when admin mode setting is disabled', :do_not_mock_admin_mode_setting do
it 'returns all the runners' do
expect(subject.items.to_a).to contain_exactly(inactive_project_runner, offline_project_runner, group_runner, subgroup_runner, instance_runner)
end
end
context 'when admin mode setting is enabled' do
context 'when in admin mode', :enable_admin_mode do
it 'returns all the runners' do
expect(subject.items.to_a).to contain_exactly(inactive_project_runner, offline_project_runner, group_runner, subgroup_runner, instance_runner)
end
end
context 'when not in admin mode' do
it 'returns no runners' do
expect(subject.items.to_a).to eq([])
end
end
2021-06-08 01:23:25 +05:30
end
end
2021-11-11 11:23:49 +05:30
# Then, we can check specific edge cases for this resolver
context 'with obj not set to nil' do
let(:obj) { build(:project) }
2021-06-08 01:23:25 +05:30
2021-11-11 11:23:49 +05:30
it 'raises an error' do
expect { subject }.to raise_error(a_string_including('Unexpected parent type'))
2021-06-08 01:23:25 +05:30
end
end
2021-09-04 01:27:46 +05:30
2021-11-11 11:23:49 +05:30
# Here we have a mocked part. We assume that all possible edge cases are covered in RunnersFinder spec. So we don't need to test them twice.
# Only thing we can do is to verify that args from the resolver is correctly transformed to params of the Finder and we return the Finder's result back.
describe 'Allowed query arguments' do
let(:finder) { instance_double(::Ci::RunnersFinder) }
2022-04-04 11:22:00 +05:30
context 'with active filter' do
let(:args) do
{
active: true,
status: 'active',
2022-08-13 15:12:31 +05:30
upgrade_status: 'recommended',
2022-04-04 11:22:00 +05:30
type: :instance_type,
tag_list: ['active_runner'],
search: 'abc',
sort: :contacted_asc
}
end
let(:expected_params) do
{
active: true,
status_status: 'active',
2022-08-13 15:12:31 +05:30
upgrade_status: 'recommended',
2022-04-04 11:22:00 +05:30
type_type: :instance_type,
tag_name: ['active_runner'],
2023-05-27 22:25:52 +05:30
preload: false,
2022-04-04 11:22:00 +05:30
search: 'abc',
sort: 'contacted_asc'
}
end
it 'calls RunnersFinder with expected arguments' do
expect(::Ci::RunnersFinder).to receive(:new).with(current_user: user, params: expected_params).once.and_return(finder)
allow(finder).to receive(:execute).once.and_return([:execute_return_value])
expect(subject.items.to_a).to eq([:execute_return_value])
end
end
context 'with both active and paused filter' do
let(:args) do
{
active: true,
paused: true
}
end
let(:expected_params) do
{
active: false,
2023-05-27 22:25:52 +05:30
preload: false
2022-04-04 11:22:00 +05:30
}
end
it 'calls RunnersFinder with expected arguments' do
expect(::Ci::RunnersFinder).to receive(:new).with(current_user: user, params: expected_params).once.and_return(finder)
allow(finder).to receive(:execute).once.and_return([:execute_return_value])
expect(subject.items.to_a).to eq([:execute_return_value])
end
2021-11-11 11:23:49 +05:30
end
2022-04-04 11:22:00 +05:30
context 'with paused filter' do
let(:args) do
{ paused: true }
end
let(:expected_params) do
{
active: false,
2023-05-27 22:25:52 +05:30
preload: false
2022-04-04 11:22:00 +05:30
}
end
it 'calls RunnersFinder with expected arguments' do
expect(::Ci::RunnersFinder).to receive(:new).with(current_user: user, params: expected_params).once.and_return(finder)
allow(finder).to receive(:execute).once.and_return([:execute_return_value])
expect(subject.items.to_a).to eq([:execute_return_value])
end
2021-11-11 11:23:49 +05:30
end
2022-04-04 11:22:00 +05:30
context 'with neither paused or active filters' do
let(:args) do
{}
end
let(:expected_params) do
2023-05-27 22:25:52 +05:30
{ preload: false }
2022-04-04 11:22:00 +05:30
end
it 'calls RunnersFinder with expected arguments' do
expect(::Ci::RunnersFinder).to receive(:new).with(current_user: user, params: expected_params).once.and_return(finder)
allow(finder).to receive(:execute).once.and_return([:execute_return_value])
2021-11-11 11:23:49 +05:30
2022-04-04 11:22:00 +05:30
expect(subject.items.to_a).to eq([:execute_return_value])
end
2021-09-04 01:27:46 +05:30
end
end
2021-06-08 01:23:25 +05:30
end
end