diff options
author | Matija Čupić <matteeyah@gmail.com> | 2018-01-06 19:02:18 +0100 |
---|---|---|
committer | Matija Čupić <matteeyah@gmail.com> | 2018-01-06 19:41:28 +0100 |
commit | a180306da8daff608f7910af0f759a7dba8f15be (patch) | |
tree | 7cce1e58c931d71a43fdf6bf1a7560a8090ea05a /spec | |
parent | 2885dc06602d8bff42421d38502f85965b7e8b34 (diff) | |
download | gitlab-ce-a180306da8daff608f7910af0f759a7dba8f15be.tar.gz |
Use token from redis in gcp project billing worker
Diffstat (limited to 'spec')
-rw-r--r-- | spec/workers/check_gcp_project_billing_worker_spec.rb | 46 |
1 files changed, 32 insertions, 14 deletions
diff --git a/spec/workers/check_gcp_project_billing_worker_spec.rb b/spec/workers/check_gcp_project_billing_worker_spec.rb index cdb114749ee..b1687cc95c6 100644 --- a/spec/workers/check_gcp_project_billing_worker_spec.rb +++ b/spec/workers/check_gcp_project_billing_worker_spec.rb @@ -3,33 +3,51 @@ require 'spec_helper' describe CheckGcpProjectBillingWorker do describe '.perform' do let(:token) { 'bogustoken' } - subject { described_class.new.perform(token) } + subject { described_class.new.perform('token_key') } - context 'when there is no lease' do + context 'when there is a token in redis' do before do - allow_any_instance_of(described_class).to receive(:try_obtain_lease_for).and_return('randomuuid') + allow_any_instance_of(described_class).to receive(:get_token).and_return(token) end - it 'calls the service' do - expect(CheckGcpProjectBillingService).to receive_message_chain(:new, :execute).and_return([double]) + context 'when there is no lease' do + before do + allow_any_instance_of(described_class).to receive(:try_obtain_lease_for).and_return('randomuuid') + end - subject + it 'calls the service' do + expect(CheckGcpProjectBillingService).to receive_message_chain(:new, :execute).and_return([double]) + + subject + end + + it 'stores billing status in redis' do + redis_double = double + + expect(CheckGcpProjectBillingService).to receive_message_chain(:new, :execute).and_return([double]) + expect(Gitlab::Redis::SharedState).to receive(:with).and_yield(redis_double) + expect(redis_double).to receive(:set).with(described_class.redis_shared_state_key_for(token), anything) + + subject + end end - it 'stores billing status in redis' do - redis_double = double + context 'when there is a lease' do + before do + allow_any_instance_of(described_class).to receive(:try_obtain_lease_for).and_return(false) + end - expect(CheckGcpProjectBillingService).to receive_message_chain(:new, :execute).and_return([double]) - expect(Gitlab::Redis::SharedState).to receive(:with).and_yield(redis_double) - expect(redis_double).to receive(:set).with(described_class.redis_shared_state_key_for(token), anything) + it 'does not call the service' do + expect(CheckGcpProjectBillingService).not_to receive(:new) - subject + subject + end end end - context 'when there is a lease' do + context 'when there is no token in redis' do before do - allow_any_instance_of(described_class).to receive(:try_obtain_lease_for).and_return(false) + allow_any_instance_of(described_class).to receive(:get_token).and_return(nil) end it 'does not call the service' do |