Commit 092feebd authored by Stan Hu's avatar Stan Hu

Merge branch 'pl-error-tracking-validate-payload' into 'master'

Ensure that all used error tracking fixtures are valid

See merge request gitlab-org/gitlab!78285
parents 7f70b741 ed8850a4
......@@ -18,43 +18,25 @@ RSpec.describe ErrorTracking::Collector::PayloadValidator do
end
end
context 'ruby payload' do
let(:payload) { Gitlab::Json.parse(fixture_file('error_tracking/parsed_event.json')) }
it_behaves_like 'valid payload'
context 'with event fixtures' do
where(:event_fixture) do
Dir.glob(Rails.root.join('spec/fixtures/error_tracking/*event*.json'))
end
context 'python payload' do
let(:payload) { Gitlab::Json.parse(fixture_file('error_tracking/python_event.json')) }
with_them do
let(:payload) { Gitlab::Json.parse(fixture_file(event_fixture)) }
it_behaves_like 'valid payload'
end
context 'python payload in repl' do
let(:payload) { Gitlab::Json.parse(fixture_file('error_tracking/python_event_repl.json')) }
it_behaves_like 'valid payload'
end
context 'browser payload' do
let(:payload) { Gitlab::Json.parse(fixture_file('error_tracking/browser_event.json')) }
it_behaves_like 'valid payload'
end
context 'go payload' do
let(:payload) { Gitlab::Json.parse(fixture_file('error_tracking/go_parsed_event.json')) }
it_behaves_like 'valid payload'
end
context 'empty payload' do
context 'when empty' do
let(:payload) { '' }
it_behaves_like 'invalid payload'
end
context 'invalid payload' do
context 'when invalid' do
let(:payload) { { 'foo' => 'bar' } }
it_behaves_like 'invalid payload'
......
......@@ -4,8 +4,9 @@ require 'spec_helper'
RSpec.describe ErrorTracking::CollectErrorService do
let_it_be(:project) { create(:project) }
let_it_be(:parsed_event_file) { 'error_tracking/parsed_event.json' }
let_it_be(:parsed_event) { Gitlab::Json.parse(fixture_file(parsed_event_file)) }
let(:parsed_event_file) { 'error_tracking/parsed_event.json' }
let(:parsed_event) { parse_valid_event(parsed_event_file) }
subject { described_class.new(project, nil, event: parsed_event) }
......@@ -43,7 +44,7 @@ RSpec.describe ErrorTracking::CollectErrorService do
end
context 'python sdk event' do
let(:parsed_event) { Gitlab::Json.parse(fixture_file('error_tracking/python_event.json')) }
let(:parsed_event_file) { 'error_tracking/python_event.json' }
it 'creates a valid event' do
expect { subject.execute }.to change { ErrorTracking::ErrorEvent.count }.by(1)
......@@ -75,7 +76,7 @@ RSpec.describe ErrorTracking::CollectErrorService do
end
context 'go payload' do
let(:parsed_event) { Gitlab::Json.parse(fixture_file('error_tracking/go_parsed_event.json')) }
let(:parsed_event_file) { 'error_tracking/go_parsed_event.json' }
it 'has correct values set' do
subject.execute
......@@ -94,7 +95,7 @@ RSpec.describe ErrorTracking::CollectErrorService do
end
context 'with two exceptions' do
let(:parsed_event) { Gitlab::Json.parse(fixture_file('error_tracking/go_two_exception_event.json')) }
let(:parsed_event_file) { 'error_tracking/go_two_exception_event.json' }
it 'reports using second exception', :aggregate_failures do
subject.execute
......@@ -113,4 +114,17 @@ RSpec.describe ErrorTracking::CollectErrorService do
end
end
end
private
def parse_valid_event(parsed_event_file)
parsed_event = Gitlab::Json.parse(fixture_file(parsed_event_file))
validator = ErrorTracking::Collector::PayloadValidator.new
# This a precondition for all specs to verify that
# submitted JSON payload is valid.
expect(validator).to be_valid(parsed_event)
parsed_event
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment