Commit 1e5a4697 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '352984-1-entity-finisher-not-run-correctly' into 'master'

Handle BulkImports::ExportStatus incorrect export status value

See merge request gitlab-org/gitlab!83811
parents c26b14ae fd9ed096
...@@ -32,10 +32,12 @@ module BulkImports ...@@ -32,10 +32,12 @@ module BulkImports
strong_memoize(:export_status) do strong_memoize(:export_status) do
status = fetch_export_status status = fetch_export_status
relation_export_status = status&.find { |item| item['relation'] == relation }
# Consider empty response as failed export # Consider empty response as failed export
raise StandardError, 'Empty export status response' unless status&.present? raise StandardError, 'Empty relation export status' unless relation_export_status&.present?
status.find { |item| item['relation'] == relation } relation_export_status
end end
rescue StandardError => e rescue StandardError => e
{ 'status' => Export::FAILED, 'error' => e.message } { 'status' => Export::FAILED, 'error' => e.message }
......
...@@ -13,6 +13,10 @@ RSpec.describe BulkImports::ExportStatus do ...@@ -13,6 +13,10 @@ RSpec.describe BulkImports::ExportStatus do
double(parsed_response: [{ 'relation' => 'labels', 'status' => status, 'error' => 'error!' }]) double(parsed_response: [{ 'relation' => 'labels', 'status' => status, 'error' => 'error!' }])
end end
let(:invalid_response_double) do
double(parsed_response: [{ 'relation' => 'not_a_real_relation', 'status' => status, 'error' => 'error!' }])
end
subject { described_class.new(tracker, relation) } subject { described_class.new(tracker, relation) }
before do before do
...@@ -36,6 +40,18 @@ RSpec.describe BulkImports::ExportStatus do ...@@ -36,6 +40,18 @@ RSpec.describe BulkImports::ExportStatus do
it 'returns false' do it 'returns false' do
expect(subject.started?).to eq(false) expect(subject.started?).to eq(false)
end end
context 'when returned relation is invalid' do
before do
allow_next_instance_of(BulkImports::Clients::HTTP) do |client|
allow(client).to receive(:get).and_return(invalid_response_double)
end
end
it 'returns false' do
expect(subject.started?).to eq(false)
end
end
end end
end end
...@@ -63,7 +79,7 @@ RSpec.describe BulkImports::ExportStatus do ...@@ -63,7 +79,7 @@ RSpec.describe BulkImports::ExportStatus do
it 'returns true' do it 'returns true' do
expect(subject.failed?).to eq(true) expect(subject.failed?).to eq(true)
expect(subject.error).to eq('Empty export status response') expect(subject.error).to eq('Empty relation export status')
end end
end 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