Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/requests/api/ci/runner/jobs_request_post_spec.rb')
-rw-r--r--spec/requests/api/ci/runner/jobs_request_post_spec.rb58
1 files changed, 53 insertions, 5 deletions
diff --git a/spec/requests/api/ci/runner/jobs_request_post_spec.rb b/spec/requests/api/ci/runner/jobs_request_post_spec.rb
index 74d8e3f7ae8..aced094e219 100644
--- a/spec/requests/api/ci/runner/jobs_request_post_spec.rb
+++ b/spec/requests/api/ci/runner/jobs_request_post_spec.rb
@@ -17,9 +17,8 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do
end
describe '/api/v4/jobs' do
- let(:root_namespace) { create(:namespace) }
- let(:namespace) { create(:namespace, parent: root_namespace) }
- let(:project) { create(:project, namespace: namespace, shared_runners_enabled: false) }
+ let(:group) { create(:group, :nested) }
+ let(:project) { create(:project, namespace: group, shared_runners_enabled: false) }
let(:pipeline) { create(:ci_pipeline, project: project, ref: 'master') }
let(:runner) { create(:ci_runner, :project, projects: [project]) }
let(:user) { create(:user) }
@@ -198,7 +197,12 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do
'when' => 'on_success' }]
end
- let(:expected_features) { { 'trace_sections' => true } }
+ let(:expected_features) do
+ {
+ 'trace_sections' => true,
+ 'failure_reasons' => include('script_failure')
+ }
+ end
it 'picks a job' do
request_job info: { platform: :darwin }
@@ -220,7 +224,7 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do
expect(json_response['artifacts']).to eq(expected_artifacts)
expect(json_response['cache']).to eq(expected_cache)
expect(json_response['variables']).to include(*expected_variables)
- expect(json_response['features']).to eq(expected_features)
+ expect(json_response['features']).to match(expected_features)
end
it 'creates persistent ref' do
@@ -793,6 +797,50 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do
end
end
+ describe 'setting the application context' do
+ subject { request_job }
+
+ context 'when triggered by a user' do
+ let(:job) { create(:ci_build, user: user, project: project) }
+
+ subject { request_job(id: job.id) }
+
+ it_behaves_like 'storing arguments in the application context' do
+ let(:expected_params) { { user: user.username, project: project.full_path, client_id: "user/#{user.id}" } }
+ end
+
+ it_behaves_like 'not executing any extra queries for the application context', 3 do
+ # Extra queries: User, Project, Route
+ let(:subject_proc) { proc { request_job(id: job.id) } }
+ end
+ end
+
+ context 'when the runner is of project type' do
+ it_behaves_like 'storing arguments in the application context' do
+ let(:expected_params) { { project: project.full_path, client_id: "runner/#{runner.id}" } }
+ end
+
+ it_behaves_like 'not executing any extra queries for the application context', 2 do
+ # Extra queries: Project, Route
+ let(:subject_proc) { proc { request_job } }
+ end
+ end
+
+ context 'when the runner is of group type' do
+ let(:group) { create(:group) }
+ let(:runner) { create(:ci_runner, :group, groups: [group]) }
+
+ it_behaves_like 'storing arguments in the application context' do
+ let(:expected_params) { { root_namespace: group.full_path_components.first, client_id: "runner/#{runner.id}" } }
+ end
+
+ it_behaves_like 'not executing any extra queries for the application context', 2 do
+ # Extra queries: Group, Route
+ let(:subject_proc) { proc { request_job } }
+ end
+ end
+ end
+
def request_job(token = runner.token, **params)
new_params = params.merge(token: token, last_update: last_update)
post api('/jobs/request'), params: new_params.to_json, headers: { 'User-Agent' => user_agent, 'Content-Type': 'application/json' }