X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=spec%2Funit%2Fclient_spec.rb;fp=spec%2Funit%2Fclient_spec.rb;h=70c0a8fcd3f282cbafb6a60324a00b69df253fe4;hb=b87d2f4e68281062df1913440ca5753ae63314a9;hp=0000000000000000000000000000000000000000;hpb=ab0ea530b8ac956091f17b104ab2311336cfc250;p=packages%2Fprecise%2Fmcollective.git diff --git a/spec/unit/client_spec.rb b/spec/unit/client_spec.rb new file mode 100644 index 0000000..70c0a8f --- /dev/null +++ b/spec/unit/client_spec.rb @@ -0,0 +1,78 @@ +#!/usr/bin/env rspec + +require 'spec_helper' + +module MCollective + describe Client do + before do + @security = mock + @security.stubs(:initiated_by=) + @connector = mock + @connector.stubs(:connect) + @connector.stubs(:subscribe) + @connector.stubs(:unsubscribe) + @ddl = mock + @ddl.stubs(:meta).returns({:timeout => 1}) + @discoverer = mock + + Discovery.expects(:new).returns(@discoverer) + + Config.instance.instance_variable_set("@configured", true) + PluginManager.expects("[]").with("connector_plugin").returns(@connector) + PluginManager.expects("[]").with("security_plugin").returns(@security) + + @client = Client.new("/nonexisting") + @client.options = Util.default_options + end + + describe "#sendreq" do + it "should send the supplied message" do + message = Message.new("rspec", nil, {:agent => "rspec", :type => :request, :collective => "mcollective", :filter => Util.empty_filter, :options => Util.default_options}) + + message.expects(:encode!) + @client.expects(:subscribe).with("rspec", :reply) + message.expects(:publish) + message.expects(:requestid).twice + @client.sendreq(message, "rspec") + end + + it "should not subscribe to a reply queue for a message with a reply-to" do + message = Message.new("rspec", nil, {:agent => "rspec", :type => :request, :collective => "mcollective", :filter => Util.empty_filter, :options => Util.default_options}) + message.reply_to = "rspec" + + message.expects(:encode!) + @client.expects(:subscribe).never + message.expects(:publish) + message.expects(:requestid).twice + @client.sendreq(message, "rspec") + end + end + describe "#req" do + it "should record the requestid" do + message = Message.new("rspec", nil, {:agent => "rspec", :type => :request, :collective => "mcollective", :filter => Util.empty_filter, :options => Util.default_options}) + message.discovered_hosts = ["rspec"] + + reply = mock + reply.stubs("payload").returns("rspec payload") + + @client.expects(:sendreq).returns("823a3419a0975c3facbde121f72ab61f") + @client.expects(:receive).returns(reply) + + @discoverer.expects(:discovery_timeout).with(message.options[:timeout], message.options[:filter]).returns(0) + + Time.stubs(:now).returns(Time.at(1340621250), Time.at(1340621251)) + + @client.req(message){}.should == {:blocktime => 1.0, :discoverytime => 0, :noresponsefrom => [], + :requestid => "823a3419a0975c3facbde121f72ab61f", :responses => 1, + :starttime => 1340621250.0, :totaltime => 1.0} + end + end + + describe "#discover" do + it "should delegate to the discovery plugins" do + @discoverer.expects(:discover).with({}, 1, 0).returns([]) + @client.discover({}, 1).should == [] + end + end + end +end