https://www.aeolusproject.org/redmine/issues/3742
https://www.aeolusproject.org/redmine/issues/3743
https://www.aeolusproject.org/redmine/issues/3448
Needed to mock out deltacloud calls.
For instance.feature:64 needed to stub ProviderAccount.connect
to return nil because it is attempting to test an inaccessible
provider.
Moved mock_deltacloud out to general_steps.rb so that it can be used
by both instance.feature and deployment.feature.
---
src/features/step_definitions/deployment_steps.rb | 13 ----------
src/features/step_definitions/general_steps.rb | 27 +++++++++++++++++++++
src/features/step_definitions/instance_steps.rb | 2 +
3 files changed, 29 insertions(+), 13 deletions(-)
diff --git a/src/features/step_definitions/deployment_steps.rb
b/src/features/step_definitions/deployment_steps.rb
index 862c3e4..4822607 100644
--- a/src/features/step_definitions/deployment_steps.rb
+++ b/src/features/step_definitions/deployment_steps.rb
@@ -1,16 +1,3 @@
-def mock_deltacloud
- @deltacloud_connection = mock("Deltacloud::API")
- @deltacloud_state = mock("Deltacloud::API::InstanceState")
- @transitions = Array.new
- deltacloud_transition = mock("Deltacloud::API::Transition")
- deltacloud_transition.stub(:to).and_return('running')
- deltacloud_transition.stub(:action).and_return('stop')
- @transitions << deltacloud_transition
- @deltacloud_state.stub(:transitions).and_return(@transitions)
- @deltacloud_connection.stub(:instance_state).and_return(@deltacloud_state)
- ProviderAccount.any_instance.stub(:connect).and_return(@deltacloud_connection)
-end
-
Given /^there is a deployment named "([^"]*)" belonging to
"([^"]*)" owned by "([^"]*)"$/ do |deployment_name,
deployable_name, owner_name|
user = FactoryGirl.create(:user, :login => owner_name, :last_name => owner_name)
@deployment = Factory.create(:deployment, {:name => deployment_name, :pool =>
Pool.first, :owner => user})
diff --git a/src/features/step_definitions/general_steps.rb
b/src/features/step_definitions/general_steps.rb
index 79047fe..8f83f72 100644
--- a/src/features/step_definitions/general_steps.rb
+++ b/src/features/step_definitions/general_steps.rb
@@ -44,3 +44,30 @@ module LocalizationHelpers
end
end
World(LocalizationHelpers)
+
+def mock_deltacloud
+ @deltacloud_connection = mock("Deltacloud::API")
+
+ @running_state = mock("Deltacloud::API::InstanceState")
+ @running_state.stub(:transitions).and_return {
+ [create_deltacloud_transition('running', 'reboot'),
+ create_deltacloud_transition('stopped', 'stop')]}
+
@deltacloud_connection.stub(:instance_state).with("running").and_return(@running_state)
+
+ @stopped_state = mock("Deltacloud::API::InstanceState")
+ @stopped_state.stub(:transitions).and_return {
+ [create_deltacloud_transition('running', 'start'),
+ create_deltacloud_transition('finish', 'destroy')]}
+
@deltacloud_connection.stub(:instance_state).with("stopped").and_return(@stopped_state)
+
+ ProviderAccount.any_instance.stub(:connect).and_return(@deltacloud_connection)
+end
+
+private
+
+def create_deltacloud_transition(to_state, action_to_get_to_state)
+ deltacloud_transition = mock("Deltacloud::API::Transition")
+ deltacloud_transition.stub(:to).and_return(to_state)
+ deltacloud_transition.stub(:action).and_return(action_to_get_to_state)
+ deltacloud_transition
+end
diff --git a/src/features/step_definitions/instance_steps.rb
b/src/features/step_definitions/instance_steps.rb
index 5f4d3bb..13989b8 100644
--- a/src/features/step_definitions/instance_steps.rb
+++ b/src/features/step_definitions/instance_steps.rb
@@ -45,6 +45,7 @@ Given /^"([^"]*)" instance's provider is not
accessible$/ do |arg1|
# cleanly
provider = instance.provider_account.provider
provider.update_attribute(:url, 'http://localhost:3002/invalid_api')
+ ProviderAccount.any_instance.stub(:connect).and_return(nil)
end
When /^I am viewing the pending instance detail$/ do
@@ -84,6 +85,7 @@ end
Given /^there is a "([^"]*)" running instance$/ do |name|
FactoryGirl.create :instance, :name => name, :state => Instance::STATE_RUNNING
+ mock_deltacloud
end
Given /^there is a "([^"]*)" stopped instance$/ do |name|
--
1.7.7.6