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
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-08-11 03:09:45 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-08-11 03:09:45 +0300
commit4f1e40017d9eadb0abeeb89d9690a8e5f0694fd9 (patch)
treec02455f9e9ff3092c2b4a3b00b2069d72f5d9507 /spec
parent20a18d1f9bf452c1dd2ef996bee50e34cfcb80f4 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/frontend/pipeline_wizard/components/step_spec.js4
-rw-r--r--spec/frontend/vue_shared/components/sidebar/issuable_move_dropdown_spec.js6
-rw-r--r--spec/graphql/types/project_type_spec.rb4
-rw-r--r--spec/lib/gitlab/ci/variables/builder_spec.rb3
-rw-r--r--spec/lib/gitlab/import_export/json/streaming_serializer_spec.rb48
-rw-r--r--spec/lib/gitlab/import_export/log_util_spec.rb43
-rw-r--r--spec/lib/gitlab/import_export/project/tree_saver_spec.rb2
-rw-r--r--spec/lib/gitlab/import_export/shared_spec.rb10
-rw-r--r--spec/lib/gitlab/redis/cache_spec.rb12
-rw-r--r--spec/models/ci/build_spec.rb2
-rw-r--r--spec/requests/api/deployments_spec.rb20
-rw-r--r--spec/services/projects/import_export/export_service_spec.rb23
-rw-r--r--spec/services/security/ci_configuration/sast_parser_service_spec.rb2
13 files changed, 163 insertions, 16 deletions
diff --git a/spec/frontend/pipeline_wizard/components/step_spec.js b/spec/frontend/pipeline_wizard/components/step_spec.js
index aa87b1d0b04..00b57f95ccc 100644
--- a/spec/frontend/pipeline_wizard/components/step_spec.js
+++ b/spec/frontend/pipeline_wizard/components/step_spec.js
@@ -139,7 +139,7 @@ describe('Pipeline Wizard - Step Page', () => {
await mockPrevClick();
await nextTick();
- expect(wrapper.emitted().back).toBeTruthy();
+ expect(wrapper.emitted().back).toEqual(expect.arrayContaining([]));
});
it('lets "next" event bubble upwards', async () => {
@@ -148,7 +148,7 @@ describe('Pipeline Wizard - Step Page', () => {
await mockNextClick();
await nextTick();
- expect(wrapper.emitted().next).toBeTruthy();
+ expect(wrapper.emitted().next).toEqual(expect.arrayContaining([]));
});
});
diff --git a/spec/frontend/vue_shared/components/sidebar/issuable_move_dropdown_spec.js b/spec/frontend/vue_shared/components/sidebar/issuable_move_dropdown_spec.js
index a4e3e34713c..9b1316677d7 100644
--- a/spec/frontend/vue_shared/components/sidebar/issuable_move_dropdown_spec.js
+++ b/spec/frontend/vue_shared/components/sidebar/issuable_move_dropdown_spec.js
@@ -308,7 +308,7 @@ describe('IssuableMoveDropdown', () => {
it('collapsed state element emits `toggle-collapse` event on component when clicked', () => {
wrapper.find('[data-testid="move-collapsed"]').trigger('click');
- expect(wrapper.emitted('toggle-collapse')).toBeTruthy();
+ expect(wrapper.emitted('toggle-collapse')).toHaveLength(1);
});
it('gl-dropdown component calls `fetchProjects` on `shown` event', () => {
@@ -337,7 +337,7 @@ describe('IssuableMoveDropdown', () => {
it('gl-dropdown component emits `dropdown-close` event on component from `hide` event', async () => {
findDropdownEl().vm.$emit('hide');
- expect(wrapper.emitted('dropdown-close')).toBeTruthy();
+ expect(wrapper.emitted('dropdown-close')).toHaveLength(1);
});
it('close icon in dropdown header closes the dropdown when clicked', () => {
@@ -372,7 +372,7 @@ describe('IssuableMoveDropdown', () => {
wrapper.find('[data-testid="footer"]').findComponent(GlButton).vm.$emit('click');
expect(wrapper.vm.$refs.dropdown.hide).toHaveBeenCalled();
- expect(wrapper.emitted('move-issuable')).toBeTruthy();
+ expect(wrapper.emitted('move-issuable')).toHaveLength(1);
expect(wrapper.emitted('move-issuable')[0]).toEqual([mockProjects[0]]);
});
});
diff --git a/spec/graphql/types/project_type_spec.rb b/spec/graphql/types/project_type_spec.rb
index fbb3aca3376..94e6a90e8db 100644
--- a/spec/graphql/types/project_type_spec.rb
+++ b/spec/graphql/types/project_type_spec.rb
@@ -194,8 +194,8 @@ RSpec.describe GitlabSchema.types['Project'] do
expect(secure_analyzers['type']).to eq('string')
expect(secure_analyzers['field']).to eq('SECURE_ANALYZERS_PREFIX')
expect(secure_analyzers['label']).to eq('Image prefix')
- expect(secure_analyzers['defaultValue']).to eq('$TEMPLATE_REGISTRY_HOST/security-products')
- expect(secure_analyzers['value']).to eq('$TEMPLATE_REGISTRY_HOST/security-products')
+ expect(secure_analyzers['defaultValue']).to eq('$CI_TEMPLATE_REGISTRY_HOST/security-products')
+ expect(secure_analyzers['value']).to eq('$CI_TEMPLATE_REGISTRY_HOST/security-products')
expect(secure_analyzers['size']).to eq('LARGE')
expect(secure_analyzers['options']).to be_nil
end
diff --git a/spec/lib/gitlab/ci/variables/builder_spec.rb b/spec/lib/gitlab/ci/variables/builder_spec.rb
index 8ec0846bdca..6ab2089cce8 100644
--- a/spec/lib/gitlab/ci/variables/builder_spec.rb
+++ b/spec/lib/gitlab/ci/variables/builder_spec.rb
@@ -3,6 +3,7 @@
require 'spec_helper'
RSpec.describe Gitlab::Ci::Variables::Builder do
+ include Ci::TemplateHelpers
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, :repository, namespace: group) }
let_it_be_with_reload(:pipeline) { create(:ci_pipeline, project: project) }
@@ -92,6 +93,8 @@ RSpec.describe Gitlab::Ci::Variables::Builder do
value: project.pages_url },
{ key: 'CI_API_V4_URL',
value: API::Helpers::Version.new('v4').root_url },
+ { key: 'CI_TEMPLATE_REGISTRY_HOST',
+ value: template_registry_host },
{ key: 'CI_PIPELINE_IID',
value: pipeline.iid.to_s },
{ key: 'CI_PIPELINE_SOURCE',
diff --git a/spec/lib/gitlab/import_export/json/streaming_serializer_spec.rb b/spec/lib/gitlab/import_export/json/streaming_serializer_spec.rb
index 3f73a730744..3088129a732 100644
--- a/spec/lib/gitlab/import_export/json/streaming_serializer_spec.rb
+++ b/spec/lib/gitlab/import_export/json/streaming_serializer_spec.rb
@@ -27,6 +27,7 @@ RSpec.describe Gitlab::ImportExport::Json::StreamingSerializer do
end
let(:exportable_path) { 'project' }
+ let(:logger) { Gitlab::Export::Logger.build }
let(:json_writer) { instance_double('Gitlab::ImportExport::Json::LegacyWriter') }
let(:hash) { { name: exportable.name, description: exportable.description }.stringify_keys }
let(:include) { [] }
@@ -42,7 +43,7 @@ RSpec.describe Gitlab::ImportExport::Json::StreamingSerializer do
end
subject do
- described_class.new(exportable, relations_schema, json_writer, exportable_path: exportable_path)
+ described_class.new(exportable, relations_schema, json_writer, exportable_path: exportable_path, logger: logger)
end
describe '#execute' do
@@ -73,6 +74,21 @@ RSpec.describe Gitlab::ImportExport::Json::StreamingSerializer do
subject.execute
end
+ it 'logs the relation name and the number of records to export' do
+ allow(json_writer).to receive(:write_relation_array)
+ allow(logger).to receive(:info)
+
+ subject.execute
+
+ expect(logger).to have_received(:info).with(
+ importer: 'Import/Export',
+ message: "Exporting issues relation. Number of records to export: 16",
+ project_id: exportable.id,
+ project_name: exportable.name,
+ project_path: exportable.full_path
+ )
+ end
+
context 'default relation ordering' do
it 'orders exported issues by primary key(:id)' do
expected_issues = exportable.issues.reorder(:id).map(&:to_json)
@@ -138,6 +154,21 @@ RSpec.describe Gitlab::ImportExport::Json::StreamingSerializer do
subject.execute
end
+
+ it 'logs the relation name' do
+ allow(json_writer).to receive(:write_relation)
+ allow(logger).to receive(:info)
+
+ subject.execute
+
+ expect(logger).to have_received(:info).with(
+ importer: 'Import/Export',
+ message: 'Exporting group relation',
+ project_id: exportable.id,
+ project_name: exportable.name,
+ project_path: exportable.full_path
+ )
+ end
end
context 'with array relation' do
@@ -155,6 +186,21 @@ RSpec.describe Gitlab::ImportExport::Json::StreamingSerializer do
subject.execute
end
+
+ it 'logs the relation name and the number of records to export' do
+ allow(json_writer).to receive(:write_relation_array)
+ allow(logger).to receive(:info)
+
+ subject.execute
+
+ expect(logger).to have_received(:info).with(
+ importer: 'Import/Export',
+ message: 'Exporting project_members relation. Number of records to export: 1',
+ project_id: exportable.id,
+ project_name: exportable.name,
+ project_path: exportable.full_path
+ )
+ end
end
describe 'load balancing' do
diff --git a/spec/lib/gitlab/import_export/log_util_spec.rb b/spec/lib/gitlab/import_export/log_util_spec.rb
new file mode 100644
index 00000000000..2b1a4b7bb61
--- /dev/null
+++ b/spec/lib/gitlab/import_export/log_util_spec.rb
@@ -0,0 +1,43 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::ImportExport::LogUtil do
+ describe '.exportable_to_log_payload' do
+ subject { described_class.exportable_to_log_payload(exportable) }
+
+ context 'when exportable is a group' do
+ let(:exportable) { build_stubbed(:group) }
+
+ it 'returns hash with group keys' do
+ expect(subject).to be_a(Hash)
+ expect(subject.keys).to eq(%i[group_id group_name group_path])
+ end
+ end
+
+ context 'when exportable is a project' do
+ let(:exportable) { build_stubbed(:project) }
+
+ it 'returns hash with project keys' do
+ expect(subject).to be_a(Hash)
+ expect(subject.keys).to eq(%i[project_id project_name project_path])
+ end
+ end
+
+ context 'when exportable is a new record' do
+ let(:exportable) { Project.new }
+
+ it 'returns empty hash' do
+ expect(subject).to eq({})
+ end
+ end
+
+ context 'when exportable is an unexpected type' do
+ let(:exportable) { build_stubbed(:issue) }
+
+ it 'returns empty hash' do
+ expect(subject).to eq({})
+ end
+ end
+ end
+end
diff --git a/spec/lib/gitlab/import_export/project/tree_saver_spec.rb b/spec/lib/gitlab/import_export/project/tree_saver_spec.rb
index ba781ae78b7..a248a04a5a0 100644
--- a/spec/lib/gitlab/import_export/project/tree_saver_spec.rb
+++ b/spec/lib/gitlab/import_export/project/tree_saver_spec.rb
@@ -404,7 +404,7 @@ RSpec.describe Gitlab::ImportExport::Project::TreeSaver do
context 'when streaming has to retry', :aggregate_failures do
let(:shared) { double('shared', export_path: exportable_path) }
- let(:logger) { Gitlab::Import::Logger.build }
+ let(:logger) { Gitlab::Export::Logger.build }
let(:serializer) { double('serializer') }
let(:error_class) { Net::OpenTimeout }
let(:info_params) do
diff --git a/spec/lib/gitlab/import_export/shared_spec.rb b/spec/lib/gitlab/import_export/shared_spec.rb
index 1945156ca59..408ed3a2176 100644
--- a/spec/lib/gitlab/import_export/shared_spec.rb
+++ b/spec/lib/gitlab/import_export/shared_spec.rb
@@ -68,12 +68,18 @@ RSpec.describe Gitlab::ImportExport::Shared do
expect(subject.errors).to eq(['Error importing into [FILTERED] Permission denied @ unlink_internal - [FILTERED]'])
end
- it 'updates the import JID' do
+ it 'tracks exception' do
import_state = create(:import_state, project: project, jid: 'jid-test')
expect(Gitlab::ErrorTracking)
.to receive(:track_exception)
- .with(error, hash_including(import_jid: import_state.jid))
+ .with(error, hash_including(
+ importer: 'Import/Export',
+ project_id: project.id,
+ project_name: project.name,
+ project_path: project.full_path,
+ import_jid: import_state.jid
+ ))
subject.error(error)
end
diff --git a/spec/lib/gitlab/redis/cache_spec.rb b/spec/lib/gitlab/redis/cache_spec.rb
index 31141ac1139..1f0ebbe107f 100644
--- a/spec/lib/gitlab/redis/cache_spec.rb
+++ b/spec/lib/gitlab/redis/cache_spec.rb
@@ -15,4 +15,16 @@ RSpec.describe Gitlab::Redis::Cache do
expect(subject.send(:raw_config_hash)).to eq(url: 'redis://localhost:6380' )
end
end
+
+ describe '.active_support_config' do
+ it 'has a default ttl of 2 weeks' do
+ expect(described_class.active_support_config[:expires_in]).to eq(2.weeks)
+ end
+
+ it 'allows configuring the TTL through an env variable' do
+ stub_env('GITLAB_RAILS_CACHE_DEFAULT_TTL_SECONDS' => '86400')
+
+ expect(described_class.active_support_config[:expires_in]).to eq(1.day)
+ end
+ end
end
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb
index 6cdc0ef9d9b..546cfd80fcf 100644
--- a/spec/models/ci/build_spec.rb
+++ b/spec/models/ci/build_spec.rb
@@ -3,6 +3,7 @@
require 'spec_helper'
RSpec.describe Ci::Build do
+ include Ci::TemplateHelpers
let_it_be(:user) { create(:user) }
let_it_be(:group, reload: true) { create(:group) }
let_it_be(:project, reload: true) { create(:project, :repository, group: group) }
@@ -2865,6 +2866,7 @@ RSpec.describe Ci::Build do
public: true,
masked: false },
{ key: 'CI_API_V4_URL', value: 'http://localhost/api/v4', public: true, masked: false },
+ { key: 'CI_TEMPLATE_REGISTRY_HOST', value: template_registry_host, public: true, masked: false },
{ key: 'CI_PIPELINE_IID', value: pipeline.iid.to_s, public: true, masked: false },
{ key: 'CI_PIPELINE_SOURCE', value: pipeline.source, public: true, masked: false },
{ key: 'CI_PIPELINE_CREATED_AT', value: pipeline.created_at.iso8601, public: true, masked: false },
diff --git a/spec/requests/api/deployments_spec.rb b/spec/requests/api/deployments_spec.rb
index 88f5bc868d4..24c3ee59c18 100644
--- a/spec/requests/api/deployments_spec.rb
+++ b/spec/requests/api/deployments_spec.rb
@@ -451,7 +451,7 @@ RSpec.describe API::Deployments do
describe 'DELETE /projects/:id/deployments/:deployment_id' do
let(:project) { create(:project, :repository) }
let(:environment) { create(:environment, project: project) }
- let(:commits) { project.repository.commits(nil, { limit: 2 }) }
+ let(:commits) { project.repository.commits(nil, { limit: 3 }) }
let!(:deploy) do
create(
:deployment,
@@ -475,12 +475,30 @@ RSpec.describe API::Deployments do
)
end
+ let!(:running_deploy) do
+ create(
+ :deployment,
+ :running,
+ project: project,
+ environment: environment,
+ deployable: nil,
+ sha: commits[2].sha
+ )
+ end
+
context 'as an maintainer' do
it 'deletes a deployment' do
delete api("/projects/#{project.id}/deployments/#{old_deploy.id}", user)
expect(response).to have_gitlab_http_status(:no_content)
end
+
+ it 'will not delete a running deployment' do
+ delete api("/projects/#{project.id}/deployments/#{running_deploy.id}", user)
+
+ expect(response).to have_gitlab_http_status(:bad_request)
+ expect(response.body).to include("Cannot destroy running deployment")
+ end
end
context 'as a developer' do
diff --git a/spec/services/projects/import_export/export_service_spec.rb b/spec/services/projects/import_export/export_service_spec.rb
index 54abbc04084..285687505e9 100644
--- a/spec/services/projects/import_export/export_service_spec.rb
+++ b/spec/services/projects/import_export/export_service_spec.rb
@@ -89,7 +89,21 @@ RSpec.describe Projects::ImportExport::ExportService do
context 'when all saver services succeed' do
before do
- allow(service).to receive(:save_services).and_return(true)
+ allow(service).to receive(:save_exporters).and_return(true)
+ end
+
+ it 'logs a successful message' do
+ allow(Gitlab::ImportExport::Saver).to receive(:save).and_return(true)
+
+ expect(service.instance_variable_get(:@logger)).to receive(:info).ordered.with(
+ hash_including({ message: 'Project export started', project_id: project.id })
+ )
+
+ expect(service.instance_variable_get(:@logger)).to receive(:info).ordered.with(
+ hash_including({ message: 'Project successfully exported', project_id: project.id })
+ )
+
+ service.execute
end
it 'saves the project in the file system' do
@@ -111,6 +125,7 @@ RSpec.describe Projects::ImportExport::ExportService do
end
it 'calls the after export strategy' do
+ allow(Gitlab::ImportExport::Saver).to receive(:save).and_return(true)
expect(after_export_strategy).to receive(:execute)
service.execute(after_export_strategy)
@@ -119,7 +134,7 @@ RSpec.describe Projects::ImportExport::ExportService do
context 'when after export strategy fails' do
before do
allow(after_export_strategy).to receive(:execute).and_return(false)
- expect(Gitlab::ImportExport::Saver).to receive(:save).with(exportable: project, shared: shared).and_return(true)
+ allow(Gitlab::ImportExport::Saver).to receive(:save).and_return(true)
end
after do
@@ -140,7 +155,9 @@ RSpec.describe Projects::ImportExport::ExportService do
end
it 'notifies logger' do
- expect(service.instance_variable_get(:@logger)).to receive(:error)
+ expect(service.instance_variable_get(:@logger)).to receive(:error).with(
+ hash_including({ message: 'Project export error', project_id: project.id })
+ )
end
end
end
diff --git a/spec/services/security/ci_configuration/sast_parser_service_spec.rb b/spec/services/security/ci_configuration/sast_parser_service_spec.rb
index b11f31a9086..1fd196cdcee 100644
--- a/spec/services/security/ci_configuration/sast_parser_service_spec.rb
+++ b/spec/services/security/ci_configuration/sast_parser_service_spec.rb
@@ -16,7 +16,7 @@ RSpec.describe Security::CiConfiguration::SastParserService do
let(:bandit) { configuration['analyzers'][0] }
let(:brakeman) { configuration['analyzers'][1] }
let(:sast_brakeman_level) { brakeman['variables'][0] }
- let(:secure_analyzers_prefix) { '$TEMPLATE_REGISTRY_HOST/security-products' }
+ let(:secure_analyzers_prefix) { '$CI_TEMPLATE_REGISTRY_HOST/security-products' }
it 'parses the configuration for SAST' do
expect(secure_analyzers['default_value']).to eql(secure_analyzers_prefix)