Added mcollective 2.3.1 package
[packages/trusty/mcollective.git] / spec / unit / ddl / dataddl_spec.rb
1 #!/usr/bin/env rspec
2
3 require 'spec_helper'
4
5 module MCollective
6   module DDL
7     describe DataDDL do
8       before :each do
9         Cache.delete!(:ddl) rescue nil
10         @ddl = DDL.new("rspec", :data, false)
11         @ddl.metadata(:name => "name", :description => "description", :author => "author", :license => "license", :version => "version", :url => "url", :timeout => "timeout")
12       end
13
14       describe "#input" do
15         it "should only allow 'query' as input for data plugins" do
16           ddl = DDL.new("rspec", :data, false)
17           ddl.dataquery(:description => "rspec")
18           ddl.instance_variable_set("@current_entity", :query)
19           ddl.instance_variable_set("@plugintype", :data)
20
21           expect { ddl.input(:rspec, {}) }.to raise_error("The only valid input name for a data query is 'query'")
22         end
23       end
24
25       describe "#dataquery_interface" do
26         it "should return the correct data" do
27           input = {:prompt => "Matcher", :description => "Augeas Matcher", :type => :string, :validation => /.+/, :maxlength => 0}
28           output = {:description=>"rspec", :display_as=>"rspec", :default => nil}
29
30           @ddl.instance_variable_set("@plugintype", :data)
31           @ddl.dataquery(:description => "rspec") do
32             @ddl.output :rspec, output
33             @ddl.input :query, input
34           end
35
36           @ddl.dataquery_interface.should == {:description => "rspec",
37                                               :input => {:query => input.merge(:optional => nil, :default => nil)},
38                                               :output => {:rspec => output}}
39         end
40       end
41
42       describe "#dataquery" do
43         it "should ensure a description is set" do
44           expect { @ddl.dataquery({}) }.to raise_error("Data queries need a :description")
45         end
46
47         it "should ensure only one definition" do
48           @ddl.dataquery(:description => "rspec")
49
50           expect { @ddl.dataquery(:description => "rspec") }.to raise_error("Data queries can only have one definition")
51         end
52
53         it "should create the default structure" do
54           @ddl.dataquery(:description => "rspec")
55           @ddl.instance_variable_set("@plugintype", :data)
56           @ddl.dataquery_interface.should == {:description => "rspec", :input => {}, :output => {}}
57         end
58
59         it "should call the block if given" do
60           @ddl.dataquery(:description => "rspec") { @ddl.instance_variable_get("@current_entity").should == :data }
61         end
62       end
63     end
64   end
65 end