diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-06 00:09:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-06 00:09:02 +0300 |
commit | 76623c12c136f43f24c3966ed4b469e2c0b434b7 (patch) | |
tree | 7c5ec884c25e03e4fea131a4d112a9d0ccfd59b8 /spec/requests/api | |
parent | b042382bbf5a4977c5b5c6b0a9a33f4e8ca8d16d (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/requests/api')
-rw-r--r-- | spec/requests/api/projects_spec.rb | 2 | ||||
-rw-r--r-- | spec/requests/api/releases_spec.rb | 8 | ||||
-rw-r--r-- | spec/requests/api/runner_spec.rb | 55 |
3 files changed, 56 insertions, 9 deletions
diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index 2b9ec4319f5..97b61b44856 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -6,8 +6,6 @@ shared_examples 'languages and percentages JSON response' do let(:expected_languages) { project.repository.languages.map { |language| language.values_at(:label, :value)}.to_h } before do - allow(DetectRepositoryLanguagesWorker).to receive(:perform_async).and_call_original - allow(project.repository).to receive(:languages).and_return( [{ value: 66.69, label: "Ruby", color: "#701516", highlight: "#701516" }, { value: 22.98, label: "JavaScript", color: "#f1e05a", highlight: "#f1e05a" }, diff --git a/spec/requests/api/releases_spec.rb b/spec/requests/api/releases_spec.rb index e0f88caeab6..12fd9f431e5 100644 --- a/spec/requests/api/releases_spec.rb +++ b/spec/requests/api/releases_spec.rb @@ -61,9 +61,9 @@ describe API::Releases do it 'returns rendered helper paths' do get api("/projects/#{project.id}/releases", maintainer) - expect(json_response.first['commit_path']).to eq("/#{release_2.project.full_path}/commit/#{release_2.commit.id}") + expect(json_response.first['commit_path']).to eq("/#{release_2.project.full_path}/-/commit/#{release_2.commit.id}") expect(json_response.first['tag_path']).to eq("/#{release_2.project.full_path}/-/tags/#{release_2.tag}") - expect(json_response.second['commit_path']).to eq("/#{release_1.project.full_path}/commit/#{release_1.commit.id}") + expect(json_response.second['commit_path']).to eq("/#{release_1.project.full_path}/-/commit/#{release_1.commit.id}") expect(json_response.second['tag_path']).to eq("/#{release_1.project.full_path}/-/tags/#{release_1.tag}") end @@ -164,7 +164,7 @@ describe API::Releases do expect(response).to match_response_schema('public_api/v4/releases') expect(json_response.first['assets']['count']).to eq(release.links.count + release.sources.count) - expect(json_response.first['commit_path']).to eq("/#{release.project.full_path}/commit/#{release.commit.id}") + expect(json_response.first['commit_path']).to eq("/#{release.project.full_path}/-/commit/#{release.commit.id}") expect(json_response.first['tag_path']).to eq("/#{release.project.full_path}/-/tags/#{release.tag}") end end @@ -214,7 +214,7 @@ describe API::Releases do expect(json_response['author']['name']).to eq(maintainer.name) expect(json_response['commit']['id']).to eq(commit.id) expect(json_response['assets']['count']).to eq(4) - expect(json_response['commit_path']).to eq("/#{release.project.full_path}/commit/#{release.commit.id}") + expect(json_response['commit_path']).to eq("/#{release.project.full_path}/-/commit/#{release.commit.id}") expect(json_response['tag_path']).to eq("/#{release.project.full_path}/-/tags/#{release.tag}") end diff --git a/spec/requests/api/runner_spec.rb b/spec/requests/api/runner_spec.rb index 23ce17b14fc..eb9db7ff6b7 100644 --- a/spec/requests/api/runner_spec.rb +++ b/spec/requests/api/runner_spec.rb @@ -311,11 +311,33 @@ describe API::Runner, :clean_gitlab_redis_shared_state do end describe '/api/v4/jobs' do + shared_examples 'application context metadata' do |api_route| + it 'contains correct context metadata' do + # Avoids popping the context from the thread so we can + # check its content after the request. + allow(Labkit::Context).to receive(:pop) + + send_request + + Labkit::Context.with_context do |context| + expected_context = { + 'meta.caller_id' => api_route, + 'meta.user' => job.user.username, + 'meta.project' => job.project.full_path, + 'meta.root_namespace' => job.project.full_path_components.first + } + + expect(context.to_h).to include(expected_context) + end + end + end + let(:root_namespace) { create(:namespace) } let(:namespace) { create(:namespace, parent: root_namespace) } let(:project) { create(:project, namespace: namespace, 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) } let(:job) do create(:ci_build, :artifacts, :extended_options, pipeline: pipeline, name: 'spinach', stage: 'test', stage_idx: 0) @@ -984,12 +1006,18 @@ describe API::Runner, :clean_gitlab_redis_shared_state do end describe 'PUT /api/v4/jobs/:id' do - let(:job) { create(:ci_build, :pending, :trace_live, pipeline: pipeline, runner_id: runner.id) } + let(:job) do + create(:ci_build, :pending, :trace_live, pipeline: pipeline, project: project, user: user, runner_id: runner.id) + end before do job.run! end + it_behaves_like 'application context metadata', '/api/:version/jobs/:id' do + let(:send_request) { update_job(state: 'success') } + end + context 'when status is given' do it 'mark job as succeeded' do update_job(state: 'success') @@ -1139,7 +1167,10 @@ describe API::Runner, :clean_gitlab_redis_shared_state do end describe 'PATCH /api/v4/jobs/:id/trace' do - let(:job) { create(:ci_build, :running, :trace_live, runner_id: runner.id, pipeline: pipeline) } + let(:job) do + create(:ci_build, :running, :trace_live, + project: project, user: user, runner_id: runner.id, pipeline: pipeline) + end let(:headers) { { API::Helpers::Runner::JOB_TOKEN_HEADER => job.token, 'Content-Type' => 'text/plain' } } let(:headers_with_range) { headers.merge({ 'Content-Range' => '11-20' }) } let(:update_interval) { 10.seconds.to_i } @@ -1148,6 +1179,10 @@ describe API::Runner, :clean_gitlab_redis_shared_state do initial_patch_the_trace end + it_behaves_like 'application context metadata', '/api/:version/jobs/:id/trace' do + let(:send_request) { patch_the_trace } + end + context 'when request is valid' do it 'gets correct response' do expect(response.status).to eq 202 @@ -1399,7 +1434,7 @@ describe API::Runner, :clean_gitlab_redis_shared_state do end describe 'artifacts' do - let(:job) { create(:ci_build, :pending, pipeline: pipeline, runner_id: runner.id) } + let(:job) { create(:ci_build, :pending, user: user, project: project, pipeline: pipeline, runner_id: runner.id) } let(:jwt_token) { JWT.encode({ 'iss' => 'gitlab-workhorse' }, Gitlab::Workhorse.secret, 'HS256') } let(:headers) { { 'GitLab-Workhorse' => '1.0', Gitlab::Workhorse::INTERNAL_API_REQUEST_HEADER => jwt_token } } let(:headers_with_token) { headers.merge(API::Helpers::Runner::JOB_TOKEN_HEADER => job.token) } @@ -1418,6 +1453,10 @@ describe API::Runner, :clean_gitlab_redis_shared_state do authorize_artifacts_with_token_in_params end + it_behaves_like 'application context metadata', '/api/:version/jobs/:id/artifacts/authorize' do + let(:send_request) { subject } + end + shared_examples 'authorizes local file' do it 'succeeds' do subject @@ -1571,6 +1610,12 @@ describe API::Runner, :clean_gitlab_redis_shared_state do end describe 'POST /api/v4/jobs/:id/artifacts' do + it_behaves_like 'application context metadata', '/api/:version/jobs/:id/artifacts' do + let(:send_request) do + upload_artifacts(file_upload, headers_with_token) + end + end + context 'when artifacts are being stored inside of tmp path' do before do # by configuring this path we allow to pass temp file from any path @@ -1971,6 +2016,10 @@ describe API::Runner, :clean_gitlab_redis_shared_state do describe 'GET /api/v4/jobs/:id/artifacts' do let(:token) { job.token } + it_behaves_like 'application context metadata', '/api/:version/jobs/:id/artifacts' do + let(:send_request) { download_artifact } + end + context 'when job has artifacts' do let(:job) { create(:ci_build) } let(:store) { JobArtifactUploader::Store::LOCAL } |