Support append/truncate for fog store

This commit is contained in:
Shinya Maeda 2018-06-25 19:59:28 +09:00
parent 44cc587652
commit 58a1a0b70c
2 changed files with 32 additions and 11 deletions

View File

@ -63,7 +63,6 @@ module Ci
end
def truncate(offset = 0)
raise ArgumentError, 'Fog store does not support truncating' if fog? # If data is null, get_data returns Excon::Error::NotFound
raise ArgumentError, 'Offset is out of range' if offset > size || offset < 0
return if offset == size # Skip the following process as it doesn't affect anything
@ -71,7 +70,6 @@ module Ci
end
def append(new_data, offset)
raise ArgumentError, 'Fog store does not support appending' if fog? # If data is null, get_data returns Excon::Error::NotFound
raise ArgumentError, 'New data is nil' unless new_data
raise ArgumentError, 'Offset is out of range' if offset > size || offset < 0
raise ArgumentError, 'Chunk size overflow' if CHUNK_SIZE < (offset + new_data.bytesize)
@ -124,6 +122,8 @@ module Ci
def get_data
self.class.get_store_class(data_store).data(self)&.force_encoding(Encoding::BINARY) # Redis/Database return UTF-8 string as default
rescue Excon::Error::NotFound
# If the data store is :fog and the file does not exist in the object storage, this method returns nil.
end
def unsafe_set_data!(value)

View File

@ -256,11 +256,31 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
context 'when data_store is fog' do
let(:data_store) { :fog }
let(:data) { '' }
let(:offset) { 0 }
it 'can not append' do
expect { subject }.to raise_error('Fog store does not support appending')
context 'when there are no data' do
let(:data) { '' }
it 'has no data' do
expect(build_trace_chunk.data).to be_empty
end
it_behaves_like 'Appending correctly'
it_behaves_like 'Scheduling no sidekiq worker'
end
context 'when there are some data' do
let(:data) { 'Sample data in fog' }
before do
build_trace_chunk.send(:unsafe_set_data!, data)
end
it 'has data' do
expect(build_trace_chunk.data).to eq(data)
end
it_behaves_like 'Appending correctly'
it_behaves_like 'Scheduling no sidekiq worker'
end
end
end
@ -313,12 +333,13 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
context 'when data_store is fog' do
let(:data_store) { :fog }
let(:data) { '' }
let(:offset) { 0 }
let(:data) { 'Sample data in fog' }
it 'can not truncate' do
expect { subject }.to raise_error('Fog store does not support truncating')
before do
build_trace_chunk.send(:unsafe_set_data!, data)
end
it_behaves_like 'truncates'
end
end
@ -373,7 +394,7 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
end
context 'when data does not exist' do
it { expect { subject }.to raise_error(Excon::Error::NotFound) }
it { is_expected.to eq(0) }
end
end
end