X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=spec%2Funit%2Fregistration%2Fbase_spec.rb;fp=spec%2Funit%2Fregistration%2Fbase_spec.rb;h=07cb7011f73f3625981326d290a5ea45cc2513ff;hb=b87d2f4e68281062df1913440ca5753ae63314a9;hp=0000000000000000000000000000000000000000;hpb=ab0ea530b8ac956091f17b104ab2311336cfc250;p=packages%2Fprecise%2Fmcollective.git diff --git a/spec/unit/registration/base_spec.rb b/spec/unit/registration/base_spec.rb new file mode 100755 index 0000000..07cb701 --- /dev/null +++ b/spec/unit/registration/base_spec.rb @@ -0,0 +1,77 @@ +#!/usr/bin/env rspec + +require 'spec_helper' + +module MCollective + module Registration + describe Base do + before do + @config = mock + @config.stubs(:identity).returns("rspec") + @config.stubs(:main_collective).returns("main_collective") + Config.stubs(:instance).returns(@config) + + @reg = Base.new + end + + describe "#config" do + it "should provide access the main configuration class" do + @reg.config.should == @config + end + + end + + describe "#identity" do + it "should return the correct identity" do + @reg.config.identity.should == "rspec" + end + end + + describe "#msg_filter" do + it "should target the registration agent" do + @reg.msg_filter["agent"].should == ["registration"] + end + end + + describe "#target_collective" do + it "should return the configured registration_collective" do + @config.expects(:registration_collective).returns("registration").once + @config.expects(:collectives).returns(["main_collective", "registration"]).once + @reg.target_collective.should == "registration" + end + + it "should use the main collective if registration collective is not valid" do + @config.expects(:registration_collective).returns("registration").once + @config.expects(:collectives).returns(["main_collective"]).once + + Log.expects(:warn).with("Sending registration to main_collective: registration is not a valid collective").once + + @reg.target_collective.should == "main_collective" + end + end + + describe "#publish" do + it "should skip registration for empty messages" do + Log.expects(:debug).with("Skipping registration due to nil body") + @reg.publish(nil) + end + + it "should publish via the message object" do + message = mock + message.expects(:encode!) + message.expects(:publish) + message.expects(:requestid).returns("123") + message.expects(:collective).returns("mcollective") + + Message.expects(:new).returns(message) + + Log.expects(:debug).with("Sending registration 123 to collective mcollective") + + @reg.expects(:target_collective).returns("mcollective") + + @reg.publish("message") + end + end + end + end +end