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>2022-09-28 21:08:30 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-09-28 21:08:30 +0300
commit7f3f19582b13b4162212bcf0ae72eef63685ffbc (patch)
tree3f7123587a68611c5443f05e33b5789c784e3d63 /spec/lib/gitlab
parent1bb7f81e238569fd0fe2b0c4385f1015407a2d59 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r--spec/lib/gitlab/github_import/importer/protected_branch_importer_spec.rb47
-rw-r--r--spec/lib/gitlab/github_import/representation/protected_branch_spec.rb20
-rw-r--r--spec/lib/gitlab/import_export/after_export_strategies/web_upload_strategy_spec.rb130
3 files changed, 103 insertions, 94 deletions
diff --git a/spec/lib/gitlab/github_import/importer/protected_branch_importer_spec.rb b/spec/lib/gitlab/github_import/importer/protected_branch_importer_spec.rb
index 6dc6db739f4..12d143f3692 100644
--- a/spec/lib/gitlab/github_import/importer/protected_branch_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/protected_branch_importer_spec.rb
@@ -5,11 +5,14 @@ require 'spec_helper'
RSpec.describe Gitlab::GithubImport::Importer::ProtectedBranchImporter do
subject(:importer) { described_class.new(github_protected_branch, project, client) }
+ let(:branch_name) { 'protection' }
let(:allow_force_pushes_on_github) { true }
+ let(:required_conversation_resolution) { true }
let(:github_protected_branch) do
Gitlab::GithubImport::Representation::ProtectedBranch.new(
- id: 'protection',
- allow_force_pushes: allow_force_pushes_on_github
+ id: branch_name,
+ allow_force_pushes: allow_force_pushes_on_github,
+ required_conversation_resolution: required_conversation_resolution
)
end
@@ -47,6 +50,12 @@ RSpec.describe Gitlab::GithubImport::Importer::ProtectedBranchImporter do
end
end
+ shared_examples 'does not change project attributes' do
+ it 'does not change only_allow_merge_if_all_discussions_are_resolved' do
+ expect { importer.execute }.not_to change(project, :only_allow_merge_if_all_discussions_are_resolved)
+ end
+ end
+
context 'when branch is protected on GitLab' do
before do
create(
@@ -87,5 +96,39 @@ RSpec.describe Gitlab::GithubImport::Importer::ProtectedBranchImporter do
it_behaves_like 'create branch protection by the strictest ruleset'
end
+
+ context "when branch is default" do
+ before do
+ allow(project).to receive(:default_branch).and_return(branch_name)
+ end
+
+ context 'when required_conversation_resolution rule is enabled' do
+ let(:required_conversation_resolution) { true }
+
+ it 'changes project settings' do
+ expect { importer.execute }.to change(project, :only_allow_merge_if_all_discussions_are_resolved).to(true)
+ end
+ end
+
+ context 'when required_conversation_resolution rule is disabled' do
+ let(:required_conversation_resolution) { false }
+
+ it_behaves_like 'does not change project attributes'
+ end
+ end
+
+ context "when branch is not default" do
+ context 'when required_conversation_resolution rule is enabled' do
+ let(:required_conversation_resolution) { true }
+
+ it_behaves_like 'does not change project attributes'
+ end
+
+ context 'when required_conversation_resolution rule is disabled' do
+ let(:required_conversation_resolution) { false }
+
+ it_behaves_like 'does not change project attributes'
+ end
+ end
end
end
diff --git a/spec/lib/gitlab/github_import/representation/protected_branch_spec.rb b/spec/lib/gitlab/github_import/representation/protected_branch_spec.rb
index e762dc469c1..1d8426c0ad8 100644
--- a/spec/lib/gitlab/github_import/representation/protected_branch_spec.rb
+++ b/spec/lib/gitlab/github_import/representation/protected_branch_spec.rb
@@ -9,23 +9,30 @@ RSpec.describe Gitlab::GithubImport::Representation::ProtectedBranch do
end
context 'with ProtectedBranch' do
- it 'includes the protected branch ID (name)' do
+ it 'includes the protected branch ID (name) attribute' do
expect(protected_branch.id).to eq 'main'
end
- it 'includes the protected branch allow_force_pushes' do
+ it 'includes the protected branch allow_force_pushes attribute' do
expect(protected_branch.allow_force_pushes).to eq true
end
+
+ it 'includes the protected branch required_conversation_resolution attribute' do
+ expect(protected_branch.required_conversation_resolution).to eq true
+ end
end
end
describe '.from_api_response' do
let(:response) do
- response = Struct.new(:url, :allow_force_pushes, keyword_init: true)
- allow_force_pushes = Struct.new(:enabled, keyword_init: true)
+ response = Struct.new(:url, :allow_force_pushes, :required_conversation_resolution, keyword_init: true)
+ enabled_setting = Struct.new(:enabled, keyword_init: true)
response.new(
url: 'https://example.com/branches/main/protection',
- allow_force_pushes: allow_force_pushes.new(
+ allow_force_pushes: enabled_setting.new(
+ enabled: true
+ ),
+ required_conversation_resolution: enabled_setting.new(
enabled: true
)
)
@@ -41,7 +48,8 @@ RSpec.describe Gitlab::GithubImport::Representation::ProtectedBranch do
let(:hash) do
{
'id' => 'main',
- 'allow_force_pushes' => true
+ 'allow_force_pushes' => true,
+ 'required_conversation_resolution' => true
}
end
diff --git a/spec/lib/gitlab/import_export/after_export_strategies/web_upload_strategy_spec.rb b/spec/lib/gitlab/import_export/after_export_strategies/web_upload_strategy_spec.rb
index 42cf9c54798..297fe3ade07 100644
--- a/spec/lib/gitlab/import_export/after_export_strategies/web_upload_strategy_spec.rb
+++ b/spec/lib/gitlab/import_export/after_export_strategies/web_upload_strategy_spec.rb
@@ -9,8 +9,6 @@ RSpec.describe Gitlab::ImportExport::AfterExportStrategies::WebUploadStrategy do
allow_next_instance_of(ProjectExportWorker) do |job|
allow(job).to receive(:jid).and_return(SecureRandom.hex(8))
end
-
- stub_feature_flags(import_export_web_upload_stream: false)
stub_uploads_object_storage(FileUploader, enabled: false)
end
@@ -109,108 +107,68 @@ RSpec.describe Gitlab::ImportExport::AfterExportStrategies::WebUploadStrategy do
end
context 'when object store is enabled' do
+ let(:object_store_url) { 'http://object-storage/project.tar.gz' }
+
before do
- object_store_url = 'http://object-storage/project.tar.gz'
stub_uploads_object_storage(FileUploader)
- stub_request(:get, object_store_url)
- stub_request(:post, example_url)
+
allow(import_export_upload.export_file).to receive(:url).and_return(object_store_url)
allow(import_export_upload.export_file).to receive(:file_storage?).and_return(false)
end
- it 'reads file using Gitlab::HttpIO and uploads to external url' do
- expect_next_instance_of(Gitlab::HttpIO) do |http_io|
- expect(http_io).to receive(:read).and_call_original
+ it 'uploads file as a remote stream' do
+ arguments = {
+ download_url: object_store_url,
+ upload_url: example_url,
+ options: {
+ upload_method: :post,
+ upload_content_type: 'application/gzip'
+ }
+ }
+
+ expect_next_instance_of(Gitlab::ImportExport::RemoteStreamUpload, arguments) do |remote_stream_upload|
+ expect(remote_stream_upload).to receive(:execute)
end
- expect(Gitlab::ImportExport::RemoteStreamUpload).not_to receive(:new)
+ expect(Gitlab::HttpIO).not_to receive(:new)
strategy.execute(user, project)
-
- expect(a_request(:post, example_url)).to have_been_made
end
- end
-
- context 'when `import_export_web_upload_stream` feature is enabled' do
- before do
- stub_feature_flags(import_export_web_upload_stream: true)
- end
-
- context 'when remote object store is disabled' do
- it 'reads file from disk and uploads to external url' do
- stub_request(:post, example_url).to_return(status: 200)
- expect(Gitlab::ImportExport::RemoteStreamUpload).not_to receive(:new)
- expect(Gitlab::HttpIO).not_to receive(:new)
-
- strategy.execute(user, project)
-
- expect(a_request(:post, example_url)).to have_been_made
- end
- end
-
- context 'when object store is enabled' do
- let(:object_store_url) { 'http://object-storage/project.tar.gz' }
+ context 'when upload as remote stream raises an exception' do
before do
- stub_uploads_object_storage(FileUploader)
-
- allow(import_export_upload.export_file).to receive(:url).and_return(object_store_url)
- allow(import_export_upload.export_file).to receive(:file_storage?).and_return(false)
+ allow_next_instance_of(Gitlab::ImportExport::RemoteStreamUpload) do |remote_stream_upload|
+ allow(remote_stream_upload).to receive(:execute).and_raise(
+ Gitlab::ImportExport::RemoteStreamUpload::StreamError.new('Exception error message', 'Response body')
+ )
+ end
end
- it 'uploads file as a remote stream' do
- arguments = {
- download_url: object_store_url,
- upload_url: example_url,
- options: {
- upload_method: :post,
- upload_content_type: 'application/gzip'
- }
- }
-
- expect_next_instance_of(Gitlab::ImportExport::RemoteStreamUpload, arguments) do |remote_stream_upload|
- expect(remote_stream_upload).to receive(:execute)
+ it 'logs the exception and stores the error message' do
+ expect_next_instance_of(Gitlab::Export::Logger) do |logger|
+ expect(logger).to receive(:error).ordered.with(
+ {
+ project_id: project.id,
+ project_name: project.name,
+ message: 'Exception error message',
+ response_body: 'Response body'
+ }
+ )
+
+ expect(logger).to receive(:error).ordered.with(
+ {
+ project_id: project.id,
+ project_name: project.name,
+ message: 'After export strategy failed',
+ 'exception.class' => 'Gitlab::ImportExport::RemoteStreamUpload::StreamError',
+ 'exception.message' => 'Exception error message',
+ 'exception.backtrace' => anything
+ }
+ )
end
- expect(Gitlab::HttpIO).not_to receive(:new)
strategy.execute(user, project)
- end
- context 'when upload as remote stream raises an exception' do
- before do
- allow_next_instance_of(Gitlab::ImportExport::RemoteStreamUpload) do |remote_stream_upload|
- allow(remote_stream_upload).to receive(:execute).and_raise(
- Gitlab::ImportExport::RemoteStreamUpload::StreamError.new('Exception error message', 'Response body')
- )
- end
- end
-
- it 'logs the exception and stores the error message' do
- expect_next_instance_of(Gitlab::Export::Logger) do |logger|
- expect(logger).to receive(:error).ordered.with(
- {
- project_id: project.id,
- project_name: project.name,
- message: 'Exception error message',
- response_body: 'Response body'
- }
- )
-
- expect(logger).to receive(:error).ordered.with(
- {
- project_id: project.id,
- project_name: project.name,
- message: 'After export strategy failed',
- 'exception.class' => 'Gitlab::ImportExport::RemoteStreamUpload::StreamError',
- 'exception.message' => 'Exception error message',
- 'exception.backtrace' => anything
- }
- )
- end
-
- strategy.execute(user, project)
-
- expect(project.import_export_shared.errors.first).to eq('Exception error message')
- end
+ expect(project.import_export_shared.errors.first).to eq('Exception error message')
end
end
end