diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-02 09:08:59 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-02 09:08:59 +0300 |
commit | 5ab92edc77d032261ce105e3fa13355b92f8ed32 (patch) | |
tree | d2628c82859c7c8810481ec54c7d564f2e080b78 /spec/contracts/provider_specs | |
parent | 0409a31740fa29fa1131c0496da16677cb3debe4 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/contracts/provider_specs')
-rw-r--r-- | spec/contracts/provider_specs/helpers/provider/contract_source_helper_spec.rb | 93 |
1 files changed, 93 insertions, 0 deletions
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 new file mode 100644 index 00000000000..8b5ea522641 --- /dev/null +++ b/spec/contracts/provider_specs/helpers/provider/contract_source_helper_spec.rb @@ -0,0 +1,93 @@ +# frozen_string_literal: true + +require 'spec_helper' +require_relative '../../../provider/helpers/contract_source_helper' + +RSpec.describe Provider::ContractSourceHelper, feature_category: :not_owned do + let(:pact_helper_path) { 'pact_helpers/project/pipelines/new/post_create_pipeline_helper.rb' } + let(:split_pact_helper_path) { %w[pipelines new post_create_pipeline] } + let(:provider_url_path) { 'POST%20create%20pipeline' } + let(:consumer_url_path) { 'Pipelines%23new' } + + describe '#contract_location' do + it 'raises an error when an invalid requester is given' do + expect { subject.contract_location(:foo, pact_helper_path) } + .to raise_error(ArgumentError, 'requester must be :rake or :spec') + 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) + + subject.contract_location(:rake, 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) + end + end + + context 'when the PACT_BROKER environment variable is set' do + before do + stub_env('PACT_BROKER', true) + end + + 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) + 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) + end + end + end + + 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" + + expect(subject.pact_broker_url(split_pact_helper_path)).to eq(contract_url_path) + end + end + + describe '#construct_provider_url_path' do + it 'returns the provider url path' do + expect(subject.construct_provider_url_path(split_pact_helper_path)).to eq(provider_url_path) + end + end + + describe '#construct_consumer_url_path' do + it 'returns the consumer url path' do + expect(subject.construct_consumer_url_path(split_pact_helper_path)).to eq(consumer_url_path) + end + end + + describe '#local_contract_location' do + it 'returns the contract file path with the prefix path for a rake task' do + rake_task_relative_path = '/gitlab/spec/contracts/contracts/project' + + expect(subject.local_contract_location(:rake, split_pact_helper_path)).to include(rake_task_relative_path) + end + + it 'returns the contract file path with the prefix path for a spec' do + rake_task_relative_path = '../contracts/project' + + expect(subject.local_contract_location(:spec, split_pact_helper_path)).to include(rake_task_relative_path) + end + end + + describe '#construct_local_contract_path' do + it 'returns the local contract path' do + contract_path = '/pipelines/new/pipelines#new-post_create_pipeline.json' + + expect(subject.construct_local_contract_path(split_pact_helper_path)).to eq(contract_path) + end + end +end |