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 ...@@ -18,43 +18,25 @@ RSpec.describe ErrorTracking::Collector::PayloadValidator do
end end
end end
context 'ruby payload' do context 'with event fixtures' do
let(:payload) { Gitlab::Json.parse(fixture_file('error_tracking/parsed_event.json')) } where(:event_fixture) do
Dir.glob(Rails.root.join('spec/fixtures/error_tracking/*event*.json'))
it_behaves_like 'valid payload' end
end
context 'python payload' do
let(:payload) { Gitlab::Json.parse(fixture_file('error_tracking/python_event.json')) }
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 with_them do
let(:payload) { Gitlab::Json.parse(fixture_file('error_tracking/go_parsed_event.json')) } let(:payload) { Gitlab::Json.parse(fixture_file(event_fixture)) }
it_behaves_like 'valid payload' it_behaves_like 'valid payload'
end
end end
context 'empty payload' do context 'when empty' do
let(:payload) { '' } let(:payload) { '' }
it_behaves_like 'invalid payload' it_behaves_like 'invalid payload'
end end
context 'invalid payload' do context 'when invalid' do
let(:payload) { { 'foo' => 'bar' } } let(:payload) { { 'foo' => 'bar' } }
it_behaves_like 'invalid payload' it_behaves_like 'invalid payload'
......
...@@ -4,8 +4,9 @@ require 'spec_helper' ...@@ -4,8 +4,9 @@ require 'spec_helper'
RSpec.describe ErrorTracking::CollectErrorService do RSpec.describe ErrorTracking::CollectErrorService do
let_it_be(:project) { create(:project) } 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) } subject { described_class.new(project, nil, event: parsed_event) }
...@@ -43,7 +44,7 @@ RSpec.describe ErrorTracking::CollectErrorService do ...@@ -43,7 +44,7 @@ RSpec.describe ErrorTracking::CollectErrorService do
end end
context 'python sdk event' do 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 it 'creates a valid event' do
expect { subject.execute }.to change { ErrorTracking::ErrorEvent.count }.by(1) expect { subject.execute }.to change { ErrorTracking::ErrorEvent.count }.by(1)
...@@ -75,7 +76,7 @@ RSpec.describe ErrorTracking::CollectErrorService do ...@@ -75,7 +76,7 @@ RSpec.describe ErrorTracking::CollectErrorService do
end end
context 'go payload' do 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 it 'has correct values set' do
subject.execute subject.execute
...@@ -94,7 +95,7 @@ RSpec.describe ErrorTracking::CollectErrorService do ...@@ -94,7 +95,7 @@ RSpec.describe ErrorTracking::CollectErrorService do
end end
context 'with two exceptions' do 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 it 'reports using second exception', :aggregate_failures do
subject.execute subject.execute
...@@ -113,4 +114,17 @@ RSpec.describe ErrorTracking::CollectErrorService do ...@@ -113,4 +114,17 @@ RSpec.describe ErrorTracking::CollectErrorService do
end end
end 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 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