8477a63f89ac71704f060b63563ec9eaeae59af3
[packages/precise/mcollective.git] / spec / unit / plugins / mcollective / data / agent_data_spec.rb
1 #!/usr/bin/env rspec
2
3 require 'spec_helper'
4
5 require File.dirname(__FILE__) + "/../../../../../plugins/mcollective/data/agent_data.rb"
6
7 module MCollective
8   module Data
9     describe Agent_data do
10       describe "#query_data" do
11         before do
12           @ddl = mock
13           @ddl.stubs(:meta).returns({:timeout => 1})
14           DDL.stubs(:new).returns(@ddl)
15           @plugin = Agent_data.new
16         end
17
18         it "should fail for unknown agents" do
19           expect { @plugin.query_data("rspec") }.to raise_error("No agent called rspec found")
20         end
21
22         it "should retrieve the correct agent and data" do
23           agent = mock
24           agent.stubs(:meta).returns({:license => "license",
25                                         :timeout => "timeout",
26                                         :description => "description",
27                                         :url => "url",
28                                         :version => "version",
29                                         :author => "author"})
30
31           PluginManager.stubs(:[]).with("rspec_agent").returns(agent)
32           PluginManager.expects(:include?).with("rspec_agent").returns(true)
33
34           @plugin.query_data("rspec")
35
36           [:license, :timeout, :description, :url, :version, :author].each do |item|
37             @plugin.result[item].should == item.to_s
38           end
39         end
40       end
41     end
42   end
43 end