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>2023-03-21 21:15:17 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-03-21 21:15:17 +0300
commit248492cc573e85aea19d7493c3a15d459be016c5 (patch)
treec25388f4af2e9a87e06121318982001b964e7573 /spec/scripts
parent97a128c1d1bf45bcc00d5fae037f840eff1ae4e0 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/scripts')
-rw-r--r--spec/scripts/create_pipeline_failure_incident_spec.rb46
-rw-r--r--spec/scripts/generate_failed_pipeline_slack_message_spec.rb81
-rw-r--r--spec/scripts/review_apps/automated_cleanup_spec.rb48
3 files changed, 173 insertions, 2 deletions
diff --git a/spec/scripts/create_pipeline_failure_incident_spec.rb b/spec/scripts/create_pipeline_failure_incident_spec.rb
index 8549cec1b12..efbd22ccb32 100644
--- a/spec/scripts/create_pipeline_failure_incident_spec.rb
+++ b/spec/scripts/create_pipeline_failure_incident_spec.rb
@@ -15,7 +15,7 @@ RSpec.describe CreatePipelineFailureIncident, feature_category: :tooling do
let(:options) do
{
- project: 1234,
+ project: 'gitlab-org/gitlab-test-project',
api_token: 'asdf1234'
}
end
@@ -104,7 +104,6 @@ RSpec.describe CreatePipelineFailureIncident, feature_category: :tooling do
end
context 'when other branch' do
- let(:incident_labels) { ['Engineering Productivity', 'master-broken::undetermined', 'master:broken'] }
let(:title) { /broken `master`/ }
let(:description) { /Follow the \[Broken `master` handbook guide\]/ }
@@ -114,6 +113,49 @@ RSpec.describe CreatePipelineFailureIncident, feature_category: :tooling do
)
end
+ context 'when GitLab FOSS' do
+ let(:incident_labels) { ['master:foss-broken', 'Engineering Productivity', 'master-broken::undetermined'] }
+
+ before do
+ stub_env(
+ 'CI_PROJECT_NAME' => 'gitlab-foss'
+ )
+ end
+
+ it_behaves_like 'creating an issue'
+ end
+
+ context 'when GitLab EE' do
+ let(:incident_labels) { ['master:broken', 'Engineering Productivity', 'master-broken::undetermined'] }
+
+ before do
+ stub_env(
+ 'CI_PROJECT_NAME' => 'gitlab'
+ )
+ end
+
+ it_behaves_like 'creating an issue'
+ end
+ end
+
+ context 'when review-apps' do
+ let(:options) do
+ {
+ project: 'gitlab-org/quality/engineering-productivity/review-apps-broken-incidents',
+ api_token: 'asdf1234'
+ }
+ end
+
+ let(:incident_labels) { ["review-apps-broken", "Engineering Productivity", "ep::review-apps"] }
+ let(:title) { /broken `my-branch`/ }
+ let(:description) { /Please refer to \[the review-apps triaging process\]/ }
+
+ before do
+ stub_env(
+ 'CI_COMMIT_REF_NAME' => 'my-branch'
+ )
+ end
+
it_behaves_like 'creating an issue'
end
end
diff --git a/spec/scripts/generate_failed_pipeline_slack_message_spec.rb b/spec/scripts/generate_failed_pipeline_slack_message_spec.rb
new file mode 100644
index 00000000000..2418116e694
--- /dev/null
+++ b/spec/scripts/generate_failed_pipeline_slack_message_spec.rb
@@ -0,0 +1,81 @@
+# frozen_string_literal: true
+
+require 'fast_spec_helper'
+require_relative '../../scripts/generate-failed-pipeline-slack-message'
+require_relative '../support/helpers/stub_env'
+
+RSpec.describe GenerateFailedPipelineSlackMessage, feature_category: :tooling do
+ include StubENV
+
+ describe '#execute' do
+ let(:create_issue) { instance_double(CreateIssue) }
+ let(:issue) { double('Issue', iid: 1) } # rubocop:disable RSpec/VerifiedDoubles
+ let(:create_issue_discussion) { instance_double(CreateIssueDiscussion, execute: true) }
+ let(:failed_jobs) { instance_double(PipelineFailedJobs, execute: []) }
+
+ let(:project_path) { 'gitlab-org/gitlab-test-project' }
+ let(:options) do
+ {
+ project: project_path,
+ incident_json_file: 'incident_json_file_tests.json'
+ }
+ end
+
+ subject { described_class.new(options).execute }
+
+ before do
+ stub_env(
+ 'CI_COMMIT_REF_NAME' => 'my-branch',
+ 'CI_COMMIT_SHA' => 'bfcd2b9b5cad0b889494ce830697392c8ca11257',
+ 'CI_COMMIT_TITLE' => 'Commit title',
+ 'CI_PIPELINE_CREATED_AT' => '2023-01-24 00:00:00',
+ 'CI_PIPELINE_ID' => '1234567',
+ 'CI_PIPELINE_SOURCE' => 'push',
+ 'CI_PIPELINE_URL' => 'https://gitlab.com/gitlab-org/gitlab/-/pipelines/1234567',
+ 'CI_PROJECT_PATH' => 'gitlab.com/gitlab-org/gitlab',
+ 'CI_PROJECT_URL' => 'https://gitlab.com/gitlab-org/gitlab',
+ 'CI_SERVER_URL' => 'https://gitlab.com',
+ 'GITLAB_USER_ID' => '1111',
+ 'GITLAB_USER_LOGIN' => 'foo',
+ 'GITLAB_USER_NAME' => 'Foo User',
+ 'PROJECT_TOKEN_FOR_CI_SCRIPTS_API_USAGE' => 'asdf1234',
+ 'SLACK_CHANNEL' => '#a-slack-channel'
+ )
+
+ allow(PipelineFailedJobs).to receive(:new)
+ .with(API::DEFAULT_OPTIONS.merge(exclude_allowed_to_fail_jobs: true))
+ .and_return(failed_jobs)
+ end
+
+ it 'returns the correct keys' do
+ expect(subject.keys).to match_array([:channel, :username, :icon_emoji, :text, :blocks])
+ end
+
+ it 'returns the correct channel' do
+ expect(subject[:channel]).to eq('#a-slack-channel')
+ end
+
+ it 'returns the correct username' do
+ expect(subject[:username]).to eq('Failed pipeline reporter')
+ end
+
+ it 'returns the correct icon_emoji' do
+ expect(subject[:icon_emoji]).to eq(':boom:')
+ end
+
+ it 'returns the correct text' do
+ expect(subject[:text]).to eq(
+ '*<https://gitlab.com/gitlab-org/gitlab|gitlab.com/gitlab-org/gitlab> pipeline ' \
+ '<https://gitlab.com/gitlab-org/gitlab/-/pipelines/1234567|#1234567> failed*'
+ )
+ end
+
+ it 'returns the correct incident button link' do
+ block_with_incident_link = subject[:blocks].detect { |block| block.key?(:accessory) }
+
+ expect(block_with_incident_link[:accessory][:url]).to eq(
+ "https://gitlab.com/#{project_path}/-/issues/new?issuable_template=incident&issue%5Bissue_type%5D=incident"
+ )
+ end
+ end
+end
diff --git a/spec/scripts/review_apps/automated_cleanup_spec.rb b/spec/scripts/review_apps/automated_cleanup_spec.rb
index 4b6016760dc..40cf0a8bf75 100644
--- a/spec/scripts/review_apps/automated_cleanup_spec.rb
+++ b/spec/scripts/review_apps/automated_cleanup_spec.rb
@@ -76,6 +76,54 @@ RSpec.describe ReviewApps::AutomatedCleanup, feature_category: :tooling do
end
end
+ describe '.parse_args' do
+ subject { described_class.parse_args(argv) }
+
+ context 'when no arguments are provided' do
+ let(:argv) { %w[] }
+
+ it 'returns the default options' do
+ expect(subject).to eq(dry_run: false)
+ end
+ end
+
+ describe '--dry-run' do
+ context 'when no DRY_RUN variable is provided' do
+ let(:argv) { ['--dry-run='] }
+
+ # This is the default behavior of OptionParser.
+ # We should always pass an environment variable with a value, or not pass the flag at all.
+ it 'raises an error' do
+ expect { subject }.to raise_error(OptionParser::InvalidArgument, 'invalid argument: --dry-run=')
+ end
+ end
+
+ context 'when the DRY_RUN variable is not set to true' do
+ let(:argv) { %w[--dry-run=false] }
+
+ it 'returns the default options' do
+ expect(subject).to eq(dry_run: false)
+ end
+ end
+
+ context 'when the DRY_RUN variable is set to true' do
+ let(:argv) { %w[--dry-run=true] }
+
+ it 'returns the correct dry_run value' do
+ expect(subject).to eq(dry_run: true)
+ end
+ end
+
+ context 'when the short version of the flag is used' do
+ let(:argv) { %w[-d true] }
+
+ it 'returns the correct dry_run value' do
+ expect(subject).to eq(dry_run: true)
+ end
+ end
+ end
+ end
+
describe '#perform_stale_pvc_cleanup!' do
subject { instance.perform_stale_pvc_cleanup!(days: days) }