summaryrefslogtreecommitdiff
path: root/spec/support/shared_examples/services
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support/shared_examples/services')
-rw-r--r--spec/support/shared_examples/services/issuable_links/create_links_shared_examples.rb2
-rw-r--r--spec/support/shared_examples/services/issuable_links/destroyable_issuable_links_shared_examples.rb7
-rw-r--r--spec/support/shared_examples/services/repositories/housekeeping_shared_examples.rb50
-rw-r--r--spec/support/shared_examples/services/security/ci_configuration/create_service_shared_examples.rb62
4 files changed, 73 insertions, 48 deletions
diff --git a/spec/support/shared_examples/services/issuable_links/create_links_shared_examples.rb b/spec/support/shared_examples/services/issuable_links/create_links_shared_examples.rb
index 12f2b5d78a5..e47ff2fcd59 100644
--- a/spec/support/shared_examples/services/issuable_links/create_links_shared_examples.rb
+++ b/spec/support/shared_examples/services/issuable_links/create_links_shared_examples.rb
@@ -30,7 +30,7 @@ RSpec.shared_examples 'issuable link creation' do
context 'when user has no permission to target issuable' do
let(:params) do
- { issuable_references: [guest_issuable.to_reference(issuable_parent)] }
+ { issuable_references: [restricted_issuable.to_reference(issuable_parent)] }
end
it 'returns error' do
diff --git a/spec/support/shared_examples/services/issuable_links/destroyable_issuable_links_shared_examples.rb b/spec/support/shared_examples/services/issuable_links/destroyable_issuable_links_shared_examples.rb
index cc170c6544d..1532e870dcc 100644
--- a/spec/support/shared_examples/services/issuable_links/destroyable_issuable_links_shared_examples.rb
+++ b/spec/support/shared_examples/services/issuable_links/destroyable_issuable_links_shared_examples.rb
@@ -1,10 +1,11 @@
# frozen_string_literal: true
-RSpec.shared_examples 'a destroyable issuable link' do
+RSpec.shared_examples 'a destroyable issuable link' do |required_role: :reporter|
context 'when successfully removes an issuable link' do
before do
- issuable_link.source.resource_parent.add_reporter(user)
- issuable_link.target.resource_parent.add_reporter(user)
+ [issuable_link.target, issuable_link.source].each do |issuable|
+ issuable.resource_parent.try(:"add_#{required_role}", user)
+ end
end
it 'removes related issue' do
diff --git a/spec/support/shared_examples/services/repositories/housekeeping_shared_examples.rb b/spec/support/shared_examples/services/repositories/housekeeping_shared_examples.rb
index 8a937303711..8cc71230ba4 100644
--- a/spec/support/shared_examples/services/repositories/housekeeping_shared_examples.rb
+++ b/spec/support/shared_examples/services/repositories/housekeeping_shared_examples.rb
@@ -65,12 +65,9 @@ RSpec.shared_examples 'housekeeps repository' do
# At push 200
expect(resource.git_garbage_collect_worker_klass).to receive(:perform_async).with(resource.id, :gc, :the_lease_key, :the_uuid)
.once
- # At push 50, 100, 150
- expect(resource.git_garbage_collect_worker_klass).to receive(:perform_async).with(resource.id, :full_repack, :the_lease_key, :the_uuid)
- .exactly(3).times
- # At push 10, 20, ... (except those above)
+ # At push 10, 20, ... (except the gc call)
expect(resource.git_garbage_collect_worker_klass).to receive(:perform_async).with(resource.id, :incremental_repack, :the_lease_key, :the_uuid)
- .exactly(16).times
+ .exactly(19).times
201.times do
subject.increment!
@@ -79,37 +76,6 @@ RSpec.shared_examples 'housekeeps repository' do
expect(resource.pushes_since_gc).to eq(1)
end
-
- context 'when optimized_repository feature flag is disabled' do
- before do
- stub_feature_flags(optimized_housekeeping: false)
- end
-
- it 'calls also the garbage collect worker with pack_refs every 6 commits' do
- allow(subject).to receive(:try_obtain_lease).and_return(:the_uuid)
- allow(subject).to receive(:lease_key).and_return(:the_lease_key)
-
- # At push 200
- expect(resource.git_garbage_collect_worker_klass).to receive(:perform_async).with(resource.id, :gc, :the_lease_key, :the_uuid)
- .once
- # At push 50, 100, 150
- expect(resource.git_garbage_collect_worker_klass).to receive(:perform_async).with(resource.id, :full_repack, :the_lease_key, :the_uuid)
- .exactly(3).times
- # At push 10, 20, ... (except those above)
- expect(resource.git_garbage_collect_worker_klass).to receive(:perform_async).with(resource.id, :incremental_repack, :the_lease_key, :the_uuid)
- .exactly(16).times
- # At push 6, 12, 18, ... (except those above)
- expect(resource.git_garbage_collect_worker_klass).to receive(:perform_async).with(resource.id, :pack_refs, :the_lease_key, :the_uuid)
- .exactly(27).times
-
- 201.times do
- subject.increment!
- subject.execute if subject.needed?
- end
-
- expect(resource.pushes_since_gc).to eq(1)
- end
- end
end
it 'runs the task specifically requested' do
@@ -136,15 +102,11 @@ RSpec.shared_examples 'housekeeps repository' do
expect(subject.needed?).to eq(true)
end
- context 'when optimized_housekeeping is disabled' do
- before do
- stub_feature_flags(optimized_housekeeping: false)
- end
+ it 'when incremental repack period is not multiple of gc period' do
+ allow(Gitlab::CurrentSettings).to receive(:housekeeping_incremental_repack_period).and_return(12)
+ allow(resource).to receive(:pushes_since_gc).and_return(200)
- it 'returns true pack refs is needed' do
- allow(resource).to receive(:pushes_since_gc).and_return(described_class::PACK_REFS_PERIOD)
- expect(subject.needed?).to eq(true)
- end
+ expect(subject.needed?).to eq(true)
end
end
diff --git a/spec/support/shared_examples/services/security/ci_configuration/create_service_shared_examples.rb b/spec/support/shared_examples/services/security/ci_configuration/create_service_shared_examples.rb
index 105c4247ff7..716be8c6210 100644
--- a/spec/support/shared_examples/services/security/ci_configuration/create_service_shared_examples.rb
+++ b/spec/support/shared_examples/services/security/ci_configuration/create_service_shared_examples.rb
@@ -88,6 +88,68 @@ RSpec.shared_examples_for 'services security ci configuration create service' do
end
end
+ context 'when existing ci config contains anchors/aliases' do
+ let(:params) { {} }
+ let(:unsupported_yaml) do
+ <<-YAML
+ image: python:latest
+
+ cache: &global_cache
+ key: 'common-cache'
+ paths:
+ - .cache/pip
+ - venv/
+
+ test:
+ cache:
+ <<: *global_cache
+ key: 'custom-cache'
+ script:
+ - python setup.py test
+ - pip install tox flake8 # you can also use tox
+ - tox -e py36,flake8
+ YAML
+ end
+
+ it 'fails with error' do
+ expect(project).to receive(:ci_config_for).and_return(unsupported_yaml)
+
+ expect { result }.to raise_error(Gitlab::Graphql::Errors::MutationError, '.gitlab-ci.yml with aliases/anchors is not supported. Please change the CI configuration manually.')
+ end
+ end
+
+ context 'when parsing existing ci config gives a Psych error' do
+ let(:params) { {} }
+ let(:invalid_yaml) do
+ <<-YAML
+ image: python:latest
+
+ test:
+ script:
+ - python setup.py test
+ - pip install tox flake8 # you can also use tox
+ - tox -e py36,flake8
+ YAML
+ end
+
+ it 'fails with error' do
+ expect(project).to receive(:ci_config_for).and_return(invalid_yaml)
+ expect(YAML).to receive(:safe_load).and_raise(Psych::Exception)
+
+ expect { result }.to raise_error(Gitlab::Graphql::Errors::MutationError, /merge request creation mutation failed/)
+ end
+ end
+
+ context 'when parsing existing ci config gives any other error' do
+ let(:params) { {} }
+ let_it_be(:repository) { project.repository }
+
+ it 'is successful' do
+ expect(repository).to receive(:root_ref_sha).and_raise(StandardError)
+ expect(result.status).to eq(:success)
+ end
+ end
+
unless skip_w_params
context 'with parameters' do
let(:params) { non_empty_params }