diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2018-07-31 10:44:22 +0000 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2018-07-31 10:44:22 +0000 |
commit | e6dd3c527626af1c0f521792360f7c4b29bfee36 (patch) | |
tree | 79dee0a3eb392d42478011af8e3eaa8d94c3e370 /spec/support | |
parent | eb8597a1b9eb575121f09b8b9904c0ad7cd489cc (diff) | |
parent | 3b81345a730714a94b3e15f0eb91c4f1e8216a44 (diff) | |
download | gitlab-ce-e6dd3c527626af1c0f521792360f7c4b29bfee36.tar.gz |
Merge branch 'feature/gb/login-activity-metrics' into 'master'
Add user authentication activity metrics
Closes #47789
See merge request gitlab-org/gitlab-ce!20668
Diffstat (limited to 'spec/support')
-rw-r--r-- | spec/support/helpers/stub_metrics.rb | 27 | ||||
-rw-r--r-- | spec/support/matchers/metric_counter_matcher.rb | 11 | ||||
-rw-r--r-- | spec/support/rspec.rb | 2 |
3 files changed, 40 insertions, 0 deletions
diff --git a/spec/support/helpers/stub_metrics.rb b/spec/support/helpers/stub_metrics.rb new file mode 100644 index 00000000000..64983fdf222 --- /dev/null +++ b/spec/support/helpers/stub_metrics.rb @@ -0,0 +1,27 @@ +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 diff --git a/spec/support/matchers/metric_counter_matcher.rb b/spec/support/matchers/metric_counter_matcher.rb new file mode 100644 index 00000000000..22d5cd17e3f --- /dev/null +++ b/spec/support/matchers/metric_counter_matcher.rb @@ -0,0 +1,11 @@ +RSpec::Matchers.define :increment do |counter| + match do |adapter| + expect(adapter.send(counter)) + .to receive(:increment) + .exactly(@exactly || :once) + end + + chain :twice do + @exactly = :twice + end +end diff --git a/spec/support/rspec.rb b/spec/support/rspec.rb index 54b8df7aa19..9b8bcebcb3a 100644 --- a/spec/support/rspec.rb +++ b/spec/support/rspec.rb @@ -1,4 +1,5 @@ require_relative "helpers/stub_configuration" +require_relative "helpers/stub_metrics" require_relative "helpers/stub_object_storage" require_relative "helpers/stub_env" @@ -7,6 +8,7 @@ RSpec.configure do |config| config.raise_errors_for_deprecations! config.include StubConfiguration + config.include StubMetrics config.include StubObjectStorage config.include StubENV |