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
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-03-31 22:27:02 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-03-31 22:27:02 +0300
commit44d033747da39826bcf6e50adc26e7130159f90b (patch)
tree9557e682489fc8f776bccb70618927d533edc184 /spec
parenta47a6d6fd56f92497b164d45ff9b53023202c4b1 (diff)
Add latest changes from gitlab-org/gitlab@15-10-stable-ee
Diffstat (limited to 'spec')
-rw-r--r--spec/scripts/api/create_merge_request_discussion_spec.rb40
-rw-r--r--spec/scripts/api/get_package_and_test_job_spec.rb47
-rw-r--r--spec/scripts/generate_failed_package_and_test_mr_message_spec.rb79
-rw-r--r--spec/tooling/danger/stable_branch_spec.rb2
4 files changed, 167 insertions, 1 deletions
diff --git a/spec/scripts/api/create_merge_request_discussion_spec.rb b/spec/scripts/api/create_merge_request_discussion_spec.rb
new file mode 100644
index 00000000000..3867f6532a9
--- /dev/null
+++ b/spec/scripts/api/create_merge_request_discussion_spec.rb
@@ -0,0 +1,40 @@
+# frozen_string_literal: true
+
+require 'fast_spec_helper'
+require_relative '../../../scripts/api/create_merge_request_discussion'
+
+RSpec.describe CreateMergeRequestDiscussion, feature_category: :tooling do
+ describe '#execute' do
+ let(:project_id) { 12345 }
+ let(:iid) { 1 }
+ let(:content) { 'test123' }
+
+ let(:options) do
+ {
+ api_token: 'token',
+ endpoint: 'https://example.gitlab.com',
+ project: project_id,
+ merge_request: {
+ 'iid' => iid
+ }
+ }
+ end
+
+ subject { described_class.new(options).execute(content) }
+
+ it 'requests commit_merge_requests from the gitlab client' do
+ expected_result = true
+ client = double('Gitlab::Client') # rubocop:disable RSpec/VerifiedDoubles
+
+ expect(Gitlab).to receive(:client)
+ .with(endpoint: options[:endpoint], private_token: options[:api_token])
+ .and_return(client)
+
+ expect(client).to receive(:create_merge_request_discussion).with(
+ project_id, iid, body: content
+ ).and_return(expected_result)
+
+ expect(subject).to eq(expected_result)
+ end
+ end
+end
diff --git a/spec/scripts/api/get_package_and_test_job_spec.rb b/spec/scripts/api/get_package_and_test_job_spec.rb
new file mode 100644
index 00000000000..60bb26cbcaf
--- /dev/null
+++ b/spec/scripts/api/get_package_and_test_job_spec.rb
@@ -0,0 +1,47 @@
+# frozen_string_literal: true
+
+require 'fast_spec_helper'
+require_relative '../../../scripts/api/get_package_and_test_job'
+
+RSpec.describe GetPackageAndTestJob, feature_category: :tooling do
+ describe '#execute' do
+ let(:project) { 12345 }
+ let(:pipeline_id) { 1 }
+
+ let(:options) do
+ {
+ api_token: 'token',
+ endpoint: 'https://example.gitlab.com',
+ project: project,
+ pipeline_id: pipeline_id
+ }
+ end
+
+ subject { described_class.new(options).execute }
+
+ it 'requests commit_merge_requests from the gitlab client' do
+ client_result = [
+ { 'name' => 'foo' },
+ { 'name' => 'e2e:package-and-test-ee' },
+ { 'name' => 'bar' }
+ ]
+ client = double('Gitlab::Client') # rubocop:disable RSpec/VerifiedDoubles
+ client_response = double('Gitlab::ClientResponse') # rubocop:disable RSpec/VerifiedDoubles
+
+ expect(Gitlab).to receive(:client)
+ .with(endpoint: options[:endpoint], private_token: options[:api_token])
+ .and_return(client)
+
+ expect(client).to receive(:pipeline_bridges).with(
+ project, pipeline_id, scope: 'failed', per_page: 100
+ ).and_return(client_response)
+
+ expect(client_response).to receive(:auto_paginate)
+ .and_yield(client_result[0])
+ .and_yield(client_result[1])
+ .and_yield(client_result[2])
+
+ expect(subject).to eq(client_result[1])
+ end
+ end
+end
diff --git a/spec/scripts/generate_failed_package_and_test_mr_message_spec.rb b/spec/scripts/generate_failed_package_and_test_mr_message_spec.rb
new file mode 100644
index 00000000000..79e63c95f65
--- /dev/null
+++ b/spec/scripts/generate_failed_package_and_test_mr_message_spec.rb
@@ -0,0 +1,79 @@
+# frozen_string_literal: true
+
+require 'fast_spec_helper'
+require_relative '../../scripts/generate-failed-package-and-test-mr-message'
+require_relative '../support/helpers/stub_env'
+
+RSpec.describe GenerateFailedPackageAndTestMrMessage, feature_category: :tooling do
+ include StubENV
+
+ describe '#execute' do
+ let(:options) do
+ {
+ project: 1234,
+ api_token: 'asdf1234'
+ }
+ end
+
+ let(:commit_merge_request) do
+ {
+ 'author' => {
+ 'id' => '2',
+ 'username' => 'test_user'
+ }
+ }
+ end
+
+ let(:package_and_test_job) do
+ { 'web_url' => 'http://example.com' }
+ end
+
+ let(:merge_request) { instance_double(CommitMergeRequests, execute: [commit_merge_request]) }
+ let(:content) { /The `e2e:package-and-test-ee` job has failed./ }
+ let(:merge_request_discussion_client) { instance_double(CreateMergeRequestDiscussion, execute: true) }
+ let(:package_and_test_job_client) { instance_double(GetPackageAndTestJob, execute: package_and_test_job) }
+
+ subject { described_class.new(options).execute }
+
+ before do
+ stub_env(
+ 'CI_MERGE_REQUEST_SOURCE_BRANCH_SHA' => 'bfcd2b9b5cad0b889494ce830697392c8ca11257',
+ 'CI_PROJECT_ID' => '13083',
+ 'CI_PIPELINE_ID' => '1234567',
+ 'CI_PIPELINE_URL' => 'https://gitlab.com/gitlab-org/gitlab/-/pipelines/1234567',
+ 'PROJECT_TOKEN_FOR_CI_SCRIPTS_API_USAGE' => 'asdf1234'
+ )
+
+ allow(GetPackageAndTestJob).to receive(:new)
+ .with(API::DEFAULT_OPTIONS)
+ .and_return(package_and_test_job_client)
+ end
+
+ context 'when package-and-test fails' do
+ before do
+ allow(CommitMergeRequests).to receive(:new)
+ .with(API::DEFAULT_OPTIONS.merge(sha: ENV['CI_MERGE_REQUEST_SOURCE_BRANCH_SHA']))
+ .and_return(merge_request)
+ end
+
+ it 'successfully creates a discussion' do
+ expect(CreateMergeRequestDiscussion).to receive(:new)
+ .with(API::DEFAULT_OPTIONS.merge(merge_request: commit_merge_request))
+ .and_return(merge_request_discussion_client)
+
+ expect(merge_request_discussion_client).to receive(:execute).with(content)
+
+ expect(subject).to eq(true)
+ end
+ end
+
+ context 'when package-and-test is did not fail' do
+ let(:package_and_test_job_client) { instance_double(GetPackageAndTestJob, execute: nil) }
+
+ it 'does not add a discussion' do
+ expect(CreateMergeRequestDiscussion).not_to receive(:new)
+ expect(subject).to eq(nil)
+ end
+ end
+ end
+end
diff --git a/spec/tooling/danger/stable_branch_spec.rb b/spec/tooling/danger/stable_branch_spec.rb
index b6ec4ad8895..b0a8ab3c132 100644
--- a/spec/tooling/danger/stable_branch_spec.rb
+++ b/spec/tooling/danger/stable_branch_spec.rb
@@ -197,7 +197,7 @@ RSpec.describe Tooling::Danger::StableBranch, feature_category: :delivery do
let(:pipeline_bridges_response) do
[
{
- 'name' => 'e2e:package-and-test',
+ 'name' => 'e2e:package-and-test-ee',
'status' => pipeline_bridge_state,
'downstream_pipeline' => nil
}