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-28 06:16:39 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-03-28 06:16:39 +0300
commit9449a8c94313cd1cbe1c4cad885635aa7e3f6c01 (patch)
treed5a4e91c82bd9ccc3faadbfcad51ac18ca9b5fed /spec/scripts
parent9968d394403ad6601fe8fdf24072fdb1ec08e1a3 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/scripts')
-rw-r--r--spec/scripts/pipeline/create_test_failure_issues_spec.rb174
1 files changed, 55 insertions, 119 deletions
diff --git a/spec/scripts/pipeline/create_test_failure_issues_spec.rb b/spec/scripts/pipeline/create_test_failure_issues_spec.rb
index 9ae18147aaa..fa27727542e 100644
--- a/spec/scripts/pipeline/create_test_failure_issues_spec.rb
+++ b/spec/scripts/pipeline/create_test_failure_issues_spec.rb
@@ -3,19 +3,16 @@
# rubocop:disable RSpec/VerifiedDoubles
require 'fast_spec_helper'
-require 'active_support/testing/time_helpers'
require 'rspec-parameterized'
require_relative '../../../scripts/pipeline/create_test_failure_issues'
RSpec.describe CreateTestFailureIssues, feature_category: :tooling do
describe CreateTestFailureIssue do
- include ActiveSupport::Testing::TimeHelpers
-
let(:env) do
{
- 'CI_JOB_URL' => 'https://gitlab.com/gitlab-org/gitlab/-/jobs/1234',
- 'CI_PIPELINE_URL' => 'https://gitlab.com/gitlab-org/gitlab/-/pipelines/5678'
+ 'CI_JOB_URL' => 'ci_job_url',
+ 'CI_PIPELINE_URL' => 'ci_pipeline_url'
}
end
@@ -39,7 +36,7 @@ RSpec.describe CreateTestFailureIssues, feature_category: :tooling do
{
'name' => test_name,
'file' => test_file,
- 'job_url' => env['CI_JOB_URL']
+ 'job_url' => 'job_url'
}
end
@@ -60,148 +57,87 @@ RSpec.describe CreateTestFailureIssues, feature_category: :tooling do
}
end
- let(:test_id) { Digest::SHA256.hexdigest(failed_test['file'] + failed_test['name'])[0...12] }
- let(:latest_format_issue_title) { "#{failed_test['file']} [test-hash:#{test_id}]" }
-
- around do |example|
- freeze_time { example.run }
- end
-
before do
stub_env(env)
- allow(creator).to receive(:puts)
end
- describe '#upsert' do
- let(:expected_search_payload) do
+ describe '#find' do
+ let(:expected_payload) do
{
- state: :opened,
- search: test_id,
- in: :title,
- per_page: 1
+ state: 'opened',
+ search: "#{failed_test['file']} - ID: #{Digest::SHA256.hexdigest(failed_test['name'])[0...12]}"
}
end
let(:find_issue_stub) { double('FindIssues') }
- let(:issue_stub) { double('Issue', title: latest_format_issue_title, web_url: 'issue_web_url') }
+ let(:issue_stub) { double(title: expected_payload[:title], web_url: 'issue_web_url') }
before do
- allow(File).to receive(:open).and_call_original
- allow(File).to receive(:open).with(File.expand_path(File.join('..', '..', '..', test_file), __dir__))
- .and_return(test_file_stub)
- allow(creator).to receive(:categories_mapping).and_return(categories_mapping)
- allow(creator).to receive(:groups_mapping).and_return(groups_mapping)
+ allow(creator).to receive(:puts)
end
- context 'when no issues are found' do
- let(:expected_description) do
- <<~DESCRIPTION
- ### Test description
-
- `#{failed_test['name']}`
-
- ### Test file path
+ it 'calls FindIssues#execute(payload)' do
+ expect(FindIssues).to receive(:new).with(project: project, api_token: api_token).and_return(find_issue_stub)
+ expect(find_issue_stub).to receive(:execute).with(expected_payload).and_return([issue_stub])
- [`#{failed_test['file']}`](https://gitlab.com/example/gitlab/-/blob/master/#{failed_test['file']})
-
- <!-- Don't add anything after the report list since it's updated automatically -->
- ### Reports (1)
-
- 1. #{Time.new.utc.strftime('%F')}: #{failed_test['job_url']} (#{env['CI_PIPELINE_URL']})
- DESCRIPTION
- end
-
- let(:create_issue_stub) { double('CreateIssue') }
-
- let(:expected_create_payload) do
- {
- title: latest_format_issue_title,
- description: expected_description,
- labels: described_class::DEFAULT_LABELS.map { |label| "wip-#{label}" } + [
- "wip-#{categories_mapping['source_code_management']['label']}",
- "wip-#{groups_mapping['source_code']['label']}"
- ],
- weight: 1
- }
- end
-
- before do
- allow(FindIssues).to receive(:new).with(project: project, api_token: api_token).and_return(find_issue_stub)
- allow(find_issue_stub).to receive(:execute).with(expected_search_payload).and_return([])
- end
-
- it 'calls CreateIssue#execute(payload)' do
- stub_const("#{described_class}::FILE_BASE_URL", 'https://gitlab.com/example/gitlab/-/blob/master/')
-
- expect(CreateIssue).to receive(:new).with(project: project, api_token: api_token)
- .and_return(create_issue_stub)
+ creator.find(failed_test)
+ end
- expect(create_issue_stub).to receive(:execute).with(expected_create_payload).and_return(issue_stub)
+ context 'when no issues are found' do
+ it 'calls FindIssues#execute(payload)' do
+ expect(FindIssues).to receive(:new).with(project: project, api_token: api_token).and_return(find_issue_stub)
+ expect(find_issue_stub).to receive(:execute).with(expected_payload).and_return([])
- creator.upsert(failed_test)
+ creator.find(failed_test)
end
end
+ end
- context 'when issues are found' do
- let(:failed_test_report_line) do
- "1. #{Time.new.utc.strftime('%F')}: #{failed_test['job_url']} (#{env['CI_PIPELINE_URL']})"
- end
-
- let(:latest_format_issue_description) do
- <<~DESCRIPTION
- ### Test description
-
- `#{failed_test['name']}`
-
- ### Test file path
-
- [`#{failed_test['file']}`](https://gitlab.com/example/gitlab/-/blob/master/#{failed_test['file']})
+ describe '#create' do
+ let(:expected_description) do
+ <<~DESCRIPTION
+ ### Full description
- <!-- Don't add anything after the report list since it's updated automatically -->
- ### Reports (1)
+ `#{failed_test['name']}`
- #{failed_test_report_line}
- DESCRIPTION
- end
+ ### File path
- let(:issue_stub) do
- double('Issue', iid: 42, title: issue_title, description: issue_description, web_url: 'issue_web_url')
- end
+ `#{failed_test['file']}`
- let(:update_issue_stub) do
- double('UpdateIssue', description: latest_format_issue_description)
- end
+ <!-- Don't add anything after the report list since it's updated automatically -->
+ ### Reports
- let(:expected_update_payload) do
- {
- description: latest_format_issue_description.sub(/^### Reports.*$/, '### Reports (2)') +
- "\n#{failed_test_report_line}",
- weight: 2
- }
- end
+ - #{failed_test['job_url']} (#{env['CI_PIPELINE_URL']})
+ DESCRIPTION
+ end
- before do
- allow(FindIssues).to receive(:new).with(project: project, api_token: api_token).and_return(find_issue_stub)
- allow(find_issue_stub).to receive(:execute).with(expected_search_payload).and_return([issue_stub])
- end
+ let(:expected_payload) do
+ {
+ title: "#{failed_test['file']} - ID: #{Digest::SHA256.hexdigest(failed_test['name'])[0...12]}",
+ description: expected_description,
+ labels: described_class::DEFAULT_LABELS.map { |label| "wip-#{label}" } + [
+ "wip-#{categories_mapping['source_code_management']['label']}", "wip-#{groups_mapping['source_code']['label']}" # rubocop:disable Layout/LineLength
+ ]
+ }
+ end
- # This shared example can be useful if we want to test migration to a new format in the future
- shared_examples 'existing issue update' do
- it 'calls UpdateIssue#execute(payload)' do
- expect(UpdateIssue).to receive(:new).with(project: project, api_token: api_token)
- .and_return(update_issue_stub)
- expect(update_issue_stub).to receive(:execute).with(42, **expected_update_payload).and_return(issue_stub)
+ let(:create_issue_stub) { double('CreateIssue') }
+ let(:issue_stub) { double(title: expected_payload[:title], web_url: 'issue_web_url') }
- creator.upsert(failed_test)
- end
- end
+ before do
+ allow(creator).to receive(:puts)
+ allow(File).to receive(:open).and_call_original
+ allow(File).to receive(:open).with(File.expand_path(File.join('..', '..', '..', test_file), __dir__))
+ .and_return(test_file_stub)
+ allow(creator).to receive(:categories_mapping).and_return(categories_mapping)
+ allow(creator).to receive(:groups_mapping).and_return(groups_mapping)
+ end
- context 'when issue already has the latest format' do
- let(:issue_description) { latest_format_issue_description }
- let(:issue_title) { latest_format_issue_title }
+ it 'calls CreateIssue#execute(payload)' do
+ expect(CreateIssue).to receive(:new).with(project: project, api_token: api_token).and_return(create_issue_stub)
+ expect(create_issue_stub).to receive(:execute).with(expected_payload).and_return(issue_stub)
- it_behaves_like 'existing issue update'
- end
+ creator.create(failed_test) # rubocop:disable Rails/SaveBang
end
end
end