diff options
Diffstat (limited to 'qa/spec/support/formatters/test_stats_formatter_spec.rb')
-rw-r--r-- | qa/spec/support/formatters/test_stats_formatter_spec.rb | 60 |
1 files changed, 57 insertions, 3 deletions
diff --git a/qa/spec/support/formatters/test_stats_formatter_spec.rb b/qa/spec/support/formatters/test_stats_formatter_spec.rb index 2bfd7863653..84fc3b83185 100644 --- a/qa/spec/support/formatters/test_stats_formatter_spec.rb +++ b/qa/spec/support/formatters/test_stats_formatter_spec.rb @@ -1,10 +1,12 @@ # frozen_string_literal: true require 'rspec/core/sandbox' +require 'active_support/testing/time_helpers' describe QA::Support::Formatters::TestStatsFormatter do include QA::Support::Helpers::StubEnv include QA::Specs::Helpers::RSpec + include ActiveSupport::Testing::TimeHelpers let(:url) { "http://influxdb.net" } let(:token) { "token" } @@ -22,6 +24,7 @@ describe QA::Support::Formatters::TestStatsFormatter do let(:file_path) { "./qa/specs/features/#{stage}/subfolder/some_spec.rb" } let(:ui_fabrication) { 0 } let(:api_fabrication) { 0 } + let(:fabrication_resources) { {} } let(:influx_client_args) do { @@ -45,7 +48,8 @@ describe QA::Support::Formatters::TestStatsFormatter do job_name: "test-job", merge_request: "false", run_type: run_type, - stage: stage.match(%r{\d{1,2}_(\w+)}).captures.first + stage: stage.match(%r{\d{1,2}_(\w+)}).captures.first, + testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/1234' }, fields: { id: './spec/support/formatters/test_stats_formatter_spec.rb[1:1]', @@ -56,8 +60,7 @@ describe QA::Support::Formatters::TestStatsFormatter do retry_attempts: 0, job_url: ci_job_url, pipeline_url: ci_pipeline_url, - pipeline_id: ci_pipeline_id, - testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/1234' + pipeline_id: ci_pipeline_id } } end @@ -88,6 +91,7 @@ describe QA::Support::Formatters::TestStatsFormatter do before do allow(InfluxDB2::Client).to receive(:new).with(url, token, **influx_client_args) { influx_client } + allow(QA::Tools::TestResourceDataProcessor).to receive(:resources) { fabrication_resources } end context "without influxdb variables configured" do @@ -135,6 +139,7 @@ describe QA::Support::Formatters::TestStatsFormatter do it('spec', :reliable, 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 @@ -147,6 +152,7 @@ describe QA::Support::Formatters::TestStatsFormatter do it('spec', :quarantine, 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 @@ -162,6 +168,7 @@ describe QA::Support::Formatters::TestStatsFormatter do it 'exports data to influxdb with correct run type' do run_spec + expect(influx_write_api).to have_received(:write).once expect(influx_write_api).to have_received(:write).with(data: [data]) end end @@ -179,6 +186,7 @@ describe QA::Support::Formatters::TestStatsFormatter do it 'exports data to influxdb with correct run type' do run_spec + expect(influx_write_api).to have_received(:write).once expect(influx_write_api).to have_received(:write).with(data: [data]) end end @@ -195,8 +203,54 @@ describe QA::Support::Formatters::TestStatsFormatter do it 'exports data to influxdb with fabrication times' do run_spec + expect(influx_write_api).to have_received(:write).once expect(influx_write_api).to have_received(:write).with(data: [data]) end end + + context 'with fabrication resources' do + let(:fabrication_resources) do + { + 'QA::Resource::Project' => [{ + info: "with id '1'", + api_path: '/project', + fabrication_method: :api, + fabrication_time: 1, + http_method: :post, + timestamp: Time.now.to_s + }] + } + end + + let(:fabrication_data) do + { + name: 'fabrication-stats', + time: DateTime.strptime(ci_timestamp).to_time, + tags: { + resource: 'QA::Resource::Project', + fabrication_method: :api, + http_method: :post, + run_type: run_type, + merge_request: "false" + }, + fields: { + fabrication_time: 1, + info: "with id '1'", + job_url: ci_job_url, + timestamp: Time.now.to_s + } + } + end + + around do |example| + freeze_time { example.run } + end + + it 'exports fabrication stats data to influxdb' do + run_spec + + expect(influx_write_api).to have_received(:write).with(data: [fabrication_data]) + end + end end end |