Skip to content
代码片段 群组 项目
提交 7622ca14 编辑于 作者: Richard Chong's avatar Richard Chong 提交者: Anastasia McDonald
浏览文件

Updates scripts to use environment variables for the broker host

上级 da78600e
No related branches found
No related tags found
无相关合并请求
......@@ -42,11 +42,11 @@ rake contracts:merge_requests:test:merge_requests[contract_merge_requests]
#### Verify the contracts in Pact Broker
By default, the Rake tasks will verify the locally stored contracts. In order to verify the contracts published in the Pact Broker, we need to set the `PACT_BROKER` environment variable to `true`. It is important to point out here that the file path and file name of the provider test is what is used to find the contract in the Pact Broker which is why it is important to make sure the [provider test naming conventions](#provider-naming) are followed.
By default, the Rake tasks will verify the locally stored contracts. In order to verify the contracts published in the Pact Broker, we need to set the `PACT_BROKER` environment variable to `true` and the `QA_PACT_BROKER_HOST` to the URL of the Pact Broker. It is important to point out here that the file path and file name of the provider test is what is used to find the contract in the Pact Broker which is why it is important to make sure the [provider test naming conventions](#provider-naming) are followed.
## Publish contracts to Pact Broker
The contracts generated by the consumer test can be published to a hosted Pact Broker by going to `spec/contracts` and running the `publish-contracts.sh` script.
The contracts generated by the consumer test can be published to a hosted Pact Broker by setting the `QA_PACT_BROKER_HOST` environment variable and running the [`publish-contracts.sh`](https://gitlab.com/gitlab-org/gitlab/-/tree/master/spec/contracts/publish-contracts.sh) script.
## Test suite folder structure and naming conventions
......
......@@ -38,7 +38,7 @@ namespace :contracts do
end
desc 'Run all merge request contract tests'
task 'test:merge_requests', :contract_merge_requests do |_t, arg|
task 'test:merge_requests', :contract_merge_requests do |_t|
errors = %w[get_diffs_batch get_diffs_metadata get_discussions].each_with_object([]) do |task, err|
Rake::Task["contracts:merge_requests:pact:verify:#{task}"].execute
rescue StandardError, SystemExit
......
......@@ -20,7 +20,7 @@ namespace :contracts do
end
desc 'Run all pipeline schedule contract tests'
task 'test:pipeline_schedules', :contract_pipeline_schedules do |_t, arg|
task 'test:pipeline_schedules', :contract_pipeline_schedules do |_t|
errors = %w[
update_pipeline_schedule
].each_with_object([]) do |task, err|
......
......@@ -47,7 +47,7 @@ namespace :contracts do
end
desc 'Run all pipeline contract tests'
task 'test:pipelines', :contract_pipelines do |_t, arg|
task 'test:pipelines', :contract_pipelines do |_t|
errors = %w[
create_a_new_pipeline
get_list_project_pipelines
......
......@@ -2,7 +2,6 @@
module Provider
module ContractSourceHelper
QA_PACT_BROKER_HOST = "http://localhost:9292/pacts"
PREFIX_PATHS = {
rake: {
ce: "../../contracts/project",
......@@ -10,7 +9,7 @@ module ContractSourceHelper
},
spec: "../contracts/project"
}.freeze
SUB_PATH_REGEX = %r{project/(?<file_path>.*?)_helper.rb}.freeze
SUB_PATH_REGEX = %r{project/(?<file_path>.*?)_helper.rb}
class << self
def contract_location(requester:, file_path:, edition: :ce)
......@@ -26,7 +25,7 @@ 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"
"#{ENV['QA_PACT_BROKER_HOST']}/pacts/#{provider_url}/#{consumer_url}/latest"
end
def construct_provider_url_path(file_path)
......
......@@ -54,8 +54,12 @@
end
describe '#pact_broker_url' do
before do
stub_env('QA_PACT_BROKER_HOST', 'http://localhost')
end
it 'returns the full url to the contract that the provider test is verifying' do
contract_url_path = "http://localhost:9292/pacts/provider/" \
contract_url_path = "http://localhost/pacts/provider/" \
"#{provider_url_path}/consumer/#{consumer_url_path}/latest"
expect(subject.pact_broker_url(split_pact_helper_path)).to eq(contract_url_path)
......
LATEST_SHA=$(git rev-parse HEAD)
GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
BROKER_BASE_URL="http://localhost:9292"
cd "${0%/*}" || exit 1
......@@ -18,7 +17,7 @@ function publish_contract () {
for contract in $CONTRACTS
do
printf "\e[32mPublishing %s...\033[0m\n" "$contract"
pact-broker publish "$contract" --consumer-app-version "$LATEST_SHA" --branch "$GIT_BRANCH" --broker-base-url "$BROKER_BASE_URL" --output json
pact-broker publish "$contract" --consumer-app-version "$LATEST_SHA" --branch "$GIT_BRANCH" --broker-base-url "$QA_PACT_BROKER_HOST" --output json
done
if [ ${ERROR} = 1 ]; then
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册