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

Introduces PUT pipeline schedule consumer

上级 6035a970
No related branches found
No related tags found
无相关合并请求
显示
241 个添加9 个删除
......@@ -28,14 +28,14 @@ Before running the consumer tests, go to `spec/contracts/consumer` and run `npm
### Run the provider tests
Before running the provider tests, make sure your GDK (GitLab Development Kit) is fully set up and running. You can follow the setup instructions detailed in the [GDK repository](https://gitlab.com/gitlab-org/gitlab-development-kit/-/tree/main). To run the provider tests, you use Rake tasks that are defined in [`./lib/tasks/contracts.rake`](https://gitlab.com/gitlab-org/gitlab/-/tree/master/lib/tasks/contracts.rake). To get a list of all the Rake tasks related to the provider tests, run `bundle exec rake -T contracts`. For example:
Before running the provider tests, make sure your GDK (GitLab Development Kit) is fully set up and running. You can follow the setup instructions detailed in the [GDK repository](https://gitlab.com/gitlab-org/gitlab-development-kit/-/tree/main). To run the provider tests, you use Rake tasks that can be found in [`./lib/tasks/contracts`](https://gitlab.com/gitlab-org/gitlab/-/tree/master/lib/tasks/contracts). To get a list of all the Rake tasks related to the provider tests, run `bundle exec rake -T contracts`. For example:
```shell
$ bundle exec rake -T contracts
rake contracts:mr:pact:verify:diffs # Verify provider against the consumer pacts for diffs
rake contracts:mr:pact:verify:discussions # Verify provider against the consumer pacts for discussions
rake contracts:mr:pact:verify:metadata # Verify provider against the consumer pacts for metadata
rake contracts:mr:test:merge_request[contract_mr] # Run all merge request contract tests
rake contracts:merge_requests:pact:verify:diffs_batch # Verify provider against the consumer pacts for diffs_batch
rake contracts:merge_requests:pact:verify:diffs_metadata # Verify provider against the consumer pacts for diffs_metadata
rake contracts:merge_requests:pact:verify:discussions # Verify provider against the consumer pacts for discussions
rake contracts:merge_requests:test:merge_requests[contract_merge_requests] # Run all merge request contract tests
```
## Test suite folder structure and naming conventions
......
......@@ -33,9 +33,9 @@ namespace :contracts do
end
desc 'Run all merge request contract tests'
task 'test:merge_requests', :contract_mr do |_t, arg|
task 'test:merge_requests', :contract_merge_requests do |_t, arg|
errors = %w[diffs_batch diffs_metadata discussions].each_with_object([]) do |task, err|
Rake::Task["contracts:mr:pact:verify:#{task}"].execute
Rake::Task["contracts:merge_requests:pact:verify:#{task}"].execute
rescue StandardError, SystemExit
err << "contracts:merge_requests:pact:verify:#{task}"
end
......
# frozen_string_literal: true
return if Rails.env.production?
require 'pact/tasks/verification_task'
contracts = File.expand_path('../../../spec/contracts/contracts/project/pipeline_schedule', __dir__)
provider = File.expand_path('../../../provider', contracts)
# rubocop:disable Rails/RakeEnvironment
namespace :contracts do
namespace :pipeline_schedules do
Pact::VerificationTask.new(:update_pipeline_schedule) do |pact|
pact.uri(
"#{contracts}/edit/pipelineschedules#edit-put_edit_a_pipeline_schedule.json",
pact_helper: "#{provider}/pact_helpers/project/pipeline_schedule/update_pipeline_schedule_helper.rb"
)
end
desc 'Run all pipeline schedule contract tests'
task 'test:pipeline_schedules', :contract_pipeline_schedules do |_t, arg|
errors = %w[
update_pipeline_schedule
].each_with_object([]) do |task, err|
Rake::Task["contracts:pipeline_schedules:pact:verify:#{task}"].execute
rescue StandardError, SystemExit
err << "contracts:pipeline_schedule:pact:verify:#{task}"
end
raise StandardError, "Errors in tasks #{errors.join(', ')}" unless errors.empty?
end
end
end
# rubocop:enable Rails/RakeEnvironment
......@@ -39,7 +39,7 @@ namespace :contracts do
end
desc 'Run all pipeline contract tests'
task 'test:pipelines', :contract_mr do |_t, arg|
task 'test:pipelines', :contract_pipelines do |_t, arg|
errors = %w[
create_a_new_pipeline
get_list_project_pipelines
......
/* eslint-disable @gitlab/require-i18n-strings */
import { Matchers } from '@pact-foundation/pact';
import { REDIRECT_HTML } from '../../../helpers/common_regex_patterns';
const body = Matchers.term({
matcher: REDIRECT_HTML,
generate:
'<html><body>You are being <a href="http://example.org/gitlab-org/gitlab-qa/-/pipelines/5">redirected</a>.</body></html>',
});
const UpdatePipelineSchedule = {
success: {
status: 302,
headers: {
'Content-Type': 'text/html; charset=utf-8',
},
body,
},
scenario: {
state: 'a project with a pipeline schedule exists',
uponReceiving: 'a request to edit a pipeline schedule',
},
request: {
withRequest: {
method: 'PUT',
path: '/gitlab-org/gitlab-qa/-/pipeline_schedules/25',
headers: {
Accept: '*/*',
'Content-Type': 'application/json; charset=utf-8',
},
body: {
schedule: {
description: 'bar',
cron: '0 1 * * *',
cron_timezone: 'UTC',
active: true,
},
},
},
},
};
export { UpdatePipelineSchedule };
/* eslint-enable @gitlab/require-i18n-strings */
......@@ -3,7 +3,7 @@
*/
export const URL = '^(http|https)://[a-z0-9]+([-.]{1}[a-z0-9]+)*.[a-z]{2,5}(:[0-9]{1,5})?(/.*)?$';
export const URL_PATH = '^/[a-zA-Z0-9#-=?_]+$';
export const REDIRECT_HTML = 'You are being <a href=\\"(.)+/pipelines/[0-9]+\\">redirected</a>.';
export const REDIRECT_HTML = 'You are being <a href=\\"(.)+\\">redirected</a>.';
// Pipelines
export const PIPELINE_GROUPS =
......
import axios from 'axios';
export async function updatePipelineSchedule(endpoint) {
const { url } = endpoint;
return axios({
method: 'PUT',
baseURL: url,
url: '/gitlab-org/gitlab-qa/-/pipeline_schedules/25',
headers: {
Accept: '*/*',
'Content-Type': 'application/json; charset=utf-8',
},
data: {
schedule: {
description: 'bar',
cron: '0 1 * * *',
cron_timezone: 'UTC',
active: true,
},
},
validateStatus: (status) => {
return status === 302;
},
});
}
/* eslint-disable @gitlab/require-i18n-strings */
import { pactWith } from 'jest-pact';
import { UpdatePipelineSchedule } from '../../../fixtures/project/pipeline_schedule/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';
// API endpoint: /pipelines.json
pactWith(
{
consumer: CONSUMER_NAME,
provider: PROVIDER_NAME,
log: CONSUMER_LOG,
dir: CONTRACT_DIR,
},
(provider) => {
describe(PROVIDER_NAME, () => {
beforeEach(() => {
const interaction = {
...UpdatePipelineSchedule.scenario,
...UpdatePipelineSchedule.request,
willRespondWith: UpdatePipelineSchedule.success,
};
provider.addInteraction(interaction);
});
it('returns a successful body', async () => {
const pipelineSchedule = await updatePipelineSchedule({
url: provider.mockService.baseUrl,
});
expect(pipelineSchedule.status).toEqual(UpdatePipelineSchedule.success.status);
});
});
},
);
/* eslint-enable @gitlab/require-i18n-strings */
{
"consumer": {
"name": "PipelineSchedules#edit"
},
"provider": {
"name": "PUT Edit a pipeline schedule"
},
"interactions": [
{
"description": "a request to edit a pipeline schedule",
"providerState": "a project with a pipeline schedule exists",
"request": {
"method": "PUT",
"path": "/gitlab-org/gitlab-qa/-/pipeline_schedules/25",
"headers": {
"Accept": "*/*",
"Content-Type": "application/json; charset=utf-8"
},
"body": {
"schedule": {
"description": "bar",
"cron": "0 1 * * *",
"cron_timezone": "UTC",
"active": true
}
}
},
"response": {
"status": 302,
"headers": {
"Content-Type": "text/html; charset=utf-8"
},
"body": "<html><body>You are being <a href=\"http://example.org/gitlab-org/gitlab-qa/-/pipelines/5\">redirected</a>.</body></html>",
"matchingRules": {
"$.body": {
"match": "regex",
"regex": "You are being <a href=\\\"(.)+\\\">redirected<\\/a>."
}
}
}
}
],
"metadata": {
"pactSpecification": {
"version": "2.0.0"
}
}
}
\ No newline at end of file
# 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
end
end
end
# frozen_string_literal: true
Pact.provider_states_for "PipelineSchedules#edit" do
provider_state "a project with a pipeline schedule exists" do
set_up do
user = User.find_by(name: Provider::UsersHelper::CONTRACT_USER_NAME)
namespace = create(:namespace, name: 'gitlab-org')
project = create(:project, :repository, name: 'gitlab-qa', namespace: namespace, creator: user)
project.add_maintainer(user)
create(:ci_pipeline_schedule, id: 25, project: project, owner: user)
end
end
end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册