diff options
Diffstat (limited to 'spec/lib/gitlab/usage_data_counters')
-rw-r--r-- | spec/lib/gitlab/usage_data_counters/kubernetes_agent_counter_spec.rb | 23 | ||||
-rw-r--r-- | spec/lib/gitlab/usage_data_counters/redis_counter_spec.rb | 48 |
2 files changed, 59 insertions, 12 deletions
diff --git a/spec/lib/gitlab/usage_data_counters/kubernetes_agent_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/kubernetes_agent_counter_spec.rb new file mode 100644 index 00000000000..8f9a3e0cd9e --- /dev/null +++ b/spec/lib/gitlab/usage_data_counters/kubernetes_agent_counter_spec.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::UsageDataCounters::KubernetesAgentCounter do + it_behaves_like 'a redis usage counter', 'Kubernetes Agent', :gitops_sync + + it_behaves_like 'a redis usage counter with totals', :kubernetes_agent, gitops_sync: 1 + + describe '.increment_gitops_sync' do + it 'increments the gtops_sync counter by the new increment amount' do + described_class.increment_gitops_sync(7) + described_class.increment_gitops_sync(2) + described_class.increment_gitops_sync(0) + + expect(described_class.totals).to eq(kubernetes_agent_gitops_sync: 9) + end + + it 'raises for negative numbers' do + expect { described_class.increment_gitops_sync(-1) }.to raise_error(ArgumentError) + end + end +end diff --git a/spec/lib/gitlab/usage_data_counters/redis_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/redis_counter_spec.rb index be528b081c5..d4f6110b3df 100644 --- a/spec/lib/gitlab/usage_data_counters/redis_counter_spec.rb +++ b/spec/lib/gitlab/usage_data_counters/redis_counter_spec.rb @@ -11,23 +11,47 @@ RSpec.describe Gitlab::UsageDataCounters::RedisCounter, :clean_gitlab_redis_shar stub_application_setting(usage_ping_enabled: setting_value) end - context 'when usage_ping is disabled' do - let(:setting_value) { false } + describe '.increment' do + context 'when usage_ping is disabled' do + let(:setting_value) { false } + + it 'counter is not increased' do + expect do + subject.increment(redis_key) + end.not_to change { subject.total_count(redis_key) } + end + end + + context 'when usage_ping is enabled' do + let(:setting_value) { true } - it 'counter is not increased' do - expect do - subject.increment(redis_key) - end.not_to change { subject.total_count(redis_key) } + it 'counter is increased' do + expect do + subject.increment(redis_key) + end.to change { subject.total_count(redis_key) }.by(1) + end end end - context 'when usage_ping is enabled' do - let(:setting_value) { true } + describe '.increment_by' do + context 'when usage_ping is disabled' do + let(:setting_value) { false } + + it 'counter is not increased' do + expect do + subject.increment_by(redis_key, 3) + end.not_to change { subject.total_count(redis_key) } + end + end + + context 'when usage_ping is enabled' do + let(:setting_value) { true } - it 'counter is increased' do - expect do - subject.increment(redis_key) - end.to change { subject.total_count(redis_key) }.by(1) + it 'counter is increased' do + expect do + subject.increment_by(redis_key, 3) + end.to change { subject.total_count(redis_key) }.by(3) + end end end end |