Commit 6a939f64 authored by Shinya Maeda's avatar Shinya Maeda

Add Content-range test for GCS

parent 331c36d1
......@@ -146,14 +146,14 @@ module Gitlab
##
# Note: If provider does not return content_range, then we set it as we requested
# Provider: minio
# - When the file size is larger than Content-range in responce header, it returns content_range in responce header. Status: Net::HTTPPartialContent 206
# - When the file size is smaller than Content-range in responce header, it returns content_range in responce header. Status: Net::HTTPPartialContent 206
# - When the file size is larger than requested Content-range, the Content-range is included in responces with Net::HTTPPartialContent 206
# - When the file size is smaller than requested Content-range, the Content-range is included in responces with Net::HTTPPartialContent 206
# Provider: AWS
# - TBD
# - TBD
# - When the file size is larger than requested Content-range, the Content-range is included in responces with Net::HTTPPartialContent 206
# - When the file size is smaller than requested Content-range, the Content-range is included in responces with Net::HTTPPartialContent 206
# Provider: GCS
# - When the file size is larger than Content-range, it returns content_range in responce header. Status: Net::HTTPPartialContent 206
# - When the file size is smaller than Content-range, it does not return content_range in responce header. Status: Net::HTTPOK 200
# - When the file size is larger than requested Content-range, the Content-range is included in responces with Net::HTTPPartialContent 206
# - When the file size is smaller than requested Content-range, the Content-range is included in responces with Net::HTTPOK 200
@chunk_range ||= (chunk_start...(chunk_start + @chunk.length))
end
......
......@@ -103,12 +103,27 @@ describe Gitlab::Ci::Trace::HttpIO do
let(:string_io) { StringIO.new(remote_trace_body) }
before do
stub_remote_trace_ok
stub_remote_trace_206
end
it 'yields lines' do
expect { |b| http_io.each_line(&b) }.to yield_successive_args(*string_io.each_line.to_a)
end
context 'when buckets on GCS' do
context 'when BUFFER_SIZE is larger than file size' do
before do
stub_remote_trace_200
set_larger_buffer_size_than(size)
end
it 'calls get_chunk only once' do
expect_any_instance_of(Net::HTTP).to receive(:request).once.and_call_original
http_io.each_line { |line| }
end
end
end
end
describe '#read' do
......@@ -116,7 +131,7 @@ describe Gitlab::Ci::Trace::HttpIO do
context 'when there are no network issue' do
before do
stub_remote_trace_ok
stub_remote_trace_206
end
context 'when read whole size' do
......@@ -220,7 +235,7 @@ describe Gitlab::Ci::Trace::HttpIO do
let(:length) { nil }
before do
stub_remote_trace_ng
stub_remote_trace_500
end
it 'reads a trace' do
......@@ -235,7 +250,7 @@ describe Gitlab::Ci::Trace::HttpIO do
let(:string_io) { StringIO.new(remote_trace_body) }
before do
stub_remote_trace_ok
stub_remote_trace_206
end
shared_examples 'all line matching' do
......@@ -250,7 +265,7 @@ describe Gitlab::Ci::Trace::HttpIO do
let(:length) { nil }
before do
stub_remote_trace_ng
stub_remote_trace_500
end
it 'reads a trace' do
......
module HttpIOHelpers
def stub_remote_trace_ok
def stub_remote_trace_206
WebMock.stub_request(:get, remote_trace_url)
.to_return { |request| remote_trace_response(request) }
.to_return { |request| remote_trace_response(request, 206) }
end
def stub_remote_trace_ng
def stub_remote_trace_200
WebMock.stub_request(:get, remote_trace_url)
.to_return { |request| remote_trace_response(request, 200) }
end
def stub_remote_trace_500
WebMock.stub_request(:get, remote_trace_url)
.to_return(status: [500, "Internal Server Error"])
end
......@@ -13,16 +18,26 @@ module HttpIOHelpers
"http://trace.com/trace"
end
def remote_trace_response(request)
def remote_trace_response(request, responce_status)
range = request.headers['Range'].match(/bytes=(\d+)-(\d+)/)
{
status: 200,
headers: { 'Content-Type' => 'text/plain' },
status: responce_status,
headers: remote_trace_response_headers(responce_status, range[1].to_i, range[2].to_i),
body: range_trace_body(range[1].to_i, range[2].to_i)
}
end
def remote_trace_response_headers(responce_status, from, to)
headers = { 'Content-Type' => 'text/plain' }
if responce_status == 206
headers.merge('Content-Range' => "bytes #{from}-#{to}/#{remote_trace_size}")
end
headers
end
def range_trace_body(from, to)
remote_trace_body[from..to]
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