diff options
Diffstat (limited to 'spec/requests/api/graphql/ci/runner_spec.rb')
-rw-r--r-- | spec/requests/api/graphql/ci/runner_spec.rb | 103 |
1 files changed, 94 insertions, 9 deletions
diff --git a/spec/requests/api/graphql/ci/runner_spec.rb b/spec/requests/api/graphql/ci/runner_spec.rb index 8c919b48849..fa16b9e1ddd 100644 --- a/spec/requests/api/graphql/ci/runner_spec.rb +++ b/spec/requests/api/graphql/ci/runner_spec.rb @@ -25,6 +25,8 @@ RSpec.describe 'Query.runner(id)' do access_level: 0, tag_list: %w[tag1 tag2], run_untagged: true, executor_type: :shell) end + let_it_be(:active_project_runner) { create(:ci_runner, :project) } + def get_runner(id) case id when :active_instance_runner @@ -33,6 +35,8 @@ RSpec.describe 'Query.runner(id)' do inactive_instance_runner when :active_group_runner active_group_runner + when :active_project_runner + active_project_runner end end @@ -55,7 +59,7 @@ RSpec.describe 'Query.runner(id)' do runner = get_runner(runner_id) expect(runner_data).to match a_hash_including( - 'id' => "gid://gitlab/Ci::Runner/#{runner.id}", + 'id' => runner.to_global_id.to_s, 'description' => runner.description, 'createdAt' => runner.created_at&.iso8601, 'contactedAt' => runner.contacted_at&.iso8601, @@ -64,6 +68,7 @@ RSpec.describe 'Query.runner(id)' do 'revision' => runner.revision, 'locked' => false, 'active' => runner.active, + 'paused' => !runner.active, 'status' => runner.status('14.5').to_s.upcase, 'maximumTimeout' => runner.maximum_timeout, 'accessLevel' => runner.access_level.to_s.upcase, @@ -72,6 +77,7 @@ RSpec.describe 'Query.runner(id)' do 'runnerType' => runner.instance_type? ? 'INSTANCE_TYPE' : 'PROJECT_TYPE', 'executorName' => runner.executor_type&.dasherize, 'jobCount' => 0, + 'jobs' => a_hash_including("count" => 0, "nodes" => [], "pageInfo" => anything), 'projectCount' => nil, 'adminUrl' => "http://localhost/admin/runners/#{runner.id}", 'userPermissions' => { @@ -103,7 +109,7 @@ RSpec.describe 'Query.runner(id)' do runner = get_runner(runner_id) expect(runner_data).to match a_hash_including( - 'id' => "gid://gitlab/Ci::Runner/#{runner.id}", + 'id' => runner.to_global_id.to_s, 'adminUrl' => nil ) expect(runner_data['tagList']).to match_array runner.tag_list @@ -179,7 +185,7 @@ RSpec.describe 'Query.runner(id)' do runner_data = graphql_data_at(:runner) expect(runner_data).to match a_hash_including( - 'id' => "gid://gitlab/Ci::Runner/#{project_runner.id}", + 'id' => project_runner.to_global_id.to_s, 'locked' => is_locked ) end @@ -216,13 +222,36 @@ RSpec.describe 'Query.runner(id)' do a_hash_including( 'webUrl' => "http://localhost/groups/#{group.full_path}/-/runners/#{active_group_runner.id}", 'node' => { - 'id' => "gid://gitlab/Ci::Runner/#{active_group_runner.id}" + 'id' => active_group_runner.to_global_id.to_s } ) ] end end + describe 'for group runner request' do + let(:query) do + %( + query { + runner(id: "#{active_group_runner.to_global_id}") { + groups { + nodes { + id + } + } + } + } + ) + end + + it 'retrieves groups field with expected value' do + post_graphql(query, current_user: user) + + runner_data = graphql_data_at(:runner, :groups) + expect(runner_data).to eq 'nodes' => [{ 'id' => group.to_global_id.to_s }] + end + end + describe 'for runner with status' do let_it_be(:stale_runner) { create(:ci_runner, description: 'Stale runner 1', created_at: 3.months.ago) } let_it_be(:never_contacted_instance_runner) { create(:ci_runner, description: 'Missing runner 1', created_at: 1.month.ago, contacted_at: nil) } @@ -279,21 +308,51 @@ RSpec.describe 'Query.runner(id)' do let!(:job) { create(:ci_build, runner: project_runner1) } - context 'requesting project and job counts' do + context 'requesting projects and counts for projects and jobs' do + let(:jobs_fragment) do + %( + jobs { + count + nodes { + id + status + } + } + ) + end + let(:query) do %( query { projectRunner1: runner(id: "#{project_runner1.to_global_id}") { projectCount jobCount + #{jobs_fragment} + projects { + nodes { + id + } + } } projectRunner2: runner(id: "#{project_runner2.to_global_id}") { projectCount jobCount + #{jobs_fragment} + projects { + nodes { + id + } + } } activeInstanceRunner: runner(id: "#{active_instance_runner.to_global_id}") { projectCount jobCount + #{jobs_fragment} + projects { + nodes { + id + } + } } } ) @@ -312,13 +371,29 @@ RSpec.describe 'Query.runner(id)' do expect(runner1_data).to match a_hash_including( 'jobCount' => 1, - 'projectCount' => 2) + 'jobs' => a_hash_including( + "count" => 1, + "nodes" => [{ "id" => job.to_global_id.to_s, "status" => job.status.upcase }] + ), + 'projectCount' => 2, + 'projects' => { + 'nodes' => [ + { 'id' => project1.to_global_id.to_s }, + { 'id' => project2.to_global_id.to_s } + ] + }) expect(runner2_data).to match a_hash_including( 'jobCount' => 0, - 'projectCount' => 0) + 'jobs' => nil, # returning jobs not allowed for more than 1 runner (see RunnerJobsResolver) + 'projectCount' => 0, + 'projects' => { + 'nodes' => [] + }) expect(runner3_data).to match a_hash_including( 'jobCount' => 0, - 'projectCount' => nil) + 'jobs' => nil, # returning jobs not allowed for more than 1 runner (see RunnerJobsResolver) + 'projectCount' => nil, + 'projects' => nil) end end end @@ -326,7 +401,17 @@ RSpec.describe 'Query.runner(id)' do describe 'by regular user' do let(:user) { create(:user) } - it_behaves_like 'retrieval by unauthorized user', :active_instance_runner + context 'on instance runner' do + it_behaves_like 'retrieval by unauthorized user', :active_instance_runner + end + + context 'on group runner' do + it_behaves_like 'retrieval by unauthorized user', :active_group_runner + end + + context 'on project runner' do + it_behaves_like 'retrieval by unauthorized user', :active_project_runner + end end describe 'by non-admin user' do |