diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
commit | e8d2c2579383897a1dd7f9debd359abe8ae8373d (patch) | |
tree | c42be41678c2586d49a75cabce89322082698334 /spec/lib/error_tracking | |
parent | fc845b37ec3a90aaa719975f607740c22ba6a113 (diff) |
Add latest changes from gitlab-org/gitlab@14-1-stable-eev14.1.0-rc42
Diffstat (limited to 'spec/lib/error_tracking')
-rw-r--r-- | spec/lib/error_tracking/collector/sentry_request_parser_spec.rb | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/spec/lib/error_tracking/collector/sentry_request_parser_spec.rb b/spec/lib/error_tracking/collector/sentry_request_parser_spec.rb new file mode 100644 index 00000000000..6f12c6d25e0 --- /dev/null +++ b/spec/lib/error_tracking/collector/sentry_request_parser_spec.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe ErrorTracking::Collector::SentryRequestParser do + describe '.parse' do + let_it_be(:raw_event) { fixture_file('error_tracking/event.txt') } + let_it_be(:parsed_event) { Gitlab::Json.parse(fixture_file('error_tracking/parsed_event.json')) } + + let(:body) { raw_event } + let(:headers) { { 'Content-Encoding' => '' } } + let(:request) { double('request', headers: headers, body: StringIO.new(body)) } + + subject { described_class.parse(request) } + + RSpec.shared_examples 'valid parser' do + it 'returns a valid hash' do + parsed_request = subject + + expect(parsed_request[:request_type]).to eq('event') + expect(parsed_request[:event]).to eq(parsed_event) + end + end + + context 'empty body content' do + let(:body) { '' } + + it 'fails with exception' do + expect { subject }.to raise_error(StandardError) + end + end + + context 'plain text sentry request' do + it_behaves_like 'valid parser' + end + + context 'gzip encoded sentry request' do + let(:headers) { { 'Content-Encoding' => 'gzip' } } + let(:body) { Zlib.gzip(raw_event) } + + it_behaves_like 'valid parser' + end + end +end |