2022-11-25 23:54:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe Gitlab::Tracking::ServicePingContext do
|
|
|
|
describe '#init' do
|
2023-03-04 22:38:38 +05:30
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
|
|
|
context 'with valid configuration' do
|
|
|
|
where(:data_source, :event, :key_path) do
|
|
|
|
:redis | nil | 'counts.some_metric'
|
|
|
|
:redis_hll | 'some_event' | nil
|
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
it 'does not raise errors' do
|
|
|
|
expect { described_class.new(data_source: data_source, event: event, key_path: key_path) }.not_to raise_error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with invalid configuration' do
|
|
|
|
where(:data_source, :event, :key_path) do
|
|
|
|
:redis | nil | nil
|
|
|
|
:redis | 'some_event' | nil
|
|
|
|
:redis_hll | nil | nil
|
|
|
|
:redis_hll | nil | 'some key_path'
|
|
|
|
:random | 'some_event' | nil
|
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
subject(:new_instance) { described_class.new(data_source: data_source, event: event, key_path: key_path) }
|
|
|
|
|
|
|
|
it 'does not raise errors' do
|
|
|
|
expect { new_instance }.to raise_error(ArgumentError)
|
|
|
|
end
|
|
|
|
end
|
2022-11-25 23:54:43 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#to_context' do
|
2023-03-04 22:38:38 +05:30
|
|
|
context 'for redis_hll data source' do
|
|
|
|
let(:context_instance) { described_class.new(data_source: :redis_hll, event: 'sample_event') }
|
|
|
|
|
|
|
|
it 'contains event_name' do
|
|
|
|
expect(context_instance.to_context.to_json.dig(:data, :event_name)).to eq('sample_event')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for redis data source' do
|
|
|
|
let(:context_instance) { described_class.new(data_source: :redis, key_path: 'counts.sample_metric') }
|
2022-11-25 23:54:43 +05:30
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
it 'contains event_name' do
|
|
|
|
expect(context_instance.to_context.to_json.dig(:data, :key_path)).to eq('counts.sample_metric')
|
|
|
|
end
|
2022-11-25 23:54:43 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|