diff options
Diffstat (limited to 'spec/lib/gitlab/middleware')
-rw-r--r-- | spec/lib/gitlab/middleware/request_context_spec.rb | 43 |
1 files changed, 13 insertions, 30 deletions
diff --git a/spec/lib/gitlab/middleware/request_context_spec.rb b/spec/lib/gitlab/middleware/request_context_spec.rb index 431f4453e37..6d5b581feaa 100644 --- a/spec/lib/gitlab/middleware/request_context_spec.rb +++ b/spec/lib/gitlab/middleware/request_context_spec.rb @@ -18,9 +18,11 @@ RSpec.describe Gitlab::Middleware::RequestContext do end describe '#call' do - context 'setting the client ip' do - subject { Gitlab::RequestContext.instance.client_ip } + let(:instance) { Gitlab::RequestContext.instance } + + subject { described_class.new(app).call(env) } + context 'setting the client ip' do context 'with X-Forwarded-For headers' do let(:load_balancer_ip) { '1.2.3.4' } let(:headers) do @@ -33,13 +35,7 @@ RSpec.describe Gitlab::Middleware::RequestContext do let(:env) { Rack::MockRequest.env_for("/").merge(headers) } it 'returns the load balancer IP' do - endpoint = proc do - [200, {}, ["Hello"]] - end - - described_class.new(endpoint).call(env) - - expect(subject).to eq(load_balancer_ip) + expect { subject }.to change { instance.client_ip }.from(nil).to(load_balancer_ip) end end @@ -47,32 +43,19 @@ RSpec.describe Gitlab::Middleware::RequestContext do let(:ip) { '192.168.1.11' } before do - allow_next_instance_of(Rack::Request) do |instance| - allow(instance).to receive(:ip).and_return(ip) + allow_next_instance_of(Rack::Request) do |request| + allow(request).to receive(:ip).and_return(ip) end - described_class.new(app).call(env) end - it { is_expected.to eq(ip) } - end + it 'sets the `client_ip`' do + expect { subject }.to change { instance.client_ip }.from(nil).to(ip) + end - context 'before RequestContext middleware run' do - it { is_expected.to be_nil } + it 'sets the `request_start_time`' do + expect { subject }.to change { instance.request_start_time }.from(nil).to(Float) + end end end end - - context 'setting the thread cpu time' do - it 'sets the `start_thread_cpu_time`' do - expect { described_class.new(app).call(env) } - .to change { Gitlab::RequestContext.instance.start_thread_cpu_time }.from(nil).to(Float) - end - end - - context 'setting the request start time' do - it 'sets the `request_start_time`' do - expect { described_class.new(app).call(env) } - .to change { Gitlab::RequestContext.instance.request_start_time }.from(nil).to(Float) - end - end end |