Welcome to mirror list, hosted at ThFree Co, Russian Federation.

snowplow_micro_spec.rb « destinations « tracking « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 19b578a4d6dfec23c48777f94662626e14294406 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Tracking::Destinations::SnowplowMicro, feature_category: :application_instrumentation do
  include StubENV

  let(:snowplow_micro_settings) do
    {
      enabled: true,
      address: address
    }
  end

  let(:address) { "gdk.test:9091" }

  before do
    allow(Rails.env).to receive(:development?).and_return(true)
  end

  it { is_expected.to delegate_method(:flush).to(:tracker) }

  describe '#hostname' do
    context 'when snowplow_micro config is set' do
      let(:address) { '127.0.0.1:9091' }

      before do
        stub_config(snowplow_micro: snowplow_micro_settings)
      end

      it 'returns proper URI' do
        expect(subject.hostname).to eq('127.0.0.1:9091')
        expect(subject.uri.scheme).to eq('http')
      end

      context 'when gitlab config has https scheme' do
        before do
          stub_config_setting(https: true)
        end

        it 'returns proper URI' do
          expect(subject.hostname).to eq('127.0.0.1:9091')
          expect(subject.uri.scheme).to eq('https')
        end
      end
    end

    context 'when snowplow_micro config is not set' do
      before do
        allow(Gitlab.config).to receive(:snowplow_micro).and_raise(GitlabSettings::MissingSetting)
      end

      it 'returns localhost hostname' do
        expect(subject.hostname).to eq('localhost:9090')
      end
    end
  end

  describe '#options' do
    let_it_be(:group) { create :group }

    before do
      stub_config(snowplow_micro: snowplow_micro_settings)
    end

    it 'includes protocol with the correct value' do
      expect(subject.options(group)[:protocol]).to eq 'http'
    end

    it 'includes port with the correct value' do
      expect(subject.options(group)[:port]).to eq 9091
    end

    it 'includes forceSecureTracker with value false' do
      expect(subject.options(group)[:forceSecureTracker]).to eq false
    end
  end
end