[astute] Unit tests for deployment_engine base class

This commit is contained in:
Mike Scherbakov 2012-12-27 20:45:23 +04:00 committed by default
parent 76e78e0993
commit 9bbf3d1ccf
2 changed files with 30 additions and 0 deletions

View File

@ -14,6 +14,7 @@ module Astute
end end
def deploy(reporter, task_id, nodes, attrs) def deploy(reporter, task_id, nodes, attrs)
raise "Nodes to deploy are not provided!" if nodes.empty?
context = Context.new(task_id, reporter) context = Context.new(task_id, reporter)
deploy_engine_instance = @deploy_engine.new(context) deploy_engine_instance = @deploy_engine.new(context)
deploy_engine_instance.deploy(nodes, attrs) deploy_engine_instance.deploy(nodes, attrs)

View File

@ -0,0 +1,29 @@
#!/usr/bin/env rspec
require File.join(File.dirname(__FILE__), "..", "spec_helper")
describe "DeploymentEngine" do
context "When deploy is called, it" do
before(:each) do
@ctx = mock
@deploy_engine = Astute::DeploymentEngine.new(@ctx)
end
it "should call valid method depends on attrs" do
nodes = [{'uid' => 1}]
attrs = {'deployment_mode' => 'ha_compute'}
attrs_modified = attrs.merge({'some' => 'somea'})
@deploy_engine.expects(:attrs_ha_compute).with(nodes, attrs).returns(attrs_modified)
@deploy_engine.expects(:deploy_ha_compute).with(nodes, attrs_modified)
# All implementations of deploy_piece go to subclasses
@deploy_engine.respond_to?(:deploy_piece).should be_false
@deploy_engine.deploy(nodes, attrs)
end
it "should raise an exception if deployment mode is unsupported" do
nodes = [{'uid' => 1}]
attrs = {'deployment_mode' => 'unknown'}
expect {@deploy_engine.deploy(nodes, attrs)}.to raise_exception(/Method attrs_unknown is not implemented/)
end
end
end