summaryrefslogtreecommitdiff
path: root/spec/support/helpers/stub_metrics.rb
blob: e347955efbbf36bce92fb6fd420aed1e8325536f (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
# frozen_string_literal: true

module StubMetrics
  def authentication_metrics
    Gitlab::Auth::Activity
  end

  def stub_authentication_activity_metrics(debug: false)
    authentication_metrics.each_counter do |name, metric, description|
      allow(authentication_metrics).to receive(name)
        .and_return(double("#{metric} - #{description}"))
    end

    debug_authentication_activity_metrics if debug
  end

  def debug_authentication_activity_metrics
    authentication_metrics.tap do |metrics|
      metrics.each_counter do |name, metric|
        "#{name}_increment!".tap do |incrementer|
          allow(metrics).to receive(incrementer).and_wrap_original do |method|
            puts "Authentication activity metric incremented: #{name}"
            method.call
          end
        end
      end
    end
  end
end