[PATCH conductor 16/17] Add RSpec test for provider selection and remove obsolete ones

ifarkas at redhat.com ifarkas at redhat.com
Mon Jul 23 13:58:15 UTC 2012


From: Imre Farkas <ifarkas at redhat.com>

---
 src/spec/lib/provider_selection.rb |   64 ++++++++++++++++++++++++++++++++++++
 src/spec/models/deployment_spec.rb |   27 ---------------
 2 files changed, 64 insertions(+), 27 deletions(-)
 create mode 100644 src/spec/lib/provider_selection.rb

diff --git a/src/spec/lib/provider_selection.rb b/src/spec/lib/provider_selection.rb
new file mode 100644
index 0000000..cf1c252
--- /dev/null
+++ b/src/spec/lib/provider_selection.rb
@@ -0,0 +1,64 @@
+#
+#   Copyright 2012 Red Hat, Inc.
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+#
+
+require 'spec_helper'
+
+describe ProviderSelection do
+
+  before(:each) do
+    @account1 = FactoryGirl.create(:mock_provider_account, :label => "test_account1")
+    @account2 = FactoryGirl.create(:mock_provider_account, :label => "test_account2")
+    @account3 = FactoryGirl.create(:mock_provider_account, :label => "test_account3")
+
+    possible1 = FactoryGirl.build(:instance_match, :provider_account => @account1)
+    possible2 = FactoryGirl.build(:instance_match, :provider_account => @account2)
+    possible3 = FactoryGirl.build(:instance_match, :provider_account => @account2)
+    possible4 = FactoryGirl.build(:instance_match, :provider_account => @account3)
+    possible5 = FactoryGirl.build(:instance_match, :provider_account => @account2)
+
+    instance1 = Factory.build(:instance)
+    instance1.stub!(:matches).and_return([[possible1, possible2], []])
+    instance2 = Factory.build(:instance)
+    instance2.stub!(:matches).and_return([[possible3, possible4], []])
+    instance3 = Factory.build(:instance)
+    instance3.stub!(:matches).and_return([[possible5], []])
+
+    instances = [instance1, instance2, instance3]
+    @provider_selection = ProviderSelection::Base.new(instances)
+  end
+
+  it "should give back valid match" do
+    match = @provider_selection.next_match
+    match.provider_account.should eql(@account2)
+  end
+
+  it "should find common provider account" do
+    common_provider_accounts = @provider_selection.send(:find_common_provider_accounts)
+    common_provider_accounts.should eql([@account2])
+  end
+
+  it "should calculate initial rank" do
+    rank = @provider_selection.calculate
+    rank.priority_groups.length.should eql(1)
+
+    priority_group = rank.priority_groups.first
+    priority_group.matches.length.should eql(1)
+
+    match = priority_group.matches.first
+    match.provider_account.should eql(@account2)
+  end
+
+end
\ No newline at end of file
diff --git a/src/spec/models/deployment_spec.rb b/src/spec/models/deployment_spec.rb
index 9b2a37e..23addf1 100644
--- a/src/spec/models/deployment_spec.rb
+++ b/src/spec/models/deployment_spec.rb
@@ -266,31 +266,6 @@ describe Deployment do
       @deployment.instances.count.should == 2
     end
 
-    it "should match provider accounts according to priority when launching deployment" do
-      @deployment.save!
-      @deployment.instances.should be_empty
-
-      Instance.any_instance.stub(:provider_images_for_match).and_return([@provider_image])
-      Taskomatic.stub!(:create_dcloud_instance).and_return(true)
-      Taskomatic.stub!(:handle_dcloud_error).and_return(true)
-      Taskomatic.stub!(:handle_instance_state).and_return(true)
-      @deployment.create_and_launch(@session_id, @user_for_launch)
-      @deployment.errors.should be_empty
-      @deployment.reload
-      @deployment.instances.count.should == 2
-      @deployment.instances[0].provider_account.should == @provider_account1
-      @deployment.instances[1].provider_account.should == @provider_account1
-      @provider_account1.priority = 30
-      @provider_account1.save!
-      deployment2 = Factory.create(:deployment, :pool_id => @pool.id)
-      deployment2.create_and_launch(@session_id, @user_for_launch)
-      deployment2.errors.should be_empty
-      deployment2.reload
-      deployment2.instances.count.should == 2
-      deployment2.instances[0].provider_account.should == @provider_account2
-      deployment2.instances[1].provider_account.should == @provider_account2
-    end
-
     it "should not fail to launch if a provider account has a nil priority" do
       @deployment.save!
       @deployment.instances.should be_empty
@@ -306,8 +281,6 @@ describe Deployment do
       @deployment.errors.should be_empty
       @deployment.reload
       @deployment.instances.count.should == 2
-      @deployment.instances[0].provider_account.should == @provider_account2
-      @deployment.instances[1].provider_account.should == @provider_account2
     end
 
     it "should not create deployment with instances if match not found" do
-- 
1.7.10.4




More information about the aeolus-devel mailing list