X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=spec%2Funit%2Fddl%2Fdataddl_spec.rb;fp=spec%2Funit%2Fddl%2Fdataddl_spec.rb;h=915cabca4a0cf310877fcb96aea22b8bda7c5f14;hb=b87d2f4e68281062df1913440ca5753ae63314a9;hp=0000000000000000000000000000000000000000;hpb=ab0ea530b8ac956091f17b104ab2311336cfc250;p=packages%2Fprecise%2Fmcollective.git diff --git a/spec/unit/ddl/dataddl_spec.rb b/spec/unit/ddl/dataddl_spec.rb new file mode 100644 index 0000000..915cabc --- /dev/null +++ b/spec/unit/ddl/dataddl_spec.rb @@ -0,0 +1,65 @@ +#!/usr/bin/env rspec + +require 'spec_helper' + +module MCollective + module DDL + describe DataDDL do + before :each do + Cache.delete!(:ddl) rescue nil + @ddl = DDL.new("rspec", :data, false) + @ddl.metadata(:name => "name", :description => "description", :author => "author", :license => "license", :version => "version", :url => "url", :timeout => "timeout") + end + + describe "#input" do + it "should only allow 'query' as input for data plugins" do + ddl = DDL.new("rspec", :data, false) + ddl.dataquery(:description => "rspec") + ddl.instance_variable_set("@current_entity", :query) + ddl.instance_variable_set("@plugintype", :data) + + expect { ddl.input(:rspec, {}) }.to raise_error("The only valid input name for a data query is 'query'") + end + end + + describe "#dataquery_interface" do + it "should return the correct data" do + input = {:prompt => "Matcher", :description => "Augeas Matcher", :type => :string, :validation => /.+/, :maxlength => 0} + output = {:description=>"rspec", :display_as=>"rspec", :default => nil} + + @ddl.instance_variable_set("@plugintype", :data) + @ddl.dataquery(:description => "rspec") do + @ddl.output :rspec, output + @ddl.input :query, input + end + + @ddl.dataquery_interface.should == {:description => "rspec", + :input => {:query => input.merge(:optional => nil, :default => nil)}, + :output => {:rspec => output}} + end + end + + describe "#dataquery" do + it "should ensure a description is set" do + expect { @ddl.dataquery({}) }.to raise_error("Data queries need a :description") + end + + it "should ensure only one definition" do + @ddl.dataquery(:description => "rspec") + + expect { @ddl.dataquery(:description => "rspec") }.to raise_error("Data queries can only have one definition") + end + + it "should create the default structure" do + @ddl.dataquery(:description => "rspec") + @ddl.instance_variable_set("@plugintype", :data) + @ddl.dataquery_interface.should == {:description => "rspec", :input => {}, :output => {}} + end + + it "should call the block if given" do + @ddl.dataquery(:description => "rspec") { @ddl.instance_variable_get("@current_entity").should == :data } + end + end + end + end +end