Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add callbacks to deployment events, refresh #176

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add test that it returns a list of all the callbacks
MarkBorcherding authored and Jonathan Owens committed Mar 22, 2017
commit 6938de75db3bc7d0e292381e849ba16246e4137c
10 changes: 6 additions & 4 deletions lib/centurion/deploy_dsl.rb
Original file line number Diff line number Diff line change
@@ -161,11 +161,13 @@ def after_health_check_ok(callback = nil, &block)
private

def collect_callback(name, callback = nil, &block)
return unless callback || block
abort('Callback expects a lambda, proc, or block') if callback && !callback.respond_to?(:call)
callbacks = fetch(name, [])
callbacks << (callback || block)
set(name, callbacks)
if callback || block
abort('Callback expects a lambda, proc, or block') if callback && !callback.respond_to?(:call)
callbacks << (callback || block)
set(name, callbacks)
end
callbacks
end

def service_under_construction
80 changes: 38 additions & 42 deletions spec/deploy_dsl_spec.rb
Original file line number Diff line number Diff line change
@@ -216,61 +216,57 @@ class DeployDSLTest
DeployDSLTest.before_stopping_image
expect(DeployDSLTest.fetch(:before_stopping_image_callbacks, [])).to eq([])
end
end

it 'collects before_stopping_image callbacks as procs' do
callback = ->(_) {}
DeployDSLTest.before_stopping_image callback
expect(DeployDSLTest.fetch(:before_stopping_image_callbacks)).to eq([callback])
end
describe 'callbacks' do
shared_examples_for 'a callback for' do |callback_name|
let(:callbacks) { DeployDSLTest.fetch("#{callback_name}_callbacks".to_sym, []) }

it 'collects before_stopping_image callbacks as blocks' do
DeployDSLTest.before_stopping_image do |_|
'from the block'
it 'does not add nil callbacks' do
DeployDSLTest.send callback_name
expect(callbacks).to eq([])
end
callback = DeployDSLTest.fetch(:before_stopping_image_callbacks)[0]
expect(callback.call).to eq('from the block')
end
end

describe '#after_image_started' do
it 'does not add nil callbacks' do
DeployDSLTest.after_image_started
expect(DeployDSLTest.fetch(:after_image_started_callbacks, [])).to eq([])
end
it 'collects callbacks as procs' do
callback = ->(_) {}
DeployDSLTest.send callback_name, callback
expect(callbacks).to eq([callback])
end

it 'collects after_image_started callbacks as procs' do
callback = ->(server) { }
DeployDSLTest.after_image_started callback
expect(DeployDSLTest.fetch(:after_image_started_callbacks)).to eq([callback])
end
it 'collects callbacks as blocks' do
DeployDSLTest.send callback_name do |_|
'from the block'
end
callback = callbacks[0]
expect(callback.call).to eq('from the block')
end

it 'returns a list of all callbacks when adding one' do
callback1 = ->(_) {}
callback2 = ->(_) {}
DeployDSLTest.send callback_name, callback1
returned_callbacks = DeployDSLTest.send callback_name, callback2
expect(returned_callbacks).to eq([callback1, callback2])
end

it 'collects after_image_started callbacks as blocks' do
DeployDSLTest.after_image_started do |_|
'from the block'
it 'returns a list of all callbacks when adding none' do
callback1 = ->(_) {}
DeployDSLTest.send callback_name, callback1
returned_callbacks = DeployDSLTest.send callback_name
expect(returned_callbacks).to eq([callback1])
end
callback = DeployDSLTest.fetch(:after_image_started_callbacks)[0]
expect(callback.call).to eq('from the block')
end
end

describe '#after_health_check_ok' do
it 'does not add nil callbacks' do
DeployDSLTest.after_health_check_ok
expect(DeployDSLTest.fetch(:after_health_check_ok_callbacks, [])).to eq([])
describe '#before_stopping_image' do
it_behaves_like 'a callback for', :before_stopping_image
end

it 'collects after_health_check_ok callbacks as procs' do
callback = ->(server) { }
DeployDSLTest.after_health_check_ok callback
expect(DeployDSLTest.fetch(:after_health_check_ok_callbacks)).to eq([callback])
describe '#after_image_started' do
it_behaves_like 'a callback for', :after_image_started
end

it 'collects after_health_check_ok callbacks as blocks' do
DeployDSLTest.after_health_check_ok do |_|
'from the block'
end
callback = DeployDSLTest.fetch(:after_health_check_ok_callbacks)[0]
expect(callback.call).to eq('from the block')
describe '#after_health_check_ok' do
it_behaves_like 'a callback for', :after_health_check_ok
end
end
end