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:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-05-15 21:07:52 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-05-15 21:07:52 +0300
commit31a340adabe75f8b02cca462ab8aa857ff62f772 (patch)
tree5540138a26430ec1ad33e0b76ff44f031729d945 /spec/controllers
parent8bd8f7d169c6ab97cdd6b0bb74e898258a6ba1f1 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/controllers')
-rw-r--r--spec/controllers/application_controller_spec.rb26
-rw-r--r--spec/controllers/projects/alert_management_controller_spec.rb30
-rw-r--r--spec/controllers/projects/artifacts_controller_spec.rb40
3 files changed, 67 insertions, 29 deletions
diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb
index 1935d05b470..b406c184b88 100644
--- a/spec/controllers/application_controller_spec.rb
+++ b/spec/controllers/application_controller_spec.rb
@@ -530,6 +530,14 @@ describe ApplicationController do
expect(controller.last_payload).to include('correlation_id' => 'new-id')
end
+
+ it 'adds context metadata to the payload' do
+ sign_in user
+
+ get :index
+
+ expect(controller.last_payload[:metadata]).to include('meta.user' => user.username)
+ end
end
describe '#access_denied' do
@@ -891,7 +899,7 @@ describe ApplicationController do
end
it 'sets the group if it was available' do
- group = build(:group)
+ group = build_stubbed(:group)
controller.instance_variable_set(:@group, group)
get :index, format: :json
@@ -900,7 +908,7 @@ describe ApplicationController do
end
it 'sets the project if one was available' do
- project = build(:project)
+ project = build_stubbed(:project)
controller.instance_variable_set(:@project, project)
get :index, format: :json
@@ -913,6 +921,20 @@ describe ApplicationController do
expect(json_response['meta.caller_id']).to eq('AnonymousController#index')
end
+
+ it 'assigns the context to a variable for logging' do
+ get :index, format: :json
+
+ expect(assigns(:current_context)).to include('meta.user' => user.username)
+ end
+
+ it 'assigns the context when the action caused an error' do
+ allow(controller).to receive(:index) { raise 'Broken' }
+
+ expect { get :index, format: :json }.to raise_error('Broken')
+
+ expect(assigns(:current_context)).to include('meta.user' => user.username)
+ end
end
describe '#current_user' do
diff --git a/spec/controllers/projects/alert_management_controller_spec.rb b/spec/controllers/projects/alert_management_controller_spec.rb
index 8fc2319ff88..b84376db33d 100644
--- a/spec/controllers/projects/alert_management_controller_spec.rb
+++ b/spec/controllers/projects/alert_management_controller_spec.rb
@@ -32,35 +32,17 @@ describe Projects::AlertManagementController do
end
describe 'GET #details' do
- context 'when alert_management_detail is enabled' do
- before do
- stub_feature_flags(alert_management_detail: true)
- end
-
- it 'shows the page' do
- get :details, params: { namespace_id: project.namespace, project_id: project, id: id }
-
- expect(response).to have_gitlab_http_status(:ok)
- end
-
- context 'when user is unauthorized' do
- let(:role) { :reporter }
-
- it 'shows 404' do
- get :index, params: { namespace_id: project.namespace, project_id: project }
+ it 'shows the page' do
+ get :details, params: { namespace_id: project.namespace, project_id: project, id: id }
- expect(response).to have_gitlab_http_status(:not_found)
- end
- end
+ expect(response).to have_gitlab_http_status(:ok)
end
- context 'when alert_management_detail is disabled' do
- before do
- stub_feature_flags(alert_management_detail: false)
- end
+ context 'when user is unauthorized' do
+ let(:role) { :reporter }
it 'shows 404' do
- get :details, params: { namespace_id: project.namespace, project_id: project, id: id }
+ get :index, params: { namespace_id: project.namespace, project_id: project }
expect(response).to have_gitlab_http_status(:not_found)
end
diff --git a/spec/controllers/projects/artifacts_controller_spec.rb b/spec/controllers/projects/artifacts_controller_spec.rb
index aa3371f7ddf..be616b566dd 100644
--- a/spec/controllers/projects/artifacts_controller_spec.rb
+++ b/spec/controllers/projects/artifacts_controller_spec.rb
@@ -308,10 +308,13 @@ describe Projects::ArtifactsController do
end
describe 'GET raw' do
- subject { get(:raw, params: { namespace_id: project.namespace, project_id: project, job_id: job, path: path }) }
+ let(:query_params) { { namespace_id: project.namespace, project_id: project, job_id: job, path: path } }
+
+ subject { get(:raw, params: query_params) }
context 'when the file exists' do
let(:path) { 'ci_artifacts.txt' }
+ let(:archive_matcher) { /build_artifacts.zip(\?[^?]+)?$/ }
shared_examples 'a valid file' do
it 'serves the file using workhorse' do
@@ -323,8 +326,8 @@ describe Projects::ArtifactsController do
expect(params.keys).to eq(%w(Archive Entry))
expect(params['Archive']).to start_with(archive_path)
# On object storage, the URL can end with a query string
- expect(params['Archive']).to match(/build_artifacts.zip(\?[^?]+)?$/)
- expect(params['Entry']).to eq(Base64.encode64('ci_artifacts.txt'))
+ expect(params['Archive']).to match(archive_matcher)
+ expect(params['Entry']).to eq(Base64.encode64(path))
end
def send_data
@@ -359,6 +362,37 @@ describe Projects::ArtifactsController do
let(:archive_path) { 'https://' }
end
end
+
+ context 'fetching an artifact of different type' do
+ before do
+ job.job_artifacts.each(&:destroy)
+ end
+
+ context 'when the artifact is zip' do
+ let!(:artifact) { create(:ci_job_artifact, :lsif, job: job, file_path: Rails.root.join("spec/fixtures/#{file_name}")) }
+ let(:path) { 'lsif/main.go.json' }
+ let(:file_name) { 'lsif.json.zip' }
+ let(:archive_matcher) { file_name }
+ let(:query_params) { super().merge(file_type: :lsif, path: path) }
+
+ it_behaves_like 'a valid file' do
+ let(:store) { ObjectStorage::Store::LOCAL }
+ let(:archive_path) { JobArtifactUploader.root }
+ end
+ end
+
+ context 'when the artifact is not zip' do
+ let(:query_params) { super().merge(file_type: :junit, path: '') }
+
+ it 'responds with not found' do
+ create(:ci_job_artifact, :junit, job: job)
+
+ subject
+
+ expect(response).to have_gitlab_http_status(:not_found)
+ end
+ end
+ end
end
end