9 @security.stubs(:initiated_by=)
11 @connector.stubs(:connect)
12 @connector.stubs(:subscribe)
13 @connector.stubs(:unsubscribe)
15 @ddl.stubs(:meta).returns({:timeout => 1})
18 Discovery.expects(:new).returns(@discoverer)
20 Config.instance.instance_variable_set("@configured", true)
21 PluginManager.expects("[]").with("connector_plugin").returns(@connector)
22 PluginManager.expects("[]").with("security_plugin").returns(@security)
24 @client = Client.new("/nonexisting")
25 @client.options = Util.default_options
28 describe "#sendreq" do
29 it "should send the supplied message" do
30 message = Message.new("rspec", nil, {:agent => "rspec", :type => :request, :collective => "mcollective", :filter => Util.empty_filter, :options => Util.default_options})
32 message.expects(:encode!)
33 @client.expects(:subscribe).with("rspec", :reply)
34 message.expects(:publish)
35 message.expects(:requestid).twice
36 @client.sendreq(message, "rspec")
39 it "should not subscribe to a reply queue for a message with a reply-to" do
40 message = Message.new("rspec", nil, {:agent => "rspec", :type => :request, :collective => "mcollective", :filter => Util.empty_filter, :options => Util.default_options})
41 message.reply_to = "rspec"
43 message.expects(:encode!)
44 @client.expects(:subscribe).never
45 message.expects(:publish)
46 message.expects(:requestid).twice
47 @client.sendreq(message, "rspec")
51 it "should record the requestid" do
52 message = Message.new("rspec", nil, {:agent => "rspec", :type => :request, :collective => "mcollective", :filter => Util.empty_filter, :options => Util.default_options})
53 message.discovered_hosts = ["rspec"]
56 reply.stubs("payload").returns("rspec payload")
58 @client.expects(:sendreq).returns("823a3419a0975c3facbde121f72ab61f")
59 @client.expects(:receive).returns(reply)
61 @discoverer.expects(:discovery_timeout).with(message.options[:timeout], message.options[:filter]).returns(0)
63 Time.stubs(:now).returns(Time.at(1340621250), Time.at(1340621251))
65 @client.req(message){}.should == {:blocktime => 1.0, :discoverytime => 0, :noresponsefrom => [],
66 :requestid => "823a3419a0975c3facbde121f72ab61f", :responses => 1,
67 :starttime => 1340621250.0, :totaltime => 1.0}
71 describe "#discover" do
72 it "should delegate to the discovery plugins" do
73 @discoverer.expects(:discover).with({}, 1, 0).returns([])
74 @client.discover({}, 1).should == []