diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-20 17:22:11 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-20 17:22:11 +0300 |
commit | 0c872e02b2c822e3397515ec324051ff540f0cd5 (patch) | |
tree | ce2fb6ce7030e4dad0f4118d21ab6453e5938cdd /spec/contracts | |
parent | f7e05a6853b12f02911494c4b3fe53d9540d74fc (diff) |
Add latest changes from gitlab-org/gitlab@15-7-stable-eev15.7.0-rc42
Diffstat (limited to 'spec/contracts')
48 files changed, 399 insertions, 217 deletions
diff --git a/spec/contracts/consumer/.node-version b/spec/contracts/consumer/.node-version deleted file mode 100644 index 18711d290ea..00000000000 --- a/spec/contracts/consumer/.node-version +++ /dev/null @@ -1 +0,0 @@ -14.17.5 diff --git a/spec/contracts/consumer/fixtures/project/merge_request/diffs_batch.fixture.js b/spec/contracts/consumer/fixtures/project/merge_requests/diffs_batch.fixture.js index 673aad721b3..673aad721b3 100644 --- a/spec/contracts/consumer/fixtures/project/merge_request/diffs_batch.fixture.js +++ b/spec/contracts/consumer/fixtures/project/merge_requests/diffs_batch.fixture.js diff --git a/spec/contracts/consumer/fixtures/project/merge_request/diffs_metadata.fixture.js b/spec/contracts/consumer/fixtures/project/merge_requests/diffs_metadata.fixture.js index 2fee4a02023..2fee4a02023 100644 --- a/spec/contracts/consumer/fixtures/project/merge_request/diffs_metadata.fixture.js +++ b/spec/contracts/consumer/fixtures/project/merge_requests/diffs_metadata.fixture.js diff --git a/spec/contracts/consumer/fixtures/project/merge_request/discussions.fixture.js b/spec/contracts/consumer/fixtures/project/merge_requests/discussions.fixture.js index 8c392395e1c..8c392395e1c 100644 --- a/spec/contracts/consumer/fixtures/project/merge_request/discussions.fixture.js +++ b/spec/contracts/consumer/fixtures/project/merge_requests/discussions.fixture.js diff --git a/spec/contracts/consumer/fixtures/project/pipeline_schedule/update_pipeline_schedule.fixture.js b/spec/contracts/consumer/fixtures/project/pipeline_schedules/update_pipeline_schedule.fixture.js index acfab14851a..acfab14851a 100644 --- a/spec/contracts/consumer/fixtures/project/pipeline_schedule/update_pipeline_schedule.fixture.js +++ b/spec/contracts/consumer/fixtures/project/pipeline_schedules/update_pipeline_schedule.fixture.js diff --git a/spec/contracts/consumer/fixtures/project/pipeline/create_a_new_pipeline.fixture.js b/spec/contracts/consumer/fixtures/project/pipelines/create_a_new_pipeline.fixture.js index 68063d2fb0c..68063d2fb0c 100644 --- a/spec/contracts/consumer/fixtures/project/pipeline/create_a_new_pipeline.fixture.js +++ b/spec/contracts/consumer/fixtures/project/pipelines/create_a_new_pipeline.fixture.js diff --git a/spec/contracts/consumer/fixtures/project/pipeline/delete_pipeline.fixture.js b/spec/contracts/consumer/fixtures/project/pipelines/delete_pipeline.fixture.js index 2e3e7355b99..2e3e7355b99 100644 --- a/spec/contracts/consumer/fixtures/project/pipeline/delete_pipeline.fixture.js +++ b/spec/contracts/consumer/fixtures/project/pipelines/delete_pipeline.fixture.js diff --git a/spec/contracts/consumer/fixtures/project/pipeline/get_list_project_pipelines.fixture.js b/spec/contracts/consumer/fixtures/project/pipelines/get_list_project_pipelines.fixture.js index a982e927572..a982e927572 100644 --- a/spec/contracts/consumer/fixtures/project/pipeline/get_list_project_pipelines.fixture.js +++ b/spec/contracts/consumer/fixtures/project/pipelines/get_list_project_pipelines.fixture.js diff --git a/spec/contracts/consumer/fixtures/project/pipeline/get_pipeline_header_data.fixture.js b/spec/contracts/consumer/fixtures/project/pipelines/get_pipeline_header_data.fixture.js index b14a230d2e0..b14a230d2e0 100644 --- a/spec/contracts/consumer/fixtures/project/pipeline/get_pipeline_header_data.fixture.js +++ b/spec/contracts/consumer/fixtures/project/pipelines/get_pipeline_header_data.fixture.js diff --git a/spec/contracts/consumer/package.json b/spec/contracts/consumer/package.json index 6d3feaa6d4c..60f268806de 100644 --- a/spec/contracts/consumer/package.json +++ b/spec/contracts/consumer/package.json @@ -22,5 +22,8 @@ "devDependencies": { "@babel/preset-env": "^7.18.2", "babel-jest": "^28.1.1" + }, + "config": { + "pact_do_not_track": true } } diff --git a/spec/contracts/consumer/specs/project/merge_request/show.spec.js b/spec/contracts/consumer/specs/project/merge_requests/show.spec.js index 4183e19435a..fcc0e117e2d 100644 --- a/spec/contracts/consumer/specs/project/merge_request/show.spec.js +++ b/spec/contracts/consumer/specs/project/merge_requests/show.spec.js @@ -1,32 +1,32 @@ import { pactWith } from 'jest-pact'; -import { DiffsBatch } from '../../../fixtures/project/merge_request/diffs_batch.fixture'; -import { Discussions } from '../../../fixtures/project/merge_request/discussions.fixture'; -import { DiffsMetadata } from '../../../fixtures/project/merge_request/diffs_metadata.fixture'; +import { DiffsBatch } from '../../../fixtures/project/merge_requests/diffs_batch.fixture'; +import { Discussions } from '../../../fixtures/project/merge_requests/discussions.fixture'; +import { DiffsMetadata } from '../../../fixtures/project/merge_requests/diffs_metadata.fixture'; import { getDiffsBatch, getDiffsMetadata, getDiscussions, } from '../../../resources/api/project/merge_requests'; -const CONSUMER_NAME = 'MergeRequest#show'; +const CONSUMER_NAME = 'MergeRequests#show'; const CONSUMER_LOG = '../logs/consumer.log'; -const CONTRACT_DIR = '../contracts/project/merge_request/show'; -const DIFFS_BATCH_PROVIDER_NAME = 'Merge Request Diffs Batch Endpoint'; -const DISCUSSIONS_PROVIDER_NAME = 'Merge Request Discussions Endpoint'; -const DIFFS_METADATA_PROVIDER_NAME = 'Merge Request Diffs Metadata Endpoint'; +const CONTRACT_DIR = '../contracts/project/merge_requests/show'; +const GET_DIFFS_BATCH_PROVIDER_NAME = 'GET diffs batch'; +const GET_DISCUSSIONS_PROVIDER_NAME = 'GET discussions'; +const GET_DIFFS_METADATA_PROVIDER_NAME = 'GET diffs metadata'; // API endpoint: /merge_requests/:id/diffs_batch.json pactWith( { consumer: CONSUMER_NAME, - provider: DIFFS_BATCH_PROVIDER_NAME, + provider: GET_DIFFS_BATCH_PROVIDER_NAME, log: CONSUMER_LOG, dir: CONTRACT_DIR, }, (provider) => { - describe(DIFFS_BATCH_PROVIDER_NAME, () => { + describe(GET_DIFFS_BATCH_PROVIDER_NAME, () => { beforeEach(() => { const interaction = { ...DiffsBatch.scenario, @@ -50,13 +50,13 @@ pactWith( pactWith( { consumer: CONSUMER_NAME, - provider: DISCUSSIONS_PROVIDER_NAME, + provider: GET_DISCUSSIONS_PROVIDER_NAME, log: CONSUMER_LOG, dir: CONTRACT_DIR, }, (provider) => { - describe(DISCUSSIONS_PROVIDER_NAME, () => { + describe(GET_DISCUSSIONS_PROVIDER_NAME, () => { beforeEach(() => { const interaction = { ...Discussions.scenario, @@ -80,13 +80,13 @@ pactWith( pactWith( { consumer: CONSUMER_NAME, - provider: DIFFS_METADATA_PROVIDER_NAME, + provider: GET_DIFFS_METADATA_PROVIDER_NAME, log: CONSUMER_LOG, dir: CONTRACT_DIR, }, (provider) => { - describe(DIFFS_METADATA_PROVIDER_NAME, () => { + describe(GET_DIFFS_METADATA_PROVIDER_NAME, () => { beforeEach(() => { const interaction = { ...DiffsMetadata.scenario, diff --git a/spec/contracts/consumer/specs/project/pipeline_schedule/edit.spec.js b/spec/contracts/consumer/specs/project/pipeline_schedules/edit.spec.js index 117e6754255..0924b1b3b3d 100644 --- a/spec/contracts/consumer/specs/project/pipeline_schedule/edit.spec.js +++ b/spec/contracts/consumer/specs/project/pipeline_schedules/edit.spec.js @@ -1,12 +1,12 @@ import { pactWith } from 'jest-pact'; -import { UpdatePipelineSchedule } from '../../../fixtures/project/pipeline_schedule/update_pipeline_schedule.fixture'; +import { UpdatePipelineSchedule } from '../../../fixtures/project/pipeline_schedules/update_pipeline_schedule.fixture'; import { updatePipelineSchedule } from '../../../resources/api/pipeline_schedules'; const CONSUMER_NAME = 'PipelineSchedules#edit'; const CONSUMER_LOG = '../logs/consumer.log'; -const CONTRACT_DIR = '../contracts/project/pipeline_schedule/edit'; -const PROVIDER_NAME = 'PUT Edit a pipeline schedule'; +const CONTRACT_DIR = '../contracts/project/pipeline_schedules/edit'; +const PROVIDER_NAME = 'PUT edit a pipeline schedule'; // API endpoint: /pipelines.json pactWith( diff --git a/spec/contracts/consumer/specs/project/pipeline/index.spec.js b/spec/contracts/consumer/specs/project/pipelines/index.spec.js index 1453435d637..14bad31a763 100644 --- a/spec/contracts/consumer/specs/project/pipeline/index.spec.js +++ b/spec/contracts/consumer/specs/project/pipelines/index.spec.js @@ -1,12 +1,12 @@ import { pactWith } from 'jest-pact'; -import { ProjectPipelines } from '../../../fixtures/project/pipeline/get_list_project_pipelines.fixture'; +import { ProjectPipelines } from '../../../fixtures/project/pipelines/get_list_project_pipelines.fixture'; import { getProjectPipelines } from '../../../resources/api/project/pipelines'; const CONSUMER_NAME = 'Pipelines#index'; const CONSUMER_LOG = '../logs/consumer.log'; -const CONTRACT_DIR = '../contracts/project/pipeline/index'; -const PROVIDER_NAME = 'GET List project pipelines'; +const CONTRACT_DIR = '../contracts/project/pipelines/index'; +const PROVIDER_NAME = 'GET list project pipelines'; // API endpoint: /pipelines.json pactWith( diff --git a/spec/contracts/consumer/specs/project/pipeline/new.spec.js b/spec/contracts/consumer/specs/project/pipelines/new.spec.js index c3824d5979e..9e381a61670 100644 --- a/spec/contracts/consumer/specs/project/pipeline/new.spec.js +++ b/spec/contracts/consumer/specs/project/pipelines/new.spec.js @@ -1,12 +1,12 @@ import { pactWith } from 'jest-pact'; -import { NewProjectPipeline } from '../../../fixtures/project/pipeline/create_a_new_pipeline.fixture'; +import { NewProjectPipeline } from '../../../fixtures/project/pipelines/create_a_new_pipeline.fixture'; import { postProjectPipelines } from '../../../resources/api/project/pipelines'; const CONSUMER_NAME = 'Pipelines#new'; const CONSUMER_LOG = '../logs/consumer.log'; -const CONTRACT_DIR = '../contracts/project/pipeline/new'; -const PROVIDER_NAME = 'POST Create a new pipeline'; +const CONTRACT_DIR = '../contracts/project/pipelines/new'; +const PROVIDER_NAME = 'POST create a new pipeline'; // API endpoint: /pipelines.json pactWith( diff --git a/spec/contracts/consumer/specs/project/pipeline/show.spec.js b/spec/contracts/consumer/specs/project/pipelines/show.spec.js index be6abb78eb5..97ad9dbbc9d 100644 --- a/spec/contracts/consumer/specs/project/pipeline/show.spec.js +++ b/spec/contracts/consumer/specs/project/pipelines/show.spec.js @@ -3,14 +3,14 @@ import { GraphQLInteraction } from '@pact-foundation/pact'; import { extractGraphQLQuery } from '../../../helpers/graphql_query_extractor'; -import { PipelineHeaderData } from '../../../fixtures/project/pipeline/get_pipeline_header_data.fixture'; -import { DeletePipeline } from '../../../fixtures/project/pipeline/delete_pipeline.fixture'; +import { PipelineHeaderData } from '../../../fixtures/project/pipelines/get_pipeline_header_data.fixture'; +import { DeletePipeline } from '../../../fixtures/project/pipelines/delete_pipeline.fixture'; import { getPipelineHeaderDataRequest, deletePipeline } from '../../../resources/graphql/pipelines'; const CONSUMER_NAME = 'Pipelines#show'; const CONSUMER_LOG = '../logs/consumer.log'; -const CONTRACT_DIR = '../contracts/project/pipeline/show'; +const CONTRACT_DIR = '../contracts/project/pipelines/show'; const GET_PIPELINE_HEADER_DATA_PROVIDER_NAME = 'GET pipeline header data'; const DELETE_PIPELINE_PROVIDER_NAME = 'DELETE pipeline'; diff --git a/spec/contracts/contracts/project/merge_request/show/mergerequest#show-merge_request_diffs_batch_endpoint.json b/spec/contracts/contracts/project/merge_requests/show/mergerequests#show-get_diffs_batch.json index 3fa13766766..809a3aeec13 100644 --- a/spec/contracts/contracts/project/merge_request/show/mergerequest#show-merge_request_diffs_batch_endpoint.json +++ b/spec/contracts/contracts/project/merge_requests/show/mergerequests#show-get_diffs_batch.json @@ -1,9 +1,9 @@ { "consumer": { - "name": "MergeRequest#show" + "name": "MergeRequests#show" }, "provider": { - "name": "Merge Request Diffs Batch Endpoint" + "name": "GET diffs batch" }, "interactions": [ { diff --git a/spec/contracts/contracts/project/merge_request/show/mergerequest#show-merge_request_diffs_metadata_endpoint.json b/spec/contracts/contracts/project/merge_requests/show/mergerequests#show-get_diffs_metadata.json index c59a3d55f43..3a7b0707445 100644 --- a/spec/contracts/contracts/project/merge_request/show/mergerequest#show-merge_request_diffs_metadata_endpoint.json +++ b/spec/contracts/contracts/project/merge_requests/show/mergerequests#show-get_diffs_metadata.json @@ -1,9 +1,9 @@ { "consumer": { - "name": "MergeRequest#show" + "name": "MergeRequests#show" }, "provider": { - "name": "Merge Request Diffs Metadata Endpoint" + "name": "GET diffs metadata" }, "interactions": [ { @@ -220,4 +220,4 @@ "version": "2.0.0" } } -} +}
\ No newline at end of file diff --git a/spec/contracts/contracts/project/merge_request/show/mergerequest#show-merge_request_discussions_endpoint.json b/spec/contracts/contracts/project/merge_requests/show/mergerequests#show-get_discussions.json index ecaf9c123af..74f75e7eb7b 100644 --- a/spec/contracts/contracts/project/merge_request/show/mergerequest#show-merge_request_discussions_endpoint.json +++ b/spec/contracts/contracts/project/merge_requests/show/mergerequests#show-get_discussions.json @@ -1,9 +1,9 @@ { "consumer": { - "name": "MergeRequest#show" + "name": "MergeRequests#show" }, "provider": { - "name": "Merge Request Discussions Endpoint" + "name": "GET discussions" }, "interactions": [ { diff --git a/spec/contracts/contracts/project/pipeline_schedule/edit/pipelineschedules#edit-put_edit_a_pipeline_schedule.json b/spec/contracts/contracts/project/pipeline_schedules/edit/pipelineschedules#edit-put_edit_a_pipeline_schedule.json index e0dd68dc230..59feebcfc64 100644 --- a/spec/contracts/contracts/project/pipeline_schedule/edit/pipelineschedules#edit-put_edit_a_pipeline_schedule.json +++ b/spec/contracts/contracts/project/pipeline_schedules/edit/pipelineschedules#edit-put_edit_a_pipeline_schedule.json @@ -3,7 +3,7 @@ "name": "PipelineSchedules#edit" }, "provider": { - "name": "PUT Edit a pipeline schedule" + "name": "PUT edit a pipeline schedule" }, "interactions": [ { diff --git a/spec/contracts/contracts/project/pipeline/index/pipelines#index-get_list_project_pipelines.json b/spec/contracts/contracts/project/pipelines/index/pipelines#index-get_list_project_pipelines.json index 2ebfd1bfdf2..01c6563f76a 100644 --- a/spec/contracts/contracts/project/pipeline/index/pipelines#index-get_list_project_pipelines.json +++ b/spec/contracts/contracts/project/pipelines/index/pipelines#index-get_list_project_pipelines.json @@ -3,7 +3,7 @@ "name": "Pipelines#index" }, "provider": { - "name": "GET List project pipelines" + "name": "GET list project pipelines" }, "interactions": [ { @@ -126,8 +126,7 @@ "committer_name": "John Doe", "committer_email": "jdoe@gitlab.com", "committed_date": "2022-06-10T22:02:10.000+00:00", - "trailers": { - }, + "trailers": {}, "web_url": "https://gitlab.com/gitlab-org/gitlab/-/commit/f559253c514d9ab707c66e", "author": null, "author_gravatar_url": "https://secure.gravatar.com/avatar/d85e45af29611ac2c1395e3c3d6ec5d6?s=80&d=identicon", @@ -141,9 +140,7 @@ "full_name": "GitLab.org / GitLab" }, "triggered_by": null, - "triggered": [ - - ] + "triggered": [] } ], "count": { @@ -198,9 +195,6 @@ "match": "regex", "regex": "^(push|web|trigger|schedule|api|external|pipeline|chat|webide|merge_request_event|external_pull_request_event|parent_pipeline|ondemand_dast_scan|ondemand_dast_validation)$" }, - "$.body.pipelines[*].name": { - "match": "type" - }, "$.body.pipelines[*].created_at": { "match": "regex", "regex": "^\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d\\.\\d+([+-][0-2]\\d(:?[0-5]\\d)?|Z)$" @@ -338,9 +332,6 @@ "$.body.pipelines[*].details.name": { "match": "type" }, - "$.body.pipelines[*].details.event_type_name": { - "match": "type" - }, "$.body.pipelines[*].details.manual_actions": { "min": 1 }, diff --git a/spec/contracts/contracts/project/pipeline/new/pipelines#new-post_create_a_new_pipeline.json b/spec/contracts/contracts/project/pipelines/new/pipelines#new-post_create_a_new_pipeline.json index 4627f0cb0bf..4be6b1e3cab 100644 --- a/spec/contracts/contracts/project/pipeline/new/pipelines#new-post_create_a_new_pipeline.json +++ b/spec/contracts/contracts/project/pipelines/new/pipelines#new-post_create_a_new_pipeline.json @@ -3,7 +3,7 @@ "name": "Pipelines#new" }, "provider": { - "name": "POST Create a new pipeline" + "name": "POST create a new pipeline" }, "interactions": [ { @@ -29,7 +29,7 @@ "matchingRules": { "$.body": { "match": "regex", - "regex": "You are being <a href=\\\"(.)+\\/pipelines\\/[0-9]+\\\">redirected<\\/a>." + "regex": "You are being <a href=\\\"(.)+\\\">redirected<\\/a>." } } } diff --git a/spec/contracts/contracts/project/pipeline/show/pipelines#show-delete_pipeline.json b/spec/contracts/contracts/project/pipelines/show/pipelines#show-delete_pipeline.json index 795c8a6e197..795c8a6e197 100644 --- a/spec/contracts/contracts/project/pipeline/show/pipelines#show-delete_pipeline.json +++ b/spec/contracts/contracts/project/pipelines/show/pipelines#show-delete_pipeline.json diff --git a/spec/contracts/contracts/project/pipeline/show/pipelines#show-get_pipeline_header_data.json b/spec/contracts/contracts/project/pipelines/show/pipelines#show-get_pipeline_header_data.json index 2d775dc0f61..2d775dc0f61 100644 --- a/spec/contracts/contracts/project/pipeline/show/pipelines#show-get_pipeline_header_data.json +++ b/spec/contracts/contracts/project/pipelines/show/pipelines#show-get_pipeline_header_data.json diff --git a/spec/contracts/provider/helpers/contract_source_helper.rb b/spec/contracts/provider/helpers/contract_source_helper.rb new file mode 100644 index 00000000000..5fc2e3ffc0d --- /dev/null +++ b/spec/contracts/provider/helpers/contract_source_helper.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +module Provider + module ContractSourceHelper + QA_PACT_BROKER_HOST = "http://localhost:9292/pacts" + PREFIX_PATHS = { + rake: "../../../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) + raise ArgumentError, 'requester must be :rake or :spec' unless [:rake, :spec].include? requester + + 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) + end + + def pact_broker_url(file_path) + provider_url = "provider/#{construct_provider_url_path(file_path)}" + consumer_url = "consumer/#{construct_consumer_url_path(file_path)}" + + "#{QA_PACT_BROKER_HOST}/#{provider_url}/#{consumer_url}/latest" + end + + def construct_provider_url_path(file_path) + split_name = file_path[2].split('_') + + split_name[0] = split_name[0].upcase + split_name.join("%20") + end + + def construct_consumer_url_path(file_path) + "#{file_path[0].split('_').map(&:capitalize).join}%23#{file_path[1]}" + end + + def local_contract_location(requester, file_path) + contract_path = construct_local_contract_path(file_path) + prefix_path = requester == :rake ? File.expand_path(PREFIX_PATHS[requester], __dir__) : PREFIX_PATHS[requester] + + "#{prefix_path}#{contract_path}" + end + + def construct_local_contract_path(file_path) + contract_file_name = "#{file_path[0].tr('_', '')}##{file_path[1]}-#{file_path[2]}.json" + + "/#{file_path[0]}/#{file_path[1]}/#{contract_file_name}" + end + end + end +end diff --git a/spec/contracts/provider/helpers/publish_contract_helper.rb b/spec/contracts/provider/helpers/publish_contract_helper.rb index 102a73d87ee..ddf1e1fd0ed 100644 --- a/spec/contracts/provider/helpers/publish_contract_helper.rb +++ b/spec/contracts/provider/helpers/publish_contract_helper.rb @@ -2,15 +2,15 @@ module Provider module PublishContractHelper - PROVIDER_VERSION = ENV['GIT_COMMIT'] || `git rev-parse --verify HEAD`.strip - PROVIDER_BRANCH = ENV['GIT_BRANCH'] || `git name-rev --name-only HEAD`.strip + PROVIDER_VERSION = ENV["GIT_COMMIT"] || `git rev-parse --verify HEAD`.strip + PROVIDER_BRANCH = ENV["GIT_BRANCH"] || `git name-rev --name-only HEAD`.strip PUBLISH_FLAG = true def self.publish_contract_setup - @setup ||= -> { - app_version PROVIDER_VERSION - app_version_branch PROVIDER_BRANCH - publish_verification_results PUBLISH_FLAG + ->(app_version, app_version_branch, publish_verification_results) { + app_version.call(PROVIDER_VERSION) + app_version_branch.call(PROVIDER_BRANCH) + publish_verification_results.call(PUBLISH_FLAG) } end end diff --git a/spec/contracts/provider/pact_helpers/project/merge_request/show/diffs_batch_helper.rb b/spec/contracts/provider/pact_helpers/project/merge_request/show/diffs_batch_helper.rb deleted file mode 100644 index 71f302f2c44..00000000000 --- a/spec/contracts/provider/pact_helpers/project/merge_request/show/diffs_batch_helper.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../../../spec_helper' -require_relative '../../../../states/project/merge_request/show_state' - -module Provider - module DiffsBatchHelper - Pact.service_provider "Merge Request Diffs Batch Endpoint" do - app { Environments::Test.app } - - honours_pact_with 'MergeRequest#show' do - pact_uri '../contracts/project/merge_request/show/mergerequest#show-merge_request_diffs_batch_endpoint.json' - end - - Provider::PublishContractHelper.publish_contract_setup.call - end - end -end diff --git a/spec/contracts/provider/pact_helpers/project/merge_request/show/diffs_metadata_helper.rb b/spec/contracts/provider/pact_helpers/project/merge_request/show/diffs_metadata_helper.rb deleted file mode 100644 index 60a3abea5ae..00000000000 --- a/spec/contracts/provider/pact_helpers/project/merge_request/show/diffs_metadata_helper.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../../../spec_helper' -require_relative '../../../../states/project/merge_request/show_state' - -module Provider - module DiffsMetadataHelper - Pact.service_provider "Merge Request Diffs Metadata Endpoint" do - app { Environments::Test.app } - - honours_pact_with 'MergeRequest#show' do - pact_uri '../contracts/project/merge_request/show/mergerequest#show-merge_request_diffs_metadata_endpoint.json' - end - - app_version Provider::PublishContractHelper::PROVIDER_VERSION - app_version_branch Provider::PublishContractHelper::PROVIDER_BRANCH - publish_verification_results Provider::PublishContractHelper::PUBLISH_FLAG - end - end -end diff --git a/spec/contracts/provider/pact_helpers/project/merge_request/show/discussions_helper.rb b/spec/contracts/provider/pact_helpers/project/merge_request/show/discussions_helper.rb deleted file mode 100644 index b9308af0a1a..00000000000 --- a/spec/contracts/provider/pact_helpers/project/merge_request/show/discussions_helper.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../../../spec_helper' -require_relative '../../../../states/project/merge_request/show_state' - -module Provider - module DiscussionsHelper - Pact.service_provider "Merge Request Discussions Endpoint" do - app { Environments::Test.app } - - honours_pact_with 'MergeRequest#show' do - pact_uri '../contracts/project/merge_request/show/mergerequest#show-merge_request_discussions_endpoint.json' - end - - app_version Provider::PublishContractHelper::PROVIDER_VERSION - app_version_branch Provider::PublishContractHelper::PROVIDER_BRANCH - publish_verification_results Provider::PublishContractHelper::PUBLISH_FLAG - end - end -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 new file mode 100644 index 00000000000..aa97a07c07b --- /dev/null +++ b/spec/contracts/provider/pact_helpers/project/merge_requests/show/get_diffs_batch_helper.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +require_relative "../../../../spec_helper" +require_relative "../../../../helpers/contract_source_helper" +require_relative "../../../../helpers/publish_contract_helper" +require_relative "../../../../states/project/merge_requests/show_state" + +module Provider + module DiffsBatchHelper + Pact.service_provider "GET diffs batch" do + app { Environments::Test.app } + + honours_pact_with "MergeRequests#show" do + pact_uri Provider::ContractSourceHelper.contract_location(:spec, __FILE__) + end + + Provider::PublishContractHelper.publish_contract_setup.call( + method(:app_version), + method(:app_version_branch), + method(:publish_verification_results) + ) + end + end +end 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 new file mode 100644 index 00000000000..891585b0066 --- /dev/null +++ b/spec/contracts/provider/pact_helpers/project/merge_requests/show/get_diffs_metadata_helper.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +require_relative "../../../../spec_helper" +require_relative "../../../../helpers/contract_source_helper" +require_relative "../../../../helpers/publish_contract_helper" +require_relative "../../../../states/project/merge_requests/show_state" + +module Provider + module DiffsMetadataHelper + Pact.service_provider "GET diffs metadata" do + app { Environments::Test.app } + + honours_pact_with "MergeRequests#show" do + pact_uri Provider::ContractSourceHelper.contract_location(:spec, __FILE__) + end + + Provider::PublishContractHelper.publish_contract_setup.call( + method(:app_version), + method(:app_version_branch), + method(:publish_verification_results) + ) + end + end +end 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 new file mode 100644 index 00000000000..229818366ca --- /dev/null +++ b/spec/contracts/provider/pact_helpers/project/merge_requests/show/get_discussions_helper.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +require_relative "../../../../spec_helper" +require_relative "../../../../helpers/contract_source_helper" +require_relative "../../../../helpers/publish_contract_helper" +require_relative "../../../../states/project/merge_requests/show_state" + +module Provider + module DiscussionsHelper + Pact.service_provider "GET discussions" do + app { Environments::Test.app } + + honours_pact_with "MergeRequests#show" do + pact_uri Provider::ContractSourceHelper.contract_location(:spec, __FILE__) + end + + Provider::PublishContractHelper.publish_contract_setup.call( + method(:app_version), + method(:app_version_branch), + method(:publish_verification_results) + ) + end + end +end diff --git a/spec/contracts/provider/pact_helpers/project/pipeline/index/create_a_new_pipeline_helper.rb b/spec/contracts/provider/pact_helpers/project/pipeline/index/create_a_new_pipeline_helper.rb deleted file mode 100644 index 2af960bc9fd..00000000000 --- a/spec/contracts/provider/pact_helpers/project/pipeline/index/create_a_new_pipeline_helper.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../../../spec_helper' -require_relative '../../../../states/project/pipeline/new_state' - -module Provider - module CreateNewPipelineHelper - Pact.service_provider "POST Create a new pipeline" do - app { Environments::Test.app } - - honours_pact_with 'Pipelines#new' do - pact_uri '../contracts/project/pipeline/new/pipelines#new-post_create_a_new_pipeline.json' - end - - app_version Provider::PublishContractHelper::PROVIDER_VERSION - app_version_branch Provider::PublishContractHelper::PROVIDER_BRANCH - publish_verification_results Provider::PublishContractHelper::PUBLISH_FLAG - end - end -end diff --git a/spec/contracts/provider/pact_helpers/project/pipeline/index/get_list_project_pipelines_helper.rb b/spec/contracts/provider/pact_helpers/project/pipeline/index/get_list_project_pipelines_helper.rb deleted file mode 100644 index 37cddd1b80e..00000000000 --- a/spec/contracts/provider/pact_helpers/project/pipeline/index/get_list_project_pipelines_helper.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../../../spec_helper' -require_relative '../../../../states/project/pipeline/index_state' - -module Provider - module GetListProjectPipelinesHelper - Pact.service_provider "GET List project pipelines" do - app { Environments::Test.app } - - honours_pact_with 'Pipelines#index' do - pact_uri '../contracts/project/project/pipeline/index/pipelines#index-get_list_project_pipelines.json' - end - - app_version Provider::PublishContractHelper::PROVIDER_VERSION - app_version_branch Provider::PublishContractHelper::PROVIDER_BRANCH - publish_verification_results Provider::PublishContractHelper::PUBLISH_FLAG - end - end -end diff --git a/spec/contracts/provider/pact_helpers/project/pipeline/show/delete_pipeline_helper.rb b/spec/contracts/provider/pact_helpers/project/pipeline/show/delete_pipeline_helper.rb deleted file mode 100644 index 0455281fcd7..00000000000 --- a/spec/contracts/provider/pact_helpers/project/pipeline/show/delete_pipeline_helper.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../../../spec_helper' -require_relative '../../../../helpers/publish_contract_helper' -require_relative '../../../../states/project/pipeline/show_state' - -module Provider - module DeletePipelineHelper - Pact.service_provider "DELETE pipeline" do - app { Environments::Test.app } - - honours_pact_with 'Pipelines#show' do - pact_uri '../contracts/project/pipeline/show/pipelines#show-delete_pipeline.json' - end - - app_version Provider::PublishContractHelper::PROVIDER_VERSION - app_version_branch Provider::PublishContractHelper::PROVIDER_BRANCH - publish_verification_results Provider::PublishContractHelper::PUBLISH_FLAG - end - end -end diff --git a/spec/contracts/provider/pact_helpers/project/pipeline/show/get_pipeline_header_data_helper.rb b/spec/contracts/provider/pact_helpers/project/pipeline/show/get_pipeline_header_data_helper.rb deleted file mode 100644 index bce1c4ab3f4..00000000000 --- a/spec/contracts/provider/pact_helpers/project/pipeline/show/get_pipeline_header_data_helper.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../../../spec_helper' -require_relative '../../../../helpers/publish_contract_helper' -require_relative '../../../../states/project/pipeline/show_state' - -module Provider - module GetPipelinesHeaderDataHelper - Pact.service_provider "GET pipeline header data" do - app { Environments::Test.app } - - honours_pact_with 'Pipelines#show' do - pact_uri '../contracts/project/pipeline/show/pipelines#show-get_project_pipeline_header_data.json' - # pact_uri 'http://localhost:9292/pacts/provider/GET%20pipeline%20header%20data/consumer/Pipelines%23show/latest' - end - - app_version Provider::PublishContractHelper::PROVIDER_VERSION - app_version_branch Provider::PublishContractHelper::PROVIDER_BRANCH - publish_verification_results Provider::PublishContractHelper::PUBLISH_FLAG - end - end -end diff --git a/spec/contracts/provider/pact_helpers/project/pipeline_schedule/update_pipeline_schedule_helper.rb b/spec/contracts/provider/pact_helpers/project/pipeline_schedule/update_pipeline_schedule_helper.rb deleted file mode 100644 index d95a09abd8d..00000000000 --- a/spec/contracts/provider/pact_helpers/project/pipeline_schedule/update_pipeline_schedule_helper.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../../spec_helper' -require_relative '../../../states/project/pipeline_schedule/edit_state' - -module Provider - module CreateNewPipelineHelper - Pact.service_provider "PUT Edit a pipeline schedule" do - app { Environments::Test.app } - - honours_pact_with 'PipelineSchedule#edit' do - pact_uri '../contracts/project/pipeline_schedule/edit/pipelineschedules#edit-put_edit_a_pipeline_schedule.json' - end - - app_version Provider::PublishContractHelper::PROVIDER_VERSION - app_version_branch Provider::PublishContractHelper::PROVIDER_BRANCH - publish_verification_results Provider::PublishContractHelper::PUBLISH_FLAG - end - end -end 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 new file mode 100644 index 00000000000..62702fd5f92 --- /dev/null +++ b/spec/contracts/provider/pact_helpers/project/pipeline_schedules/edit/put_edit_a_pipeline_schedule_helper.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +require_relative "../../../../spec_helper" +require_relative "../../../../helpers/contract_source_helper" +require_relative "../../../../helpers/publish_contract_helper" +require_relative "../../../../states/project/pipeline_schedules/edit_state" + +module Provider + module CreateNewPipelineHelper + Pact.service_provider "PUT edit a pipeline schedule" do + app { Environments::Test.app } + + honours_pact_with "PipelineSchedules#edit" do + pact_uri Provider::ContractSourceHelper.contract_location(:spec, __FILE__) + end + + Provider::PublishContractHelper.publish_contract_setup.call( + method(:app_version), + method(:app_version_branch), + method(:publish_verification_results) + ) + end + end +end 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 new file mode 100644 index 00000000000..03708db2eb2 --- /dev/null +++ b/spec/contracts/provider/pact_helpers/project/pipelines/index/get_list_project_pipelines_helper.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +require_relative "../../../../spec_helper" +require_relative "../../../../helpers/contract_source_helper" +require_relative "../../../../helpers/publish_contract_helper" +require_relative "../../../../states/project/pipelines/index_state" + +module Provider + module GetListProjectPipelinesHelper + Pact.service_provider "GET list project pipelines" do + app { Environments::Test.app } + + honours_pact_with "Pipelines#index" do + pact_uri Provider::ContractSourceHelper.contract_location(:spec, __FILE__) + end + + Provider::PublishContractHelper.publish_contract_setup.call( + method(:app_version), + method(:app_version_branch), + method(:publish_verification_results) + ) + end + end +end 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 new file mode 100644 index 00000000000..53e5ab61a20 --- /dev/null +++ b/spec/contracts/provider/pact_helpers/project/pipelines/new/post_create_a_new_pipeline_helper.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +require_relative "../../../../spec_helper" +require_relative "../../../../helpers/contract_source_helper" +require_relative "../../../../helpers/publish_contract_helper" +require_relative "../../../../states/project/pipelines/new_state" + +module Provider + module CreateNewPipelineHelper + Pact.service_provider "POST create a new pipeline" do + app { Environments::Test.app } + + honours_pact_with "Pipelines#new" do + pact_uri Provider::ContractSourceHelper.contract_location(:spec, __FILE__) + end + + Provider::PublishContractHelper.publish_contract_setup.call( + method(:app_version), + method(:app_version_branch), + method(:publish_verification_results) + ) + end + end +end 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 new file mode 100644 index 00000000000..1801e989c99 --- /dev/null +++ b/spec/contracts/provider/pact_helpers/project/pipelines/show/delete_pipeline_helper.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +require_relative "../../../../spec_helper" +require_relative "../../../../helpers/contract_source_helper" +require_relative "../../../../helpers/publish_contract_helper" +require_relative "../../../../states/project/pipelines/show_state" + +module Provider + module DeletePipelineHelper + Pact.service_provider "DELETE pipeline" do + app { Environments::Test.app } + + honours_pact_with "Pipelines#show" do + pact_uri Provider::ContractSourceHelper.contract_location(:spec, __FILE__) + end + + Provider::PublishContractHelper.publish_contract_setup.call( + method(:app_version), + method(:app_version_branch), + method(:publish_verification_results) + ) + end + end +end 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 new file mode 100644 index 00000000000..1f3ba9dd007 --- /dev/null +++ b/spec/contracts/provider/pact_helpers/project/pipelines/show/get_pipeline_header_data_helper.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +require_relative "../../../../spec_helper" +require_relative "../../../../helpers/contract_source_helper" +require_relative "../../../../helpers/publish_contract_helper" +require_relative "../../../../states/project/pipelines/show_state" + +module Provider + module GetPipelinesHeaderDataHelper + Pact.service_provider "GET pipeline header data" do + app { Environments::Test.app } + + honours_pact_with "Pipelines#show" do + pact_uri Provider::ContractSourceHelper.contract_location(:spec, __FILE__) + end + + Provider::PublishContractHelper.publish_contract_setup.call( + method(:app_version), + method(:app_version_branch), + method(:publish_verification_results) + ) + end + end +end diff --git a/spec/contracts/provider/spec_helper.rb b/spec/contracts/provider/spec_helper.rb index 6009d6524e1..44e4d29c18e 100644 --- a/spec/contracts/provider/spec_helper.rb +++ b/spec/contracts/provider/spec_helper.rb @@ -3,6 +3,13 @@ require 'spec_helper' require 'zeitwerk' require_relative 'helpers/users_helper' +require_relative('../../../ee/spec/contracts/provider/spec_helper') if Gitlab.ee? +require Rails.root.join("spec/support/helpers/rails_helpers.rb") +require Rails.root.join("spec/support/helpers/stub_env.rb") + +# Opt out of telemetry collection. We can't allow all engineers, and users who install GitLab from source, to be +# automatically enrolled in sending data on their usage without their knowledge. +ENV['PACT_DO_NOT_TRACK'] = 'true' RSpec.configure do |config| config.include Devise::Test::IntegrationHelpers @@ -19,6 +26,8 @@ end Pact.configure do |config| config.include FactoryBot::Syntax::Methods + config.include RailsHelpers + config.include StubENV end module SpecHelper diff --git a/spec/contracts/provider/states/project/merge_request/show_state.rb b/spec/contracts/provider/states/project/merge_requests/show_state.rb index 46f322f723a..ecb6784db1e 100644 --- a/spec/contracts/provider/states/project/merge_request/show_state.rb +++ b/spec/contracts/provider/states/project/merge_requests/show_state.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -Pact.provider_states_for "MergeRequest#show" do +Pact.provider_states_for "MergeRequests#show" do provider_state "a merge request with diffs exists" do set_up do user = User.find_by(name: Provider::UsersHelper::CONTRACT_USER_NAME) diff --git a/spec/contracts/provider/states/project/pipeline_schedule/edit_state.rb b/spec/contracts/provider/states/project/pipeline_schedules/edit_state.rb index 4ee714f15f3..4ee714f15f3 100644 --- a/spec/contracts/provider/states/project/pipeline_schedule/edit_state.rb +++ b/spec/contracts/provider/states/project/pipeline_schedules/edit_state.rb diff --git a/spec/contracts/provider/states/project/pipeline/index_state.rb b/spec/contracts/provider/states/project/pipelines/index_state.rb index 639c25e9894..639c25e9894 100644 --- a/spec/contracts/provider/states/project/pipeline/index_state.rb +++ b/spec/contracts/provider/states/project/pipelines/index_state.rb diff --git a/spec/contracts/provider/states/project/pipeline/new_state.rb b/spec/contracts/provider/states/project/pipelines/new_state.rb index 95914180bec..95914180bec 100644 --- a/spec/contracts/provider/states/project/pipeline/new_state.rb +++ b/spec/contracts/provider/states/project/pipelines/new_state.rb diff --git a/spec/contracts/provider/states/project/pipeline/show_state.rb b/spec/contracts/provider/states/project/pipelines/show_state.rb index 3365647cd13..3365647cd13 100644 --- a/spec/contracts/provider/states/project/pipeline/show_state.rb +++ b/spec/contracts/provider/states/project/pipelines/show_state.rb 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..8bb3b577135 --- /dev/null +++ b/spec/contracts/provider_specs/helpers/provider/contract_source_helper_spec.rb @@ -0,0 +1,96 @@ +# 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 = '/spec/contracts/contracts/project' + + rake_task_path = subject.local_contract_location(:rake, split_pact_helper_path) + + expect(rake_task_path).to include(rake_task_relative_path) + expect(rake_task_path).not_to include('../') + end + + 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) + 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 |