diff options
Diffstat (limited to 'qa/spec/support')
-rw-r--r-- | qa/spec/support/formatters/allure_metadata_formatter_spec.rb | 70 | ||||
-rw-r--r-- | qa/spec/support/loglinking_spec.rb | 129 | ||||
-rw-r--r-- | qa/spec/support/system_logs/kibana_spec.rb | 75 | ||||
-rw-r--r-- | qa/spec/support/system_logs/sentry_spec.rb | 42 |
4 files changed, 230 insertions, 86 deletions
diff --git a/qa/spec/support/formatters/allure_metadata_formatter_spec.rb b/qa/spec/support/formatters/allure_metadata_formatter_spec.rb index d84e190fd56..ab3b753c3b0 100644 --- a/qa/spec/support/formatters/allure_metadata_formatter_spec.rb +++ b/qa/spec/support/formatters/allure_metadata_formatter_spec.rb @@ -5,25 +5,33 @@ describe QA::Support::Formatters::AllureMetadataFormatter do let(:formatter) { described_class.new(StringIO.new) } - let(:rspec_example_notification) { double('RSpec::Core::Notifications::ExampleNotification', example: rspec_example) } + let(:rspec_example_notification) do + instance_double(RSpec::Core::Notifications::ExampleNotification, example: rspec_example) + end + + # rubocop:disable RSpec/VerifiedDoubles let(:rspec_example) do double( - 'RSpec::Core::Example', + RSpec::Core::Example, tms: nil, issue: nil, add_link: nil, + set_flaky: nil, + parameter: nil, attempts: 0, - file_path: 'file/path/spec.rb', - execution_result: instance_double("RSpec::Core::Example::ExecutionResult", status: :passed), + file_path: 'spec.rb', + execution_result: instance_double(RSpec::Core::Example::ExecutionResult, status: status), metadata: { testcase: 'testcase', quarantine: { issue: 'issue' } } ) end + # rubocop:enable RSpec/VerifiedDoubles let(:ci_job) { 'ee:relative 5' } let(:ci_job_url) { 'url' } + let(:status) { :failed } before do stub_env('CI', 'true') @@ -31,16 +39,62 @@ describe QA::Support::Formatters::AllureMetadataFormatter do stub_env('CI_JOB_URL', ci_job_url) end - it "adds additional data to report" do - formatter.example_finished(rspec_example_notification) + context 'with links' do + it 'adds quarantine, failure issue and ci job links', :aggregate_failures do + formatter.example_finished(rspec_example_notification) - aggregate_failures do expect(rspec_example).to have_received(:issue).with('Quarantine issue', 'issue') expect(rspec_example).to have_received(:add_link).with(name: "Job(#{ci_job})", url: ci_job_url) expect(rspec_example).to have_received(:issue).with( 'Failure issues', - 'https://gitlab.com/gitlab-org/gitlab/-/issues?scope=all&state=opened&search=spec.rb' + 'https://gitlab.com/gitlab-org/gitlab/-/issues?scope=all&state=opened&search=Failure%20in%20spec.rb' ) end end + + context 'with flaky test data', :aggregate_failures do + let(:influx_client) { instance_double(InfluxDB2::Client, create_query_api: influx_query_api) } + let(:influx_query_api) { instance_double(InfluxDB2::QueryApi, query: data) } + let(:data) do + [ + instance_double( + InfluxDB2::FluxTable, + records: [ + instance_double(InfluxDB2::FluxRecord, values: { 'status' => 'failed', 'testcase' => 'testcase' }), + instance_double(InfluxDB2::FluxRecord, values: { 'status' => 'passed', 'testcase' => 'testcase' }) + ] + ) + ] + end + + before do + stub_env('QA_RUN_TYPE', 'package-and-test') + stub_env('QA_INFLUXDB_URL', 'url') + stub_env('QA_INFLUXDB_TOKEN', 'token') + + allow(InfluxDB2::Client).to receive(:new) { influx_client } + end + + context 'with non skipped spec' do + it 'adds flaky test data' do + formatter.start(nil) + formatter.example_finished(rspec_example_notification) + + expect(rspec_example).to have_received(:set_flaky) + expect(rspec_example).to have_received(:parameter).with('pass_rate', '50%') + end + end + + context 'with skipped spec' do + let(:status) { :pending } + + it 'skips adding flaky test data' do + formatter.start(nil) + formatter.example_finished(rspec_example_notification) + + expect(rspec_example).not_to have_received(:set_flaky) + expect(rspec_example).not_to have_received(:parameter) + end + end + end end diff --git a/qa/spec/support/loglinking_spec.rb b/qa/spec/support/loglinking_spec.rb index 3955d266ef6..79004630253 100644 --- a/qa/spec/support/loglinking_spec.rb +++ b/qa/spec/support/loglinking_spec.rb @@ -13,103 +13,76 @@ RSpec.describe QA::Support::Loglinking do end context 'when correlation_id exists' do - context 'and logging environment exists' do - it 'returns Sentry URL' do - allow(QA::Support::Loglinking).to receive(:get_logging_environment).and_return(:foo) - allow(QA::Support::Loglinking).to receive(:get_sentry_base_url).and_return('https://sentry.address/?environment=bar') - allow(QA::Support::Loglinking).to receive(:get_kibana_base_url).and_return(nil) - allow(QA::Support::Loglinking).to receive(:get_kibana_index).and_return(nil) + let(:correlation_id) { 'foo123' } + let(:sentry_url) { "https://sentry.address/?environment=bar&query=correlation_id%3A%22#{correlation_id}%22" } + let(:discover_url) { "https://kibana.address/app/discover#/?_a=%28index:%27pubsub-rails-inf-foo%27%2Cquery%3A%28language%3Akuery%2Cquery%3A%27json.correlation_id%20%3A%20#{correlation_id}%27%29%29&_g=%28time%3A%28from%3A%272022-11-13T00:00:00.000Z%27%2Cto%3A%272022-11-14T00:00:00.000Z%27%29%29" } + let(:dashboard_url) { "https://kibana.address/app/dashboards#/view/abc-123-dashboard-id?_g=%28time%3A%28from:%272022-11-13T00:00:00.000Z%27%2Cto%3A%272022-11-14T00:00:00.000Z%27%29%29&_a=%28filters%3A%21%28%28query%3A%28match_phrase%3A%28json.correlation_id%3A%27#{correlation_id}%27%29%29%29%29%29" } + + before do + allow(QA::Support::SystemLogs::Sentry).to receive(:new).and_return(sentry) + allow(QA::Support::SystemLogs::Kibana).to receive(:new).and_return(kibana) + end - 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 + context 'and both Sentry and Kibana exist for the logging environment' do + let(:sentry) { instance_double(QA::Support::SystemLogs::Sentry, url: sentry_url) } + let(:kibana) do + instance_double(QA::Support::SystemLogs::Kibana, + discover_url: discover_url, dashboard_url: dashboard_url) end - it 'returns Kibana URL' do - time = Time.new(2022, 11, 14, 0, 0, 0, '+00:00') - - allow(QA::Support::Loglinking).to receive(:get_logging_environment).and_return(:foo) - allow(QA::Support::Loglinking).to receive(:get_sentry_base_url).and_return(nil) - allow(QA::Support::Loglinking).to receive(:get_kibana_base_url).and_return('https://kibana.address/') - allow(QA::Support::Loglinking).to receive(:get_kibana_index).and_return('pubsub-rails-inf-foo') - allow(Time).to receive(:now).and_return(time) - - expect(QA::Support::Loglinking.failure_metadata('foo123')).to eql(<<~ERROR.chomp) + it 'returns both Sentry and Kibana URLs' do + expect(QA::Support::Loglinking.failure_metadata(correlation_id)).to eql(<<~ERROR.chomp) Correlation Id: foo123 - Kibana Url: https://kibana.address/app/discover#/?_a=%28index:%27pubsub-rails-inf-foo%27%2Cquery%3A%28language%3Akuery%2Cquery%3A%27json.correlation_id%20%3A%20foo123%27%29%29&_g=%28time%3A%28from%3A%272022-11-13T00:00:00.000Z%27%2Cto%3A%272022-11-14T00:00:00.000Z%27%29%29 + Sentry Url: #{sentry_url} + Kibana - Discover Url: #{discover_url} + Kibana - Dashboard Url: #{dashboard_url} ERROR end end - context 'and logging environment does not exist' do - it 'returns only the correlation ID' do - allow(QA::Support::Loglinking).to receive(:get_logging_environment).and_return(nil) - - expect(QA::Support::Loglinking.failure_metadata('foo123')).to eql('Correlation Id: foo123') + context 'and only Sentry exists for the logging environment' do + let(:sentry) { instance_double(QA::Support::SystemLogs::Sentry, url: sentry_url) } + let(:kibana) do + instance_double(QA::Support::SystemLogs::Kibana, + discover_url: nil, dashboard_url: nil) end - end - end - end - describe '.get_sentry_base_url' do - let(:url_hash) do - { - :staging => 'https://sentry.gitlab.net/gitlab/staginggitlabcom/?environment=gstg', - :staging_ref => 'https://sentry.gitlab.net/gitlab/staging-ref/?environment=all', - :pre => 'https://sentry.gitlab.net/gitlab/pregitlabcom/?environment=all', - :production => 'https://sentry.gitlab.net/gitlab/gitlabcom/?environment=gprd', - :foo => nil, - nil => nil - } - end - - it 'returns Sentry base URL based on environment' do - url_hash.each do |environment, url| - expect(QA::Support::Loglinking.get_sentry_base_url(environment)).to eq(url) + it 'returns only Sentry URL' do + expect(QA::Support::Loglinking.failure_metadata(correlation_id)).to eql(<<~ERROR.chomp) + Correlation Id: foo123 + Sentry Url: #{sentry_url} + ERROR + end end - end - end - describe '.get_kibana_base_url' do - let(:url_hash) do - { - :staging => 'https://nonprod-log.gitlab.net/', - :staging_ref => nil, - :production => 'https://log.gprd.gitlab.net/', - :pre => 'https://nonprod-log.gitlab.net/', - :foo => nil, - nil => nil - } - end + context 'and only Kibana exists for the logging environment' do + let(:sentry) { instance_double(QA::Support::SystemLogs::Sentry, url: nil) } + let(:kibana) do + instance_double(QA::Support::SystemLogs::Kibana, + discover_url: discover_url, dashboard_url: dashboard_url) + end - it 'returns Kibana URL based on environment' do - url_hash.each do |environment, url| - expect(QA::Support::Loglinking.get_kibana_base_url(environment)).to eq(url) + it 'returns only Kibana Discover and Dashboard URLs' do + expect(QA::Support::Loglinking.failure_metadata(correlation_id)).to eql(<<~ERROR.chomp) + Correlation Id: foo123 + Kibana - Discover Url: #{discover_url} + Kibana - Dashboard Url: #{dashboard_url} + ERROR + end end - end - end - describe '.get_kibana_index' do - let(:index_hash) do - { - :staging => 'ed942d00-5186-11ea-ad8a-f3610a492295', - :staging_ref => nil, - :production => '7092c4e2-4eb5-46f2-8305-a7da2edad090', - :pre => 'pubsub-rails-inf-pre', - :foo => nil, - nil => nil - } - end + context 'and neither Sentry nor Kibana exists for the logging environment' do + let(:sentry) { instance_double(QA::Support::SystemLogs::Sentry, url: nil) } + let(:kibana) { instance_double(QA::Support::SystemLogs::Kibana, discover_url: nil, dashboard_url: nil) } - it 'returns Kibana index based on environment' do - index_hash.each do |environment, index| - expect(QA::Support::Loglinking.get_kibana_index(environment)).to eq(index) + it 'returns only the correlation ID' do + expect(QA::Support::Loglinking.failure_metadata(correlation_id)).to eql("Correlation Id: #{correlation_id}") + end end end end - describe '.get_logging_environment' do + describe '.logging_environment' do let(:staging_address) { 'https://staging.gitlab.com' } let(:staging_ref_address) { 'https://staging-ref.gitlab.com' } let(:production_address) { 'https://gitlab.com' } @@ -143,7 +116,7 @@ RSpec.describe QA::Support::Loglinking do logging_env_array.each do |logging_env_hash| allow(QA::Runtime::Scenario).to receive(:attributes).and_return({ gitlab_address: logging_env_hash[:address] }) - expect(QA::Support::Loglinking.get_logging_environment).to eq(logging_env_hash[:expected_env]) + expect(QA::Support::Loglinking.logging_environment).to eq(logging_env_hash[:expected_env]) end end end diff --git a/qa/spec/support/system_logs/kibana_spec.rb b/qa/spec/support/system_logs/kibana_spec.rb new file mode 100644 index 00000000000..7e13f5a0a06 --- /dev/null +++ b/qa/spec/support/system_logs/kibana_spec.rb @@ -0,0 +1,75 @@ +# frozen_string_literal: true + +RSpec.describe QA::Support::SystemLogs::Kibana do + using RSpec::Parameterized::TableSyntax + + let(:correlation_id) { 'foo123' } + + shared_examples 'returns the expected URL' do + where(:env, :expected_url) do + :staging | ref(:staging_url) + :production | ref(:production_url) + :pre | ref(:pre_url) + :foo | nil + nil | nil + end + + with_them do + before do + allow(Time).to receive(:now).and_return(Time.new(2022, 11, 14, 0, 0, 0, '+00:00')) + end + + specify do + expect(subject).to eq(expected_url) + end + end + end + + describe '#discover_url' do + subject { described_class.new(env, correlation_id).discover_url } + + let(:staging_url) do + "https://nonprod-log.gitlab.net/app/discover#/?_a=%28index:%27ed942d00-5186-11ea-ad8a-f3610a492295%27" \ + "%2Cquery%3A%28language%3Akuery%2Cquery%3A%27json.correlation_id%20%3A%20#{correlation_id}%27%29" \ + "%29&_g=%28time%3A%28from%3A%272022-11-13T00:00:00.000Z%27%2Cto%3A%272022-11-14T00:00:00.000Z%27%29%29" + end + + let(:production_url) do + "https://log.gprd.gitlab.net/app/discover#/?_a=%28index:%277092c4e2-4eb5-46f2-8305-a7da2edad090%27" \ + "%2Cquery%3A%28language%3Akuery%2Cquery%3A%27json.correlation_id%20%3A%20#{correlation_id}%27%29" \ + "%29&_g=%28time%3A%28from%3A%272022-11-13T00:00:00.000Z%27%2Cto%3A%272022-11-14T00:00:00.000Z%27%29%29" + end + + let(:pre_url) do + "https://nonprod-log.gitlab.net/app/discover#/?_a=%28index:%27pubsub-rails-inf-pre%27" \ + "%2Cquery%3A%28language%3Akuery%2Cquery%3A%27json.correlation_id%20%3A%20#{correlation_id}%27%29" \ + "%29&_g=%28time%3A%28from%3A%272022-11-13T00:00:00.000Z%27%2Cto%3A%272022-11-14T00:00:00.000Z%27%29%29" + end + + it_behaves_like 'returns the expected URL' + end + + describe '#dashboard_url' do + subject { described_class.new(env, correlation_id).dashboard_url } + + let(:staging_url) do + "https://nonprod-log.gitlab.net/app/dashboards#/view/b74dc030-6f56-11ed-9af2-6131f0ee4ce6?_g=%28time" \ + "%3A%28from:%272022-11-13T00:00:00.000Z%27%2Cto%3A%272022-11-14T00:00:00.000Z%27%29%29&_a=%28filters%3A%21" \ + "%28%28query%3A%28match_phrase%3A%28json.correlation_id%3A%27#{correlation_id}%27%29%29%29%29%29" + end + + let(:production_url) do + "https://log.gprd.gitlab.net/app/dashboards#/view/5e6d3440-7597-11ed-9f43-e3784d7fe3ca?_g=%28time" \ + "%3A%28from:%272022-11-13T00:00:00.000Z%27%2Cto%3A%272022-11-14T00:00:00.000Z%27%29%29&_a=%28filters%3A%21" \ + "%28%28query%3A%28match_phrase%3A%28json.correlation_id%3A%27#{correlation_id}%27%29%29%29%29%29" + end + + let(:pre_url) do + "https://nonprod-log.gitlab.net/app/dashboards#/view/15596340-7570-11ed-9af2-6131f0ee4ce6?_g=%28time" \ + "%3A%28from:%272022-11-13T00:00:00.000Z%27%2Cto%3A%272022-11-14T00:00:00.000Z%27%29%29&_a=%28filters%3A%21" \ + "%28%28query%3A%28match_phrase%3A%28json.correlation_id%3A%27#{correlation_id}%27%29%29%29%29%29" + end + + it_behaves_like 'returns the expected URL' + end +end diff --git a/qa/spec/support/system_logs/sentry_spec.rb b/qa/spec/support/system_logs/sentry_spec.rb new file mode 100644 index 00000000000..6821c527b23 --- /dev/null +++ b/qa/spec/support/system_logs/sentry_spec.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +RSpec.describe QA::Support::SystemLogs::Sentry do + using RSpec::Parameterized::TableSyntax + + let(:correlation_id) { 'foo123' } + + describe '#url' do + subject { described_class.new(env, correlation_id).url } + + let(:staging_url) do + "https://sentry.gitlab.net/gitlab/staginggitlabcom/?environment=gstg&query=correlation_id%3A%22#{correlation_id}%22" + end + + let(:staging_ref_url) do + "https://sentry.gitlab.net/gitlab/staging-ref/?environment=all&query=correlation_id%3A%22#{correlation_id}%22" + end + + let(:pre_url) do + "https://sentry.gitlab.net/gitlab/pregitlabcom/?environment=all&query=correlation_id%3A%22#{correlation_id}%22" + end + + let(:production_url) do + "https://sentry.gitlab.net/gitlab/gitlabcom/?environment=gprd&query=correlation_id%3A%22#{correlation_id}%22" + end + + where(:env, :expected_url) do + :staging | ref(:staging_url) + :staging_ref | ref(:staging_ref_url) + :production | ref(:production_url) + :pre | ref(:pre_url) + :foo | nil + nil | nil + end + + with_them do + it 'returns the expected URL' do + expect(subject).to eq(expected_url) + end + end + end +end |