diff options
Diffstat (limited to 'spec/lib/gitlab/grape_logging/loggers')
3 files changed, 51 insertions, 3 deletions
diff --git a/spec/lib/gitlab/grape_logging/loggers/perf_logger_spec.rb b/spec/lib/gitlab/grape_logging/loggers/perf_logger_spec.rb index 641fb27a071..ef4bc0ca104 100644 --- a/spec/lib/gitlab/grape_logging/loggers/perf_logger_spec.rb +++ b/spec/lib/gitlab/grape_logging/loggers/perf_logger_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe Gitlab::GrapeLogging::Loggers::PerfLogger do - let(:mock_request) { OpenStruct.new(env: {}) } + let(:mock_request) { double('env', env: {}) } describe ".parameters" do subject { described_class.new.parameters(mock_request, nil) } diff --git a/spec/lib/gitlab/grape_logging/loggers/queue_duration_logger_spec.rb b/spec/lib/gitlab/grape_logging/loggers/queue_duration_logger_spec.rb index 9538c4bae2b..4cd9f9dfad0 100644 --- a/spec/lib/gitlab/grape_logging/loggers/queue_duration_logger_spec.rb +++ b/spec/lib/gitlab/grape_logging/loggers/queue_duration_logger_spec.rb @@ -9,7 +9,7 @@ RSpec.describe Gitlab::GrapeLogging::Loggers::QueueDurationLogger do let(:start_time) { Time.new(2018, 01, 01) } describe 'when no proxy time is available' do - let(:mock_request) { OpenStruct.new(env: {}) } + let(:mock_request) { double('env', env: {}) } it 'returns an empty hash' do expect(subject.parameters(mock_request, nil)).to eq({}) @@ -18,7 +18,7 @@ RSpec.describe Gitlab::GrapeLogging::Loggers::QueueDurationLogger do describe 'when a proxy time is available' do let(:mock_request) do - OpenStruct.new( + double('env', env: { 'HTTP_GITLAB_WORKHORSE_PROXY_START' => (start_time - 1.hour).to_i * (10**9) } diff --git a/spec/lib/gitlab/grape_logging/loggers/urgency_logger_spec.rb b/spec/lib/gitlab/grape_logging/loggers/urgency_logger_spec.rb new file mode 100644 index 00000000000..464534f0271 --- /dev/null +++ b/spec/lib/gitlab/grape_logging/loggers/urgency_logger_spec.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::GrapeLogging::Loggers::UrgencyLogger do + def endpoint(options, namespace: '') + Struct.new(:options, :namespace).new(options, namespace) + end + + let(:api_class) do + Class.new(API::Base) do + namespace 'testing' do + # rubocop:disable Rails/HttpPositionalArguments + # This is not the get that performs a request, but the one from Grape + get 'test', urgency: :high do + {} + end + # rubocop:enable Rails/HttpPositionalArguments + end + end + end + + describe ".parameters" do + where(:request_env, :expected_parameters) do + [ + [{}, {}], + [{ 'api.endpoint' => endpoint({}) }, {}], + [{ 'api.endpoint' => endpoint({ for: 'something weird' }) }, {}], + [ + { 'api.endpoint' => endpoint({ for: api_class, path: [] }) }, + { request_urgency: :default, target_duration_s: 1 } + ], + [ + { 'api.endpoint' => endpoint({ for: api_class, path: ['test'] }, namespace: '/testing') }, + { request_urgency: :high, target_duration_s: 0.25 } + ] + ] + end + + with_them do + let(:request) { double('request', env: request_env) } + + subject { described_class.new.parameters(request, nil) } + + it { is_expected.to eq(expected_parameters) } + end + end +end |