summaryrefslogtreecommitdiff
path: root/spec/scripts
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-07-20 15:40:28 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-07-20 15:40:28 +0000
commitb595cb0c1dec83de5bdee18284abe86614bed33b (patch)
tree8c3d4540f193c5ff98019352f554e921b3a41a72 /spec/scripts
parent2f9104a328fc8a4bddeaa4627b595166d24671d0 (diff)
downloadgitlab-ce-b595cb0c1dec83de5bdee18284abe86614bed33b.tar.gz
Add latest changes from gitlab-org/gitlab@15-2-stable-eev15.2.0-rc42
Diffstat (limited to 'spec/scripts')
-rw-r--r--spec/scripts/determine-qa-tests_spec.rb109
-rw-r--r--spec/scripts/lib/glfm/update_example_snapshots_spec.rb47
-rw-r--r--spec/scripts/pipeline_test_report_builder_spec.rb48
3 files changed, 187 insertions, 17 deletions
diff --git a/spec/scripts/determine-qa-tests_spec.rb b/spec/scripts/determine-qa-tests_spec.rb
new file mode 100644
index 00000000000..043eb7f2dc9
--- /dev/null
+++ b/spec/scripts/determine-qa-tests_spec.rb
@@ -0,0 +1,109 @@
+# frozen_string_literal: true
+require 'fast_spec_helper'
+
+load File.expand_path('../../scripts/determine-qa-tests', __dir__)
+
+RSpec.describe 'scripts/determine-qa-tests' do
+ describe DetermineQATests do
+ describe '.execute' do
+ let(:qa_spec_files) do
+ %w[qa/qa/specs/features/browser_ui/1_manage/test1.rb
+ qa/qa/specs/features/browser_ui/1_manage/user/test2.rb]
+ end
+
+ let(:qa_spec_and_non_spec_files) do
+ %w[qa/qa/specs/features/browser_ui/1_manage/test1.rb
+ qa/qa/page/admin/menu.rb]
+ end
+
+ let(:non_qa_files) do
+ %w[rubocop/code_reuse_helpers.rb
+ app/components/diffs/overflow_warning_component.rb]
+ end
+
+ let(:non_qa_and_feature_flag_files) do
+ %w[rubocop/code_reuse_helpers.rb
+ app/components/diffs/overflow_warning_component.rb
+ config/feature_flags/development/access_token_ajax.yml]
+ end
+
+ let(:qa_spec_and_non_qa_files) do
+ %w[rubocop/code_reuse_helpers.rb
+ app/components/diffs/overflow_warning_component.rb
+ qa/qa/specs/features/browser_ui/1_manage/test1.rb]
+ end
+
+ let(:qa_non_spec_and_non_qa_files) do
+ %w[rubocop/code_reuse_helpers.rb
+ app/components/diffs/overflow_warning_component.rb
+ qa/qa/page/admin/menu.rb]
+ end
+
+ shared_examples 'determine qa tests' do
+ context 'when only qa spec files have changed' do
+ it 'returns only the changed qa specs' do
+ subject = described_class.new({ changed_files: qa_spec_files }.merge(labels))
+
+ expect(subject.execute).to eql qa_spec_files.map { |path| path.delete_prefix("qa/") }.join(' ')
+ end
+ end
+
+ context 'when qa spec and non spec files have changed' do
+ it 'does not return any specs' do
+ subject = described_class.new({ changed_files: qa_spec_and_non_spec_files }.merge(labels))
+ expect(subject.execute).to be_nil
+ end
+ end
+
+ context 'when non-qa and feature flag files have changed' do
+ it 'does not return any specs' do
+ subject = described_class.new({ changed_files: non_qa_and_feature_flag_files }.merge(labels))
+ expect(subject.execute).to be_nil
+ end
+ end
+
+ context 'when qa spec and non-qa files have changed' do
+ it 'does not return any specs' do
+ subject = described_class.new({ changed_files: qa_spec_and_non_qa_files }.merge(labels))
+ expect(subject.execute).to be_nil
+ end
+ end
+
+ context 'when qa non-spec and non-qa files have changed' do
+ it 'does not return any specs' do
+ subject = described_class.new({ changed_files: qa_non_spec_and_non_qa_files }.merge(labels))
+ expect(subject.execute).to be_nil
+ end
+ end
+ end
+
+ context 'when a devops label is not specified' do
+ let(:labels) { { mr_labels: ['type::feature'] } }
+
+ it_behaves_like 'determine qa tests'
+
+ context 'when only non-qa files have changed' do
+ it 'does not return any specs' do
+ subject = described_class.new({ changed_files: non_qa_files })
+ expect(subject.execute).to be_nil
+ end
+ end
+ end
+
+ context 'when a devops label is specified' do
+ let(:labels) { { mr_labels: %w[devops::manage type::feature] } }
+
+ it_behaves_like 'determine qa tests'
+
+ context 'when only non-qa files have changed' do
+ it 'returns the specs for the devops label' do
+ subject = described_class.new({ changed_files: non_qa_files }.merge(labels))
+ allow(subject).to receive(:qa_spec_directories_for_devops_stage)
+ .and_return(['qa/qa/specs/features/browser_ui/1_manage/'])
+ expect(subject.execute).to eql 'qa/specs/features/browser_ui/1_manage/'
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/spec/scripts/lib/glfm/update_example_snapshots_spec.rb b/spec/scripts/lib/glfm/update_example_snapshots_spec.rb
index 82ed8563c3a..149a384d31e 100644
--- a/spec/scripts/lib/glfm/update_example_snapshots_spec.rb
+++ b/spec/scripts/lib/glfm/update_example_snapshots_spec.rb
@@ -14,7 +14,7 @@ require_relative '../../../../scripts/lib/glfm/update_example_snapshots'
# This is because the invocation of the full script is slow, because it executes
# two subshells for processing, one which runs a full Rails environment, and one
# which runs a jest test environment. This results in each full run of the script
-# taking between 30-60 seconds. The majority of this is spent loading the Rails environmnent.
+# taking between 30-60 seconds. The majority of this is spent loading the Rails environment.
#
# However, only the `writing html.yml and prosemirror_json.yml` context is used
# to test these slow sub-processes, and it only contains a single example.
@@ -79,6 +79,31 @@ RSpec.describe Glfm::UpdateExampleSnapshots, '#process' do
<div class="extension">
+ ### Motivation
+
+ This is a third-level heading with no examples, as exists in the actual GHFM
+ specification. It exists to drive a fix for a bug where this caused the
+ indexing and ordering to in examples_index.yml to be incorrect.
+
+ ### Another H3
+
+ This is a second consecutive third-level heading. It exists to drive full code coverage
+ for this scenario, although it doesn't (yet) exist in the actual spec.txt.
+
+ ## An H2 with all disabled examples
+
+ In the GHFM specification, the 'Task list items (extension)' contains only "disabled"
+ examples, which are ignored by the GitHub fork of `spec_test.py`, and thus not part of the
+ Markdown conformance tests, but are part of the HTML-rendered version of the specification.
+ We also exclude them from our GLFM specification for consistency, but we may add
+ GitLab-specific examples for the behavior instead.
+
+ ```````````````````````````````` example disabled
+ this example is disabled during conformance testing
+ .
+ <p>this example is disabled during conformance testing</p>
+ ````````````````````````````````
+
## Strikethrough (extension)
GFM enables the `strikethrough` extension.
@@ -202,7 +227,7 @@ RSpec.describe Glfm::UpdateExampleSnapshots, '#process' do
"existing": "This entry is existing, but not skipped, so it will be overwritten."
}
# 02_01__inlines__strong__002: is omitted from the existing file and skipped, to test that scenario.
- 02_02__inlines__strikethrough_extension__001: |-
+ 02_03__inlines__strikethrough_extension__001: |-
{
"type": "doc",
"content": [
@@ -314,20 +339,20 @@ RSpec.describe Glfm::UpdateExampleSnapshots, '#process' do
02_01__inlines__strong__002:
spec_txt_example_position: 2
source_specification: github
- 02_02__inlines__strikethrough_extension__001:
- spec_txt_example_position: 3
+ 02_03__inlines__strikethrough_extension__001:
+ spec_txt_example_position: 4
source_specification: github
03_01__first_gitlab_specific_section_with_examples__strong_but_with_two_asterisks__001:
- spec_txt_example_position: 4
+ spec_txt_example_position: 5
source_specification: gitlab
04_01__second_gitlab_specific_section_with_examples__strong_but_with_html__001:
- spec_txt_example_position: 5
+ spec_txt_example_position: 6
source_specification: gitlab
05_01__third_gitlab_specific_section_with_skipped_examples__strong_but_skipped__001:
- spec_txt_example_position: 6
+ spec_txt_example_position: 7
source_specification: gitlab
05_02__third_gitlab_specific_section_with_skipped_examples__strong_but_manually_modified_and_skipped__001:
- spec_txt_example_position: 7
+ spec_txt_example_position: 8
source_specification: gitlab
ES_EXAMPLES_INDEX_YML_CONTENTS
end
@@ -349,7 +374,7 @@ RSpec.describe Glfm::UpdateExampleSnapshots, '#process' do
__bold__
02_01__inlines__strong__002: |
__bold with more text__
- 02_02__inlines__strikethrough_extension__001: |
+ 02_03__inlines__strikethrough_extension__001: |
~~Hi~~ Hello, world!
03_01__first_gitlab_specific_section_with_examples__strong_but_with_two_asterisks__001: |
**bold**
@@ -413,7 +438,7 @@ RSpec.describe Glfm::UpdateExampleSnapshots, '#process' do
<p data-sourcepos="1:1-1:23" dir="auto"><strong>bold with more text</strong></p>
wysiwyg: |-
<p><strong>bold with more text</strong></p>
- 02_02__inlines__strikethrough_extension__001:
+ 02_03__inlines__strikethrough_extension__001:
canonical: |
<p><del>Hi</del> Hello, world!</p>
static: |-
@@ -468,7 +493,7 @@ RSpec.describe Glfm::UpdateExampleSnapshots, '#process' do
}
]
}
- 02_02__inlines__strikethrough_extension__001: |-
+ 02_03__inlines__strikethrough_extension__001: |-
{
"type": "doc",
"content": [
diff --git a/spec/scripts/pipeline_test_report_builder_spec.rb b/spec/scripts/pipeline_test_report_builder_spec.rb
index 8553ada044e..198cdefc530 100644
--- a/spec/scripts/pipeline_test_report_builder_spec.rb
+++ b/spec/scripts/pipeline_test_report_builder_spec.rb
@@ -103,16 +103,18 @@ RSpec.describe PipelineTestReportBuilder do
end
describe '#test_report_for_latest_pipeline' do
+ let(:failed_build_uri) { "#{failed_pipeline_url}/tests/suite.json?build_ids[]=#{failed_build_id}" }
+
+ before do
+ allow(subject).to receive(:fetch).with(failed_build_uri).and_return(failed_builds_for_pipeline)
+ end
+
it 'fetches builds from pipeline related to MR' do
- expect(subject).to receive(:fetch).with("#{failed_pipeline_url}/tests/suite.json?build_ids[]=#{failed_build_id}").and_return(failed_builds_for_pipeline)
- subject.test_report_for_latest_pipeline
+ expected = { "suites" => [failed_builds_for_pipeline] }.to_json
+ expect(subject.test_report_for_latest_pipeline).to eq(expected)
end
context 'canonical pipeline' do
- before do
- allow(subject).to receive(:test_report_for_build).and_return(test_report_for_build)
- end
-
context 'no previous pipeline' do
let(:mr_pipelines) { [] }
@@ -171,6 +173,10 @@ RSpec.describe PipelineTestReportBuilder do
end
context 'failed pipeline and failed test builds' do
+ before do
+ allow(subject).to receive(:fetch).with(failed_build_uri).and_return(test_report_for_build)
+ end
+
it 'returns populated test list for suites' do
actual = subject.test_report_for_latest_pipeline
expected = {
@@ -180,6 +186,36 @@ RSpec.describe PipelineTestReportBuilder do
expect(actual).to eq(expected)
end
end
+
+ context 'when receiving a server error' do
+ let(:response) { instance_double('Net::HTTPResponse') }
+ let(:error) { Net::HTTPServerException.new('server error', response) }
+ let(:test_report_for_latest_pipeline) { subject.test_report_for_latest_pipeline }
+
+ before do
+ allow(response).to receive(:code).and_return(response_code)
+ allow(subject).to receive(:fetch).with(failed_build_uri).and_raise(error)
+ end
+
+ context 'when response code is 404' do
+ let(:response_code) { 404 }
+
+ it 'continues without the missing reports' do
+ expected = { 'suites' => [] }.to_json
+
+ expect { test_report_for_latest_pipeline }.not_to raise_error
+ expect(test_report_for_latest_pipeline).to eq(expected)
+ end
+ end
+
+ context 'when response code is unexpected' do
+ let(:response_code) { 500 }
+
+ it 'raises HTTPServerException' do
+ expect { test_report_for_latest_pipeline }.to raise_error(error)
+ end
+ end
+ end
end
end
end