summaryrefslogtreecommitdiff
path: root/qa/spec/support
diff options
context:
space:
mode:
Diffstat (limited to 'qa/spec/support')
-rw-r--r--qa/spec/support/formatters/allure_metadata_formatter_spec.rb3
-rw-r--r--qa/spec/support/formatters/test_stats_formatter_spec.rb20
-rw-r--r--qa/spec/support/loglinking_spec.rb185
-rw-r--r--qa/spec/support/page_error_checker_spec.rb66
-rw-r--r--qa/spec/support/repeater_spec.rb6
5 files changed, 271 insertions, 9 deletions
diff --git a/qa/spec/support/formatters/allure_metadata_formatter_spec.rb b/qa/spec/support/formatters/allure_metadata_formatter_spec.rb
index 631d2eda54f..d84e190fd56 100644
--- a/qa/spec/support/formatters/allure_metadata_formatter_spec.rb
+++ b/qa/spec/support/formatters/allure_metadata_formatter_spec.rb
@@ -14,6 +14,7 @@ describe QA::Support::Formatters::AllureMetadataFormatter do
add_link: nil,
attempts: 0,
file_path: 'file/path/spec.rb',
+ execution_result: instance_double("RSpec::Core::Example::ExecutionResult", status: :passed),
metadata: {
testcase: 'testcase',
quarantine: { issue: 'issue' }
@@ -31,7 +32,7 @@ describe QA::Support::Formatters::AllureMetadataFormatter do
end
it "adds additional data to report" do
- formatter.example_started(rspec_example_notification)
+ formatter.example_finished(rspec_example_notification)
aggregate_failures do
expect(rspec_example).to have_received(:issue).with('Quarantine issue', 'issue')
diff --git a/qa/spec/support/formatters/test_stats_formatter_spec.rb b/qa/spec/support/formatters/test_stats_formatter_spec.rb
index 84fc3b83185..518c7407ba6 100644
--- a/qa/spec/support/formatters/test_stats_formatter_spec.rb
+++ b/qa/spec/support/formatters/test_stats_formatter_spec.rb
@@ -60,7 +60,8 @@ describe QA::Support::Formatters::TestStatsFormatter do
retry_attempts: 0,
job_url: ci_job_url,
pipeline_url: ci_pipeline_url,
- pipeline_id: ci_pipeline_id
+ pipeline_id: ci_pipeline_id,
+ merge_request_iid: nil
}
}
end
@@ -157,6 +158,23 @@ describe QA::Support::Formatters::TestStatsFormatter do
end
end
+ context 'with context quarantined spec' do
+ let(:quarantined) { 'false' }
+
+ it 'exports data to influxdb with correct qurantine tag' do
+ run_spec do
+ it(
+ 'spec',
+ quarantine: { only: { job: 'praefect' } },
+ testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/1234'
+ ) {}
+ end
+
+ expect(influx_write_api).to have_received(:write).once
+ expect(influx_write_api).to have_received(:write).with(data: [data])
+ end
+ end
+
context 'with staging full run' do
let(:run_type) { 'staging-full' }
diff --git a/qa/spec/support/loglinking_spec.rb b/qa/spec/support/loglinking_spec.rb
new file mode 100644
index 00000000000..cba8a139767
--- /dev/null
+++ b/qa/spec/support/loglinking_spec.rb
@@ -0,0 +1,185 @@
+# frozen_string_literal: true
+
+RSpec.describe QA::Support::Loglinking do
+ describe '.failure_metadata' do
+ context 'return nil string' do
+ it 'if correlation_id is empty' do
+ expect(QA::Support::Loglinking.failure_metadata('')).to eq(nil)
+ end
+ it 'if correlation_id is nil' do
+ expect(QA::Support::Loglinking.failure_metadata(nil)).to eq(nil)
+ end
+ end
+
+ context 'return error string' do
+ it 'with sentry URL' do
+ allow(QA::Support::Loglinking).to receive(:sentry_url).and_return('https://sentry.address/?environment=bar')
+ allow(QA::Support::Loglinking).to receive(:kibana_url).and_return(nil)
+
+ expect(QA::Support::Loglinking.failure_metadata('foo123')).to eql(<<~ERROR.chomp)
+ Correlation Id: foo123
+ Sentry Url: https://sentry.address/?environment=bar&query=correlation_id%3A%22foo123%22
+ ERROR
+ end
+
+ it 'with kibana URL' do
+ allow(QA::Support::Loglinking).to receive(:sentry_url).and_return(nil)
+ allow(QA::Support::Loglinking).to receive(:kibana_url).and_return('https://kibana.address/')
+
+ expect(QA::Support::Loglinking.failure_metadata('foo123')).to eql(<<~ERROR.chomp)
+ Correlation Id: foo123
+ Kibana Url: https://kibana.address/app/discover#/?_a=(query:(language:kuery,query:'json.correlation_id%20:%20foo123'))
+ ERROR
+ end
+ end
+ end
+
+ describe '.sentry_url' do
+ let(:url_hash) do
+ {
+ :staging => 'https://sentry.gitlab.net/gitlab/staginggitlabcom/?environment=gstg',
+ :staging_canary => 'https://sentry.gitlab.net/gitlab/staginggitlabcom/?environment=gstg-cny',
+ :staging_ref => 'https://sentry.gitlab.net/gitlab/staging-ref/?environment=gstg-ref',
+ :pre => 'https://sentry.gitlab.net/gitlab/pregitlabcom/?environment=pre',
+ :canary => 'https://sentry.gitlab.net/gitlab/gitlabcom/?environment=gprd',
+ :production => 'https://sentry.gitlab.net/gitlab/gitlabcom/?environment=gprd-cny',
+ :foo => nil,
+ nil => nil
+ }
+ end
+
+ it 'returns sentry URL if environment found' do
+ url_hash.each do |environment, url|
+ allow(QA::Support::Loglinking).to receive(:logging_environment).and_return(environment)
+
+ expect(QA::Support::Loglinking.sentry_url).to eq(url)
+ end
+ end
+ end
+
+ describe '.kibana_url' do
+ let(:url_hash) do
+ {
+ :staging => 'https://nonprod-log.gitlab.net/',
+ :staging_canary => 'https://nonprod-log.gitlab.net/',
+ :staging_ref => nil,
+ :pre => nil,
+ :canary => 'https://log.gprd.gitlab.net/',
+ :production => 'https://log.gprd.gitlab.net/',
+ :foo => nil,
+ nil => nil
+ }
+ end
+
+ it 'returns kibana URL if environment found' do
+ url_hash.each do |environment, url|
+ allow(QA::Support::Loglinking).to receive(:logging_environment).and_return(environment)
+
+ expect(QA::Support::Loglinking.kibana_url).to eq(url)
+ end
+ end
+ end
+
+ describe '.logging_environment' do
+ let(:staging_address) { 'https://staging.gitlab.com' }
+ let(:staging_ref_address) { 'https://staging-ref.gitlab.com' }
+ let(:production_address) { 'https://www.gitlab.com' }
+ let(:pre_prod_address) { 'https://pre.gitlab.com' }
+ let(:logging_env_array) do
+ [
+ {
+ address: staging_address,
+ canary: false,
+ expected_env: :staging
+ },
+ {
+ address: staging_address,
+ canary: true,
+ expected_env: :staging_canary
+ },
+ {
+ address: staging_ref_address,
+ canary: true,
+ expected_env: :staging_ref
+ },
+ {
+ address: production_address,
+ canary: false,
+ expected_env: :production
+ },
+ {
+ address: production_address,
+ canary: true,
+ expected_env: :canary
+ },
+ {
+ address: pre_prod_address,
+ canary: true,
+ expected_env: :pre
+ },
+ {
+ address: 'https://foo.com',
+ canary: true,
+ expected_env: nil
+ }
+ ]
+ end
+
+ it 'returns logging environment if environment found' do
+ logging_env_array.each do |logging_env_hash|
+ allow(QA::Runtime::Scenario).to receive(:attributes).and_return({ gitlab_address: logging_env_hash[:address] })
+ allow(QA::Support::Loglinking).to receive(:canary?).and_return(logging_env_hash[:canary])
+
+ expect(QA::Support::Loglinking.logging_environment).to eq(logging_env_hash[:expected_env])
+ end
+ end
+ end
+
+ describe '.logging_environment?' do
+ context 'returns boolean' do
+ it 'returns true if logging_environment is not nil' do
+ allow(QA::Support::Loglinking).to receive(:logging_environment).and_return(:staging)
+
+ expect(QA::Support::Loglinking.logging_environment?).to eq(true)
+ end
+
+ it 'returns false if logging_environment is nil' do
+ allow(QA::Support::Loglinking).to receive(:logging_environment).and_return(nil)
+
+ expect(QA::Support::Loglinking.logging_environment?).to eq(false)
+ end
+ end
+ end
+
+ describe '.cookies' do
+ let(:cookies) { [{ name: 'Foo', value: 'Bar' }, { name: 'gitlab_canary', value: 'true' }] }
+
+ it 'returns browser cookies' do
+ allow(Capybara.current_session).to receive_message_chain(:driver, :browser, :manage, :all_cookies).and_return(cookies)
+
+ expect(QA::Support::Loglinking.cookies).to eq({ "Foo" => { name: "Foo", value: "Bar" }, "gitlab_canary" => { name: "gitlab_canary", value: "true" } })
+ end
+ end
+
+ describe '.canary?' do
+ context 'gitlab_canary cookie is present' do
+ it 'and true returns true' do
+ allow(QA::Support::Loglinking).to receive(:cookies).and_return({ 'gitlab_canary' => { name: 'gitlab_canary', value: 'true' } })
+
+ expect(QA::Support::Loglinking.canary?).to eq(true)
+ end
+ it 'and not true returns false' do
+ allow(QA::Support::Loglinking).to receive(:cookies).and_return({ 'gitlab_canary' => { name: 'gitlab_canary', value: 'false' } })
+
+ expect(QA::Support::Loglinking.canary?).to eq(false)
+ end
+ end
+ context 'gitlab_canary cookie is not present' do
+ it 'returns false' do
+ allow(QA::Support::Loglinking).to receive(:cookies).and_return({ 'foo' => { name: 'foo', path: '/pathname' } })
+
+ expect(QA::Support::Loglinking.canary?).to eq(false)
+ end
+ end
+ end
+end
diff --git a/qa/spec/support/page_error_checker_spec.rb b/qa/spec/support/page_error_checker_spec.rb
index 764b6110e08..b9b085fa7b9 100644
--- a/qa/spec/support/page_error_checker_spec.rb
+++ b/qa/spec/support/page_error_checker_spec.rb
@@ -8,16 +8,28 @@ RSpec.describe QA::Support::PageErrorChecker do
describe '.report!' do
context 'reports errors' do
let(:expected_chrome_error) do
+ "Error Code 500\n\n"\
"chrome errors\n\n"\
- "Path: #{test_path}"
+ "Path: #{test_path}\n\n"\
+ "Logging: foo123"
end
let(:expected_basic_error) do
+ "Error Code 500\n\n"\
+ "foo status\n\n"\
+ "Path: #{test_path}\n\n"\
+ "Logging: foo123"
+ end
+
+ let(:expected_basic_404) do
+ "Error Code 404\n\n"\
"foo status\n\n"\
"Path: #{test_path}"
end
it 'reports error message on chrome browser' do
+ allow(QA::Support::PageErrorChecker).to receive(:parse_five_c_page_request_id).and_return('foo123')
+ allow(QA::Support::Loglinking).to receive(:failure_metadata).with('foo123').and_return('Logging: foo123')
allow(QA::Support::PageErrorChecker).to receive(:return_chrome_errors).and_return('chrome errors')
allow(page).to receive(:current_path).and_return(test_path)
allow(QA::Runtime::Env).to receive(:browser).and_return(:chrome)
@@ -26,12 +38,64 @@ RSpec.describe QA::Support::PageErrorChecker do
end
it 'reports basic message on non-chrome browser' do
+ allow(QA::Support::PageErrorChecker).to receive(:parse_five_c_page_request_id).and_return('foo123')
+ allow(QA::Support::Loglinking).to receive(:failure_metadata).with('foo123').and_return('Logging: foo123')
allow(QA::Support::PageErrorChecker).to receive(:status_code_report).and_return('foo status')
allow(page).to receive(:current_path).and_return(test_path)
allow(QA::Runtime::Env).to receive(:browser).and_return(:firefox)
expect { QA::Support::PageErrorChecker.report!(page, 500) }.to raise_error(RuntimeError, expected_basic_error)
end
+
+ it 'does not report failure metadata on non 500 error' do
+ allow(QA::Support::PageErrorChecker).to receive(:parse_five_c_page_request_id).and_return('foo123')
+
+ expect(QA::Support::Loglinking).not_to receive(:failure_metadata)
+
+ allow(QA::Support::PageErrorChecker).to receive(:status_code_report).and_return('foo status')
+ allow(page).to receive(:current_path).and_return(test_path)
+ allow(QA::Runtime::Env).to receive(:browser).and_return(:firefox)
+
+ expect { QA::Support::PageErrorChecker.report!(page, 404) }.to raise_error(RuntimeError, expected_basic_404)
+ end
+ end
+ end
+
+ describe '.parse_five_c_page_request_id' do
+ context 'parse correlation ID' do
+ require 'nokogiri'
+ before do
+ nokogiri_parse = Class.new do
+ def self.parse(str)
+ Nokogiri::HTML.parse(str)
+ end
+ end
+ stub_const('NokogiriParse', nokogiri_parse)
+ end
+ let(:error_500_str) do
+ "<html><body><div><p><code>"\
+ "req678"\
+ "</code></p></div></body></html>"
+ end
+
+ let(:error_500_no_code_str) do
+ "<html><body>"\
+ "The code you are looking for is not here"\
+ "</body></html>"
+ end
+
+ it 'returns code is present' do
+ allow(page).to receive(:html).and_return(error_500_str)
+ allow(Nokogiri::HTML).to receive(:parse).with(error_500_str).and_return(NokogiriParse.parse(error_500_str))
+
+ expect(QA::Support::PageErrorChecker.parse_five_c_page_request_id(page).to_str).to eq('req678')
+ end
+ it 'returns nil if not present' do
+ allow(page).to receive(:html).and_return(error_500_no_code_str)
+ allow(Nokogiri::HTML).to receive(:parse).with(error_500_no_code_str).and_return(NokogiriParse.parse(error_500_no_code_str))
+
+ expect(QA::Support::PageErrorChecker.parse_five_c_page_request_id(page)).to be_nil
+ end
end
end
diff --git a/qa/spec/support/repeater_spec.rb b/qa/spec/support/repeater_spec.rb
index 4fa3bcde5e7..96e780fc9bd 100644
--- a/qa/spec/support/repeater_spec.rb
+++ b/qa/spec/support/repeater_spec.rb
@@ -3,12 +3,6 @@
require 'active_support/core_ext/integer/time'
RSpec.describe QA::Support::Repeater do
- before do
- logger = ::Logger.new $stdout
- logger.level = ::Logger::DEBUG
- QA::Runtime::Logger.logger = logger
- end
-
subject do
Module.new do
extend QA::Support::Repeater