diff options
Diffstat (limited to 'spec/lib/gitlab/tracking/destinations')
-rw-r--r-- | spec/lib/gitlab/tracking/destinations/product_analytics_spec.rb | 84 | ||||
-rw-r--r-- | spec/lib/gitlab/tracking/destinations/snowplow_micro_spec.rb | 51 |
2 files changed, 51 insertions, 84 deletions
diff --git a/spec/lib/gitlab/tracking/destinations/product_analytics_spec.rb b/spec/lib/gitlab/tracking/destinations/product_analytics_spec.rb deleted file mode 100644 index 63e2e930acd..00000000000 --- a/spec/lib/gitlab/tracking/destinations/product_analytics_spec.rb +++ /dev/null @@ -1,84 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Gitlab::Tracking::Destinations::ProductAnalytics do - let(:emitter) { SnowplowTracker::Emitter.new('localhost', buffer_size: 1) } - let(:tracker) { SnowplowTracker::Tracker.new(emitter, SnowplowTracker::Subject.new, 'namespace', 'app_id') } - - describe '#event' do - shared_examples 'does not send an event' do - it 'does not send an event' do - expect_any_instance_of(SnowplowTracker::Tracker).not_to receive(:track_struct_event) - - subject.event(allowed_category, allowed_action) - end - end - - let(:allowed_category) { 'epics' } - let(:allowed_action) { 'promote' } - let(:self_monitoring_project) { create(:project) } - - before do - stub_feature_flags(product_analytics_tracking: true) - stub_application_setting(self_monitoring_project_id: self_monitoring_project.id) - stub_application_setting(usage_ping_enabled: true) - end - - context 'with allowed event' do - it 'sends an event to Product Analytics snowplow collector' do - expect(SnowplowTracker::AsyncEmitter) - .to receive(:new) - .with(ProductAnalytics::Tracker::COLLECTOR_URL, protocol: Gitlab.config.gitlab.protocol) - .and_return(emitter) - - expect(SnowplowTracker::Tracker) - .to receive(:new) - .with(emitter, an_instance_of(SnowplowTracker::Subject), Gitlab::Tracking::SNOWPLOW_NAMESPACE, self_monitoring_project.id.to_s) - .and_return(tracker) - - freeze_time do - expect(tracker) - .to receive(:track_struct_event) - .with(allowed_category, allowed_action, 'label', 'property', 1.5, nil, (Time.now.to_f * 1000).to_i) - - subject.event(allowed_category, allowed_action, label: 'label', property: 'property', value: 1.5) - end - end - end - - context 'with non-allowed event' do - it 'does not send an event' do - expect_any_instance_of(SnowplowTracker::Tracker).not_to receive(:track_struct_event) - - subject.event('category', 'action') - subject.event(allowed_category, 'action') - subject.event('category', allowed_action) - end - end - - context 'when self-monitoring project does not exist' do - before do - stub_application_setting(self_monitoring_project_id: nil) - end - - include_examples 'does not send an event' - end - - context 'when product_analytics_tracking FF is disabled' do - before do - stub_feature_flags(product_analytics_tracking: false) - end - - include_examples 'does not send an event' - end - - context 'when usage ping is disabled' do - before do - stub_application_setting(usage_ping_enabled: false) - end - - include_examples 'does not send an event' - end - end -end diff --git a/spec/lib/gitlab/tracking/destinations/snowplow_micro_spec.rb b/spec/lib/gitlab/tracking/destinations/snowplow_micro_spec.rb new file mode 100644 index 00000000000..6004698d092 --- /dev/null +++ b/spec/lib/gitlab/tracking/destinations/snowplow_micro_spec.rb @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Tracking::Destinations::SnowplowMicro do + include StubENV + + before do + stub_application_setting(snowplow_enabled: true) + stub_env('SNOWPLOW_MICRO_ENABLE', '1') + allow(Rails.env).to receive(:development?).and_return(true) + end + + describe '#hostname' do + context 'when SNOWPLOW_MICRO_URI is set' do + before do + stub_env('SNOWPLOW_MICRO_URI', 'http://gdk.test:9091') + end + + it 'returns hostname URI part' do + expect(subject.hostname).to eq('gdk.test:9091') + end + end + + context 'when SNOWPLOW_MICRO_URI is without protocol' do + before do + stub_env('SNOWPLOW_MICRO_URI', 'gdk.test:9091') + end + + it 'returns hostname URI part' do + expect(subject.hostname).to eq('gdk.test:9091') + end + end + + context 'when SNOWPLOW_MICRO_URI is hostname only' do + before do + stub_env('SNOWPLOW_MICRO_URI', 'uriwithoutport') + end + + it 'returns hostname URI with default HTTP port' do + expect(subject.hostname).to eq('uriwithoutport:80') + end + end + + context 'when SNOWPLOW_MICRO_URI is not set' do + it 'returns localhost hostname' do + expect(subject.hostname).to eq('localhost:9090') + end + end + end +end |