diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-23 15:09:45 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-23 15:09:45 +0000 |
commit | 99c1dfd5e3f39868d65cb006078a8d091992fa54 (patch) | |
tree | 18d970852272c6d5ba303911da13d16cbff2514c /spec/contracts | |
parent | 23634aa773e10e7df79247fb6fddbce88b825909 (diff) | |
download | gitlab-ce-99c1dfd5e3f39868d65cb006078a8d091992fa54.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/contracts')
10 files changed, 32 insertions, 22 deletions
diff --git a/spec/contracts/provider/helpers/contract_source_helper.rb b/spec/contracts/provider/helpers/contract_source_helper.rb index 5fc2e3ffc0d..f59f228722d 100644 --- a/spec/contracts/provider/helpers/contract_source_helper.rb +++ b/spec/contracts/provider/helpers/contract_source_helper.rb @@ -4,18 +4,22 @@ module Provider module ContractSourceHelper QA_PACT_BROKER_HOST = "http://localhost:9292/pacts" PREFIX_PATHS = { - rake: "../../../contracts/contracts/project", + rake: { + ce: "../../contracts/project", + ee: "../../../../ee/spec/contracts/contracts/project" + }, spec: "../contracts/project" }.freeze SUB_PATH_REGEX = %r{project/(?<file_path>.*?)_helper.rb}.freeze class << self - def contract_location(requester, file_path) + def contract_location(requester:, file_path:, edition: :ce) raise ArgumentError, 'requester must be :rake or :spec' unless [:rake, :spec].include? requester + raise ArgumentError, 'edition must be :ce or :ee' unless [:ce, :ee].include? edition relevant_path = file_path.match(SUB_PATH_REGEX)[:file_path].split('/') - ENV["PACT_BROKER"] ? pact_broker_url(relevant_path) : local_contract_location(requester, relevant_path) + ENV["PACT_BROKER"] ? pact_broker_url(relevant_path) : local_contract_location(requester, relevant_path, edition) end def pact_broker_url(file_path) @@ -36,9 +40,10 @@ module Provider "#{file_path[0].split('_').map(&:capitalize).join}%23#{file_path[1]}" end - def local_contract_location(requester, file_path) + def local_contract_location(requester, file_path, edition) contract_path = construct_local_contract_path(file_path) - prefix_path = requester == :rake ? File.expand_path(PREFIX_PATHS[requester], __dir__) : PREFIX_PATHS[requester] + prefix_path = PREFIX_PATHS[requester] + prefix_path = File.expand_path(prefix_path[edition], __dir__) if requester == :rake "#{prefix_path}#{contract_path}" end diff --git a/spec/contracts/provider/pact_helpers/project/merge_requests/show/get_diffs_batch_helper.rb b/spec/contracts/provider/pact_helpers/project/merge_requests/show/get_diffs_batch_helper.rb index aa97a07c07b..2d7486562c2 100644 --- a/spec/contracts/provider/pact_helpers/project/merge_requests/show/get_diffs_batch_helper.rb +++ b/spec/contracts/provider/pact_helpers/project/merge_requests/show/get_diffs_batch_helper.rb @@ -11,7 +11,7 @@ module Provider app { Environments::Test.app } honours_pact_with "MergeRequests#show" do - pact_uri Provider::ContractSourceHelper.contract_location(:spec, __FILE__) + pact_uri Provider::ContractSourceHelper.contract_location(requester: :spec, file_path: __FILE__) end Provider::PublishContractHelper.publish_contract_setup.call( diff --git a/spec/contracts/provider/pact_helpers/project/merge_requests/show/get_diffs_metadata_helper.rb b/spec/contracts/provider/pact_helpers/project/merge_requests/show/get_diffs_metadata_helper.rb index 891585b0066..4cb358f6e32 100644 --- a/spec/contracts/provider/pact_helpers/project/merge_requests/show/get_diffs_metadata_helper.rb +++ b/spec/contracts/provider/pact_helpers/project/merge_requests/show/get_diffs_metadata_helper.rb @@ -11,7 +11,7 @@ module Provider app { Environments::Test.app } honours_pact_with "MergeRequests#show" do - pact_uri Provider::ContractSourceHelper.contract_location(:spec, __FILE__) + pact_uri Provider::ContractSourceHelper.contract_location(requester: :spec, file_path: __FILE__) end Provider::PublishContractHelper.publish_contract_setup.call( diff --git a/spec/contracts/provider/pact_helpers/project/merge_requests/show/get_discussions_helper.rb b/spec/contracts/provider/pact_helpers/project/merge_requests/show/get_discussions_helper.rb index 229818366ca..4dea90fc6b7 100644 --- a/spec/contracts/provider/pact_helpers/project/merge_requests/show/get_discussions_helper.rb +++ b/spec/contracts/provider/pact_helpers/project/merge_requests/show/get_discussions_helper.rb @@ -11,7 +11,7 @@ module Provider app { Environments::Test.app } honours_pact_with "MergeRequests#show" do - pact_uri Provider::ContractSourceHelper.contract_location(:spec, __FILE__) + pact_uri Provider::ContractSourceHelper.contract_location(requester: :spec, file_path: __FILE__) end Provider::PublishContractHelper.publish_contract_setup.call( diff --git a/spec/contracts/provider/pact_helpers/project/pipeline_schedules/edit/put_edit_a_pipeline_schedule_helper.rb b/spec/contracts/provider/pact_helpers/project/pipeline_schedules/edit/put_edit_a_pipeline_schedule_helper.rb index 62702fd5f92..1d9c1331d3b 100644 --- a/spec/contracts/provider/pact_helpers/project/pipeline_schedules/edit/put_edit_a_pipeline_schedule_helper.rb +++ b/spec/contracts/provider/pact_helpers/project/pipeline_schedules/edit/put_edit_a_pipeline_schedule_helper.rb @@ -11,7 +11,7 @@ module Provider app { Environments::Test.app } honours_pact_with "PipelineSchedules#edit" do - pact_uri Provider::ContractSourceHelper.contract_location(:spec, __FILE__) + pact_uri Provider::ContractSourceHelper.contract_location(requester: :spec, file_path: __FILE__) end Provider::PublishContractHelper.publish_contract_setup.call( diff --git a/spec/contracts/provider/pact_helpers/project/pipelines/index/get_list_project_pipelines_helper.rb b/spec/contracts/provider/pact_helpers/project/pipelines/index/get_list_project_pipelines_helper.rb index 03708db2eb2..2263723b123 100644 --- a/spec/contracts/provider/pact_helpers/project/pipelines/index/get_list_project_pipelines_helper.rb +++ b/spec/contracts/provider/pact_helpers/project/pipelines/index/get_list_project_pipelines_helper.rb @@ -11,7 +11,7 @@ module Provider app { Environments::Test.app } honours_pact_with "Pipelines#index" do - pact_uri Provider::ContractSourceHelper.contract_location(:spec, __FILE__) + pact_uri Provider::ContractSourceHelper.contract_location(requester: :spec, file_path: __FILE__) end Provider::PublishContractHelper.publish_contract_setup.call( diff --git a/spec/contracts/provider/pact_helpers/project/pipelines/new/post_create_a_new_pipeline_helper.rb b/spec/contracts/provider/pact_helpers/project/pipelines/new/post_create_a_new_pipeline_helper.rb index 53e5ab61a20..8c2b0278ad1 100644 --- a/spec/contracts/provider/pact_helpers/project/pipelines/new/post_create_a_new_pipeline_helper.rb +++ b/spec/contracts/provider/pact_helpers/project/pipelines/new/post_create_a_new_pipeline_helper.rb @@ -11,7 +11,7 @@ module Provider app { Environments::Test.app } honours_pact_with "Pipelines#new" do - pact_uri Provider::ContractSourceHelper.contract_location(:spec, __FILE__) + pact_uri Provider::ContractSourceHelper.contract_location(requester: :spec, file_path: __FILE__) end Provider::PublishContractHelper.publish_contract_setup.call( diff --git a/spec/contracts/provider/pact_helpers/project/pipelines/show/delete_pipeline_helper.rb b/spec/contracts/provider/pact_helpers/project/pipelines/show/delete_pipeline_helper.rb index 1801e989c99..01b57388d70 100644 --- a/spec/contracts/provider/pact_helpers/project/pipelines/show/delete_pipeline_helper.rb +++ b/spec/contracts/provider/pact_helpers/project/pipelines/show/delete_pipeline_helper.rb @@ -11,7 +11,7 @@ module Provider app { Environments::Test.app } honours_pact_with "Pipelines#show" do - pact_uri Provider::ContractSourceHelper.contract_location(:spec, __FILE__) + pact_uri Provider::ContractSourceHelper.contract_location(requester: :spec, file_path: __FILE__) end Provider::PublishContractHelper.publish_contract_setup.call( diff --git a/spec/contracts/provider/pact_helpers/project/pipelines/show/get_pipeline_header_data_helper.rb b/spec/contracts/provider/pact_helpers/project/pipelines/show/get_pipeline_header_data_helper.rb index 1f3ba9dd007..aac8d25dbd1 100644 --- a/spec/contracts/provider/pact_helpers/project/pipelines/show/get_pipeline_header_data_helper.rb +++ b/spec/contracts/provider/pact_helpers/project/pipelines/show/get_pipeline_header_data_helper.rb @@ -11,7 +11,7 @@ module Provider app { Environments::Test.app } honours_pact_with "Pipelines#show" do - pact_uri Provider::ContractSourceHelper.contract_location(:spec, __FILE__) + pact_uri Provider::ContractSourceHelper.contract_location(requester: :spec, file_path: __FILE__) end Provider::PublishContractHelper.publish_contract_setup.call( diff --git a/spec/contracts/provider_specs/helpers/provider/contract_source_helper_spec.rb b/spec/contracts/provider_specs/helpers/provider/contract_source_helper_spec.rb index 8bb3b577135..39537aa153d 100644 --- a/spec/contracts/provider_specs/helpers/provider/contract_source_helper_spec.rb +++ b/spec/contracts/provider_specs/helpers/provider/contract_source_helper_spec.rb @@ -11,21 +11,26 @@ RSpec.describe Provider::ContractSourceHelper, feature_category: :not_owned do describe '#contract_location' do it 'raises an error when an invalid requester is given' do - expect { subject.contract_location(:foo, pact_helper_path) } + expect { subject.contract_location(requester: :foo, file_path: pact_helper_path) } .to raise_error(ArgumentError, 'requester must be :rake or :spec') end + it 'raises an error when an invalid edition is given' do + expect { subject.contract_location(requester: :spec, file_path: pact_helper_path, edition: :zz) } + .to raise_error(ArgumentError, 'edition must be :ce or :ee') + end + context 'when the PACT_BROKER environment variable is not set' do it 'extracts the relevant path from the pact_helper path' do - expect(subject).to receive(:local_contract_location).with(:rake, split_pact_helper_path) + expect(subject).to receive(:local_contract_location).with(:rake, split_pact_helper_path, :ce) - subject.contract_location(:rake, pact_helper_path) + subject.contract_location(requester: :rake, file_path: pact_helper_path) end it 'does not construct the pact broker url' do expect(subject).not_to receive(:pact_broker_url) - subject.contract_location(:rake, pact_helper_path) + subject.contract_location(requester: :rake, file_path: pact_helper_path) end end @@ -37,13 +42,13 @@ RSpec.describe Provider::ContractSourceHelper, feature_category: :not_owned do it 'extracts the relevant path from the pact_helper path' do expect(subject).to receive(:pact_broker_url).with(split_pact_helper_path) - subject.contract_location(:spec, pact_helper_path) + subject.contract_location(requester: :spec, file_path: pact_helper_path) end it 'does not construct the pact broker url' do expect(subject).not_to receive(:local_contract_location) - subject.contract_location(:spec, pact_helper_path) + subject.contract_location(requester: :spec, file_path: pact_helper_path) end end end @@ -51,7 +56,7 @@ RSpec.describe Provider::ContractSourceHelper, feature_category: :not_owned do describe '#pact_broker_url' do it 'returns the full url to the contract that the provider test is verifying' do contract_url_path = "http://localhost:9292/pacts/provider/" \ - "#{provider_url_path}/consumer/#{consumer_url_path}/latest" + "#{provider_url_path}/consumer/#{consumer_url_path}/latest" expect(subject.pact_broker_url(split_pact_helper_path)).to eq(contract_url_path) end @@ -73,7 +78,7 @@ RSpec.describe Provider::ContractSourceHelper, feature_category: :not_owned do it 'returns the contract file path with the prefix path for a rake task' do rake_task_relative_path = '/spec/contracts/contracts/project' - rake_task_path = subject.local_contract_location(:rake, split_pact_helper_path) + rake_task_path = subject.local_contract_location(:rake, split_pact_helper_path, :ce) expect(rake_task_path).to include(rake_task_relative_path) expect(rake_task_path).not_to include('../') @@ -82,7 +87,7 @@ RSpec.describe Provider::ContractSourceHelper, feature_category: :not_owned do it 'returns the contract file path with the prefix path for a spec' do spec_relative_path = '../contracts/project' - expect(subject.local_contract_location(:spec, split_pact_helper_path)).to include(spec_relative_path) + expect(subject.local_contract_location(:spec, split_pact_helper_path, :ce)).to include(spec_relative_path) end end |