2017-12-16 01:39:55 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe CheckGcpProjectBillingWorker do
|
|
|
|
describe '.perform' do
|
|
|
|
let(:token) { 'bogustoken' }
|
2018-01-06 18:02:18 +00:00
|
|
|
subject { described_class.new.perform('token_key') }
|
2017-12-16 01:39:55 +00:00
|
|
|
|
2018-01-06 18:02:18 +00:00
|
|
|
context 'when there is a token in redis' do
|
2017-12-16 03:21:13 +00:00
|
|
|
before do
|
2018-01-06 18:02:18 +00:00
|
|
|
allow_any_instance_of(described_class).to receive(:get_token).and_return(token)
|
2017-12-16 03:21:13 +00:00
|
|
|
end
|
2017-12-16 01:39:55 +00:00
|
|
|
|
2018-01-06 18:02:18 +00:00
|
|
|
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
|
2017-12-16 03:21:13 +00:00
|
|
|
|
2018-01-06 18:02:18 +00:00
|
|
|
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
|
2017-12-16 03:21:13 +00:00
|
|
|
end
|
|
|
|
|
2018-01-06 18:02:18 +00:00
|
|
|
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
|
2017-12-16 03:21:13 +00:00
|
|
|
|
2018-01-06 18:02:18 +00:00
|
|
|
it 'does not call the service' do
|
|
|
|
expect(CheckGcpProjectBillingService).not_to receive(:new)
|
2017-12-16 03:21:13 +00:00
|
|
|
|
2018-01-06 18:02:18 +00:00
|
|
|
subject
|
|
|
|
end
|
2017-12-16 03:21:13 +00:00
|
|
|
end
|
2017-12-16 01:39:55 +00:00
|
|
|
end
|
|
|
|
|
2018-01-06 18:02:18 +00:00
|
|
|
context 'when there is no token in redis' do
|
2017-12-16 03:21:13 +00:00
|
|
|
before do
|
2018-01-06 18:02:18 +00:00
|
|
|
allow_any_instance_of(described_class).to receive(:get_token).and_return(nil)
|
2017-12-16 03:21:13 +00:00
|
|
|
end
|
2017-12-16 03:00:54 +00:00
|
|
|
|
2017-12-16 03:21:13 +00:00
|
|
|
it 'does not call the service' do
|
|
|
|
expect(CheckGcpProjectBillingService).not_to receive(:new)
|
2017-12-16 01:39:55 +00:00
|
|
|
|
2017-12-16 03:21:13 +00:00
|
|
|
subject
|
|
|
|
end
|
2017-12-16 01:39:55 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|