Add validation and skip logic at #truncate
This commit is contained in:
parent
812dd06d51
commit
28284c1497
2 changed files with 6 additions and 7 deletions
|
@ -28,11 +28,14 @@ module Ci
|
|||
end
|
||||
|
||||
def truncate(offset = 0)
|
||||
self.append("", offset) if offset < size
|
||||
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
|
||||
|
||||
self.append("", offset)
|
||||
end
|
||||
|
||||
def append(new_data, offset)
|
||||
raise ArgumentError, 'Offset is out of range' if offset > data.bytesize || offset < 0
|
||||
raise ArgumentError, 'Offset is out of range' if offset > size || offset < 0
|
||||
raise ArgumentError, 'Chunk size overflow' if CHUNK_SIZE < (offset + new_data.bytesize)
|
||||
|
||||
set_data(data.byteslice(0, offset) + new_data)
|
||||
|
|
|
@ -141,11 +141,7 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
|
|||
context 'when offset is bigger than data size' do
|
||||
let(:offset) { data.bytesize + 1 }
|
||||
|
||||
it do
|
||||
expect_any_instance_of(described_class).not_to receive(:append) { }
|
||||
|
||||
subject
|
||||
end
|
||||
it { expect { subject }.to raise_error('Offset is out of range') }
|
||||
end
|
||||
|
||||
context 'when offset is 10' do
|
||||
|
|
Loading…
Reference in a new issue