Commit 28284c14 authored by Shinya Maeda's avatar Shinya Maeda

Add validation and skip logic at #truncate

parent 812dd06d
...@@ -28,11 +28,14 @@ module Ci ...@@ -28,11 +28,14 @@ module Ci
end end
def truncate(offset = 0) 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 end
def append(new_data, offset) 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) raise ArgumentError, 'Chunk size overflow' if CHUNK_SIZE < (offset + new_data.bytesize)
set_data(data.byteslice(0, offset) + new_data) set_data(data.byteslice(0, offset) + new_data)
......
...@@ -141,11 +141,7 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do ...@@ -141,11 +141,7 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
context 'when offset is bigger than data size' do context 'when offset is bigger than data size' do
let(:offset) { data.bytesize + 1 } let(:offset) { data.bytesize + 1 }
it do it { expect { subject }.to raise_error('Offset is out of range') }
expect_any_instance_of(described_class).not_to receive(:append) { }
subject
end
end end
context 'when offset is 10' do context 'when offset is 10' do
......
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