From 15cd91c71a57a0b84af620181a64b26d5aec8237 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Trzci=C5=84ski?= Date: Mon, 15 Oct 2018 12:17:21 +0200 Subject: Make all legacy security reports to use raw format - This introduces and uses `:raw` format for all legacy reports, the ones that do not have yet proper parsers on Backend - Raw format is needed to make Frontend be able to parse reports, without the need of decompressing, - This also extends fixtures to seed security reports with database, even though parser code is part of EE --- .../build/artifacts/adapters/gzip_stream_spec.rb | 56 ++++++++++++++++++++++ .../ci/build/artifacts/adapters/raw_stream_spec.rb | 47 ++++++++++++++++++ .../ci/build/artifacts/gzip_file_adapter_spec.rb | 56 ---------------------- 3 files changed, 103 insertions(+), 56 deletions(-) create mode 100644 spec/lib/gitlab/ci/build/artifacts/adapters/gzip_stream_spec.rb create mode 100644 spec/lib/gitlab/ci/build/artifacts/adapters/raw_stream_spec.rb delete mode 100644 spec/lib/gitlab/ci/build/artifacts/gzip_file_adapter_spec.rb (limited to 'spec/lib') diff --git a/spec/lib/gitlab/ci/build/artifacts/adapters/gzip_stream_spec.rb b/spec/lib/gitlab/ci/build/artifacts/adapters/gzip_stream_spec.rb new file mode 100644 index 00000000000..987c6b37aaa --- /dev/null +++ b/spec/lib/gitlab/ci/build/artifacts/adapters/gzip_stream_spec.rb @@ -0,0 +1,56 @@ +require 'spec_helper' + +describe Gitlab::Ci::Build::Artifacts::Adapters::GzipStream do + describe '#initialize' do + context 'when stream is passed' do + let(:stream) { File.open(expand_fixture_path('junit/junit.xml.gz'), 'rb') } + + it 'initialized' do + expect { described_class.new(stream) }.not_to raise_error + end + end + + context 'when stream is not passed' do + let(:stream) { nil } + + it 'raises an error' do + expect { described_class.new(stream) }.to raise_error(described_class::InvalidStreamError) + end + end + end + + describe '#each_blob' do + let(:adapter) { described_class.new(stream) } + + context 'when stream is gzip file' do + context 'when gzip file contains one file' do + let(:stream) { File.open(expand_fixture_path('junit/junit.xml.gz'), 'rb') } + + it 'iterates content and file_name' do + expect { |b| adapter.each_blob(&b) } + .to yield_with_args(fixture_file('junit/junit.xml'), 'rspec.xml') + end + end + + context 'when gzip file contains three files' do + let(:stream) { File.open(expand_fixture_path('junit/junit_with_three_testsuites.xml.gz'), 'rb') } + + it 'iterates content and file_name' do + expect { |b| adapter.each_blob(&b) } + .to yield_successive_args( + [fixture_file('junit/junit_with_three_testsuites_1.xml'), 'rspec-3.xml'], + [fixture_file('junit/junit_with_three_testsuites_2.xml'), 'rspec-1.xml'], + [fixture_file('junit/junit_with_three_testsuites_3.xml'), 'rspec-2.xml']) + end + end + end + + context 'when stream is zip file' do + let(:stream) { File.open(expand_fixture_path('ci_build_artifacts.zip'), 'rb') } + + it 'raises an error' do + expect { |b| adapter.each_blob(&b) }.to raise_error(described_class::InvalidStreamError) + end + end + end +end diff --git a/spec/lib/gitlab/ci/build/artifacts/adapters/raw_stream_spec.rb b/spec/lib/gitlab/ci/build/artifacts/adapters/raw_stream_spec.rb new file mode 100644 index 00000000000..ec2dd724b45 --- /dev/null +++ b/spec/lib/gitlab/ci/build/artifacts/adapters/raw_stream_spec.rb @@ -0,0 +1,47 @@ +require 'spec_helper' + +describe Gitlab::Ci::Build::Artifacts::Adapters::RawStream do + describe '#initialize' do + context 'when stream is passed' do + let(:stream) { File.open(expand_fixture_path('junit/junit.xml'), 'rb') } + + it 'initialized' do + expect { described_class.new(stream) }.not_to raise_error + end + end + + context 'when stream is not passed' do + let(:stream) { nil } + + it 'raises an error' do + expect { described_class.new(stream) }.to raise_error(described_class::InvalidStreamError) + end + end + end + + describe '#each_blob' do + let(:adapter) { described_class.new(stream) } + + context 'when file is not empty' do + let(:stream) { File.open(expand_fixture_path('junit/junit.xml'), 'rb') } + + it 'iterates content' do + expect { |b| adapter.each_blob(&b) } + .to yield_with_args(fixture_file('junit/junit.xml'), 'raw') + end + end + + context 'when file is empty' do + let(:stream) { Tempfile.new } + + after do + stream.unlink + end + + it 'does not iterate content' do + expect { |b| adapter.each_blob(&b) } + .not_to yield_control + end + end + end +end diff --git a/spec/lib/gitlab/ci/build/artifacts/gzip_file_adapter_spec.rb b/spec/lib/gitlab/ci/build/artifacts/gzip_file_adapter_spec.rb deleted file mode 100644 index 384329dda18..00000000000 --- a/spec/lib/gitlab/ci/build/artifacts/gzip_file_adapter_spec.rb +++ /dev/null @@ -1,56 +0,0 @@ -require 'spec_helper' - -describe Gitlab::Ci::Build::Artifacts::GzipFileAdapter do - describe '#initialize' do - context 'when stream is passed' do - let(:stream) { File.open(expand_fixture_path('junit/junit.xml.gz'), 'rb') } - - it 'initialized' do - expect { described_class.new(stream) }.not_to raise_error - end - end - - context 'when stream is not passed' do - let(:stream) { nil } - - it 'raises an error' do - expect { described_class.new(stream) }.to raise_error(described_class::InvalidStreamError) - end - end - end - - describe '#each_blob' do - let(:adapter) { described_class.new(stream) } - - context 'when stream is gzip file' do - context 'when gzip file contains one file' do - let(:stream) { File.open(expand_fixture_path('junit/junit.xml.gz'), 'rb') } - - it 'iterates content and file_name' do - expect { |b| adapter.each_blob(&b) } - .to yield_with_args(fixture_file('junit/junit.xml'), 'rspec.xml') - end - end - - context 'when gzip file contains three files' do - let(:stream) { File.open(expand_fixture_path('junit/junit_with_three_testsuites.xml.gz'), 'rb') } - - it 'iterates content and file_name' do - expect { |b| adapter.each_blob(&b) } - .to yield_successive_args( - [fixture_file('junit/junit_with_three_testsuites_1.xml'), 'rspec-3.xml'], - [fixture_file('junit/junit_with_three_testsuites_2.xml'), 'rspec-1.xml'], - [fixture_file('junit/junit_with_three_testsuites_3.xml'), 'rspec-2.xml']) - end - end - end - - context 'when stream is zip file' do - let(:stream) { File.open(expand_fixture_path('ci_build_artifacts.zip'), 'rb') } - - it 'raises an error' do - expect { |b| adapter.each_blob(&b) }.to raise_error(described_class::InvalidStreamError) - end - end - end -end -- cgit v1.2.1