Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-08-04 00:08:59 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-08-04 00:08:59 +0300
commite643b1a37690e16a3683aea0a3369e9723e17a35 (patch)
tree8f5d606291b2827eafac76b3413fe2793860317e /spec/contracts
parentb9b477a3f1e64590e087cfe2cc21c9d5bd448756 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/contracts')
-rw-r--r--spec/contracts/consumer/fixtures/project/pipeline/create_a_new_pipeline.fixture.js43
-rw-r--r--spec/contracts/consumer/helpers/common_regex_patterns.js1
-rw-r--r--spec/contracts/consumer/resources/api/project/pipelines.js19
-rw-r--r--spec/contracts/consumer/resources/graphql/pipelines.js2
-rw-r--r--spec/contracts/consumer/specs/project/pipeline/new.spec.js45
-rw-r--r--spec/contracts/contracts/project/pipeline/new/pipelines#new-post_create_a_new_pipeline.json43
-rw-r--r--spec/contracts/provider/pact_helpers/project/pipeline/create_a_new_pipeline_helper.rb16
-rw-r--r--spec/contracts/provider/states/project/pipeline/new_state.rb24
8 files changed, 192 insertions, 1 deletions
diff --git a/spec/contracts/consumer/fixtures/project/pipeline/create_a_new_pipeline.fixture.js b/spec/contracts/consumer/fixtures/project/pipeline/create_a_new_pipeline.fixture.js
new file mode 100644
index 00000000000..a732189e6fb
--- /dev/null
+++ b/spec/contracts/consumer/fixtures/project/pipeline/create_a_new_pipeline.fixture.js
@@ -0,0 +1,43 @@
+/* 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 NewProjectPipeline = {
+ success: {
+ status: 302,
+ headers: {
+ 'Content-Type': 'text/html; charset=utf-8',
+ },
+ body,
+ },
+
+ scenario: {
+ state: 'a project with a valid .gitlab-ci.yml configuration exists',
+ uponReceiving: 'a request to create a new pipeline',
+ },
+
+ request: {
+ withRequest: {
+ method: 'POST',
+ path: '/gitlab-org/gitlab-qa/-/pipelines',
+ headers: {
+ Accept: '*/*',
+ 'Content-Type': 'application/json; charset=utf-8',
+ },
+ body: {
+ ref: 'master',
+ },
+ },
+ },
+};
+
+export { NewProjectPipeline };
+
+/* eslint-enable @gitlab/require-i18n-strings */
diff --git a/spec/contracts/consumer/helpers/common_regex_patterns.js b/spec/contracts/consumer/helpers/common_regex_patterns.js
index 664a71ab8a9..2fbb4ea49f8 100644
--- a/spec/contracts/consumer/helpers/common_regex_patterns.js
+++ b/spec/contracts/consumer/helpers/common_regex_patterns.js
@@ -3,6 +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>.';
// Pipelines
export const PIPELINE_GROUPS =
diff --git a/spec/contracts/consumer/resources/api/project/pipelines.js b/spec/contracts/consumer/resources/api/project/pipelines.js
new file mode 100644
index 00000000000..f58a7a5fb0f
--- /dev/null
+++ b/spec/contracts/consumer/resources/api/project/pipelines.js
@@ -0,0 +1,19 @@
+import axios from 'axios';
+
+export async function postProjectPipelines(endpoint) {
+ const { url } = endpoint;
+
+ return axios({
+ method: 'POST',
+ baseURL: url,
+ url: '/gitlab-org/gitlab-qa/-/pipelines',
+ headers: {
+ Accept: '*/*',
+ 'Content-Type': 'application/json; charset=utf-8',
+ },
+ data: { ref: 'master' },
+ validateStatus: (status) => {
+ return status === 302;
+ },
+ });
+}
diff --git a/spec/contracts/consumer/resources/graphql/pipelines.js b/spec/contracts/consumer/resources/graphql/pipelines.js
index b076006af17..48724e15eb8 100644
--- a/spec/contracts/consumer/resources/graphql/pipelines.js
+++ b/spec/contracts/consumer/resources/graphql/pipelines.js
@@ -16,9 +16,9 @@ export async function getPipelineHeaderDataRequest(endpoint) {
};
return axios({
+ method: 'POST',
baseURL: url,
url: '/api/graphql',
- method: 'POST',
headers: { Accept: '*/*' },
data: graphqlQuery,
});
diff --git a/spec/contracts/consumer/specs/project/pipeline/new.spec.js b/spec/contracts/consumer/specs/project/pipeline/new.spec.js
new file mode 100644
index 00000000000..621b31af52d
--- /dev/null
+++ b/spec/contracts/consumer/specs/project/pipeline/new.spec.js
@@ -0,0 +1,45 @@
+/* eslint-disable @gitlab/require-i18n-strings */
+
+import { pactWith } from 'jest-pact';
+
+import { NewProjectPipeline } from '../../../fixtures/project/pipeline/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';
+
+// API endpoint: /pipelines.json
+pactWith(
+ {
+ consumer: CONSUMER_NAME,
+ provider: PROVIDER_NAME,
+ log: CONSUMER_LOG,
+ dir: CONTRACT_DIR,
+ },
+
+ (provider) => {
+ describe(PROVIDER_NAME, () => {
+ beforeEach(async () => {
+ const interaction = {
+ ...NewProjectPipeline.scenario,
+ ...NewProjectPipeline.request,
+ willRespondWith: NewProjectPipeline.success,
+ };
+
+ provider.addInteraction(interaction);
+ });
+
+ it('returns a successful body', async () => {
+ const newPipeline = await postProjectPipelines({
+ url: provider.mockService.baseUrl,
+ });
+
+ expect(newPipeline.status).toEqual(NewProjectPipeline.success.status);
+ });
+ });
+ },
+);
+
+/* eslint-enable @gitlab/require-i18n-strings */
diff --git a/spec/contracts/contracts/project/pipeline/new/pipelines#new-post_create_a_new_pipeline.json b/spec/contracts/contracts/project/pipeline/new/pipelines#new-post_create_a_new_pipeline.json
new file mode 100644
index 00000000000..4627f0cb0bf
--- /dev/null
+++ b/spec/contracts/contracts/project/pipeline/new/pipelines#new-post_create_a_new_pipeline.json
@@ -0,0 +1,43 @@
+{
+ "consumer": {
+ "name": "Pipelines#new"
+ },
+ "provider": {
+ "name": "POST Create a new pipeline"
+ },
+ "interactions": [
+ {
+ "description": "a request to create a new pipeline",
+ "providerState": "a project with a valid .gitlab-ci.yml configuration exists",
+ "request": {
+ "method": "POST",
+ "path": "/gitlab-org/gitlab-qa/-/pipelines",
+ "headers": {
+ "Accept": "*/*",
+ "Content-Type": "application/json; charset=utf-8"
+ },
+ "body": {
+ "ref": "master"
+ }
+ },
+ "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=\\\"(.)+\\/pipelines\\/[0-9]+\\\">redirected<\\/a>."
+ }
+ }
+ }
+ }
+ ],
+ "metadata": {
+ "pactSpecification": {
+ "version": "2.0.0"
+ }
+ }
+} \ No newline at end of file
diff --git a/spec/contracts/provider/pact_helpers/project/pipeline/create_a_new_pipeline_helper.rb b/spec/contracts/provider/pact_helpers/project/pipeline/create_a_new_pipeline_helper.rb
new file mode 100644
index 00000000000..e7d9b1452d3
--- /dev/null
+++ b/spec/contracts/provider/pact_helpers/project/pipeline/create_a_new_pipeline_helper.rb
@@ -0,0 +1,16 @@
+# 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
+ end
+ end
+end
diff --git a/spec/contracts/provider/states/project/pipeline/new_state.rb b/spec/contracts/provider/states/project/pipeline/new_state.rb
new file mode 100644
index 00000000000..95914180bec
--- /dev/null
+++ b/spec/contracts/provider/states/project/pipeline/new_state.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+Pact.provider_states_for "Pipelines#new" do
+ provider_state "a project with a valid .gitlab-ci.yml configuration exists" do
+ set_up do
+ user = User.find_by(name: Provider::UsersHelper::CONTRACT_USER_NAME)
+ namespace = create(:namespace, name: 'gitlab-org')
+ project = create(
+ :project,
+ :custom_repo,
+ name: 'gitlab-qa',
+ namespace: namespace,
+ creator: user,
+ files: {
+ '.gitlab-ci.yml' => <<~YAML
+ test-success:
+ script: echo 'OK'
+ YAML
+ })
+
+ project.add_maintainer(user)
+ end
+ end
+end