diff options
author | Matija Čupić <matteeyah@gmail.com> | 2018-02-06 23:01:36 +0100 |
---|---|---|
committer | Matija Čupić <matteeyah@gmail.com> | 2018-02-12 21:32:55 +0100 |
commit | 7f430a91bd839a396001f25fd8174f8b4d37aca3 (patch) | |
tree | 8fd00a1b84a0416ffd73031b3411d5ddc2f4e61c /spec/workers | |
parent | 0dd202007f902bbde38498f2f424bd4a5c06d814 (diff) | |
download | gitlab-ce-7f430a91bd839a396001f25fd8174f8b4d37aca3.tar.gz |
Add specs for billing_enabled change counter
Diffstat (limited to 'spec/workers')
-rw-r--r-- | spec/workers/check_gcp_project_billing_worker_spec.rb | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/spec/workers/check_gcp_project_billing_worker_spec.rb b/spec/workers/check_gcp_project_billing_worker_spec.rb index 7b7a7c1bc44..5878f5cefa2 100644 --- a/spec/workers/check_gcp_project_billing_worker_spec.rb +++ b/spec/workers/check_gcp_project_billing_worker_spec.rb @@ -6,6 +6,11 @@ describe CheckGcpProjectBillingWorker do subject { described_class.new.perform('token_key') } + before do + allow_any_instance_of(described_class).to receive(:check_previous_state) + allow_any_instance_of(described_class).to receive(:update_billing_change_counter) + end + context 'when there is a token in redis' do before do allow(described_class).to receive(:get_session_token).and_return(token) @@ -58,4 +63,65 @@ describe CheckGcpProjectBillingWorker do end end end + + describe 'billing change counter' do + subject { described_class.new.perform('token_key') } + + before do + allow(described_class).to receive(:get_session_token).and_return('bogustoken') + allow_any_instance_of(described_class).to receive(:try_obtain_lease_for).and_return('randomuuid') + Gitlab::Redis::SharedState.with do |redis| + allow(redis).to receive(:set) + end + end + + context 'when previous state was false' do + before do + expect_any_instance_of(described_class).to receive(:check_previous_state).and_return('false') + end + + context 'when the current state is false' do + before do + expect(CheckGcpProjectBillingService).to receive_message_chain(:new, :execute).and_return([]) + end + + it 'does not increment the billing change counter' do + Gitlab::Redis::SharedState.with do |redis| + expect(redis).not_to receive(:incr) + end + + subject + end + end + + context 'when the current state is true' do + before do + expect(CheckGcpProjectBillingService).to receive_message_chain(:new, :execute).and_return([double]) + end + + it 'increments the billing change counter' do + Gitlab::Redis::SharedState.with do |redis| + expect(redis).to receive(:incr) + end + + subject + end + end + end + + context 'when previous state was true' do + before do + expect_any_instance_of(described_class).to receive(:check_previous_state).and_return('true') + expect(CheckGcpProjectBillingService).to receive_message_chain(:new, :execute).and_return([double]) + end + + it 'does not increment the billing change counter' do + Gitlab::Redis::SharedState.with do |redis| + expect(redis).not_to receive(:incr) + end + + subject + end + end + end end |