summaryrefslogtreecommitdiffstats
path: root/spec/unit/parser
diff options
context:
space:
mode:
authorLuke Kanies <luke@reductivelabs.com>2009-12-21 16:23:44 -0800
committerLuke Kanies <luke@reductivelabs.com>2009-12-21 16:23:44 -0800
commit740fd6b301af89ab3aad89bca183ad1fcdc24ac4 (patch)
treef34617a229509c373d28d67abb453e7ae2136c39 /spec/unit/parser
parent8971d8beae2c409f9052f27c3f80ad3bdfff4de2 (diff)
parent4a06379f8770c164e42bcc410d874076c6e95f24 (diff)
downloadpuppet-740fd6b301af89ab3aad89bca183ad1fcdc24ac4.tar.gz
puppet-740fd6b301af89ab3aad89bca183ad1fcdc24ac4.tar.xz
puppet-740fd6b301af89ab3aad89bca183ad1fcdc24ac4.zip
Merge branch '0.25.x'
Conflicts: lib/puppet/agent.rb lib/puppet/application/puppetd.rb lib/puppet/parser/ast/leaf.rb lib/puppet/util/rdoc/parser.rb
Diffstat (limited to 'spec/unit/parser')
-rwxr-xr-xspec/unit/parser/collector.rb29
-rwxr-xr-xspec/unit/parser/functions/require.rb6
-rwxr-xr-xspec/unit/parser/resource.rb15
-rwxr-xr-xspec/unit/parser/resource/reference.rb7
-rwxr-xr-xspec/unit/parser/scope.rb2
5 files changed, 47 insertions, 12 deletions
diff --git a/spec/unit/parser/collector.rb b/spec/unit/parser/collector.rb
index 926033c68..7f88bf754 100755
--- a/spec/unit/parser/collector.rb
+++ b/spec/unit/parser/collector.rb
@@ -498,35 +498,46 @@ describe Puppet::Parser::Collector, "when building its ActiveRecord query for co
Puppet::Rails::Host.expects(:find_by_name).with(@scope.host).returns(@host)
Puppet::Rails::Resource.stubs(:find).with { |*arguments|
- options = arguments[3]
+ options = arguments[1]
options[:conditions][0] =~ /^host_id != \?/ and options[:conditions][1] == 5
}.returns([@resource])
@collector.evaluate.should == [@resource]
end
- it "should return parameter names, parameter values when querying ActiveRecord" do
+ it "should join with parameter names, parameter values when querying ActiveRecord" do
+ @collector.equery = "param_names.name = title"
Puppet::Rails::Resource.stubs(:find).with { |*arguments|
- options = arguments[3]
- options[:include] == {:param_values => :param_name}
+ options = arguments[1]
+ options[:joins] == {:param_values => :param_name}
}.returns([@resource])
@collector.evaluate.should == [@resource]
end
- it "should return tags when querying ActiveRecord with a tag exported query" do
+ it "should join with tag tables when querying ActiveRecord with a tag exported query" do
@collector.equery = "puppet_tags.name = test"
Puppet::Rails::Resource.stubs(:find).with { |*arguments|
- options = arguments[3]
- options[:include] == {:param_values => :param_name, :puppet_tags => :resource_tags}
+ options = arguments[1]
+ options[:joins] == {:resource_tags => :puppet_tag}
}.returns([@resource])
@collector.evaluate.should == [@resource]
end
+ it "should not join parameters when querying ActiveRecord with a tag exported query" do
+ @collector.equery = "puppet_tags.name = test"
+ Puppet::Rails::Resource.stubs(:find).with { |*arguments|
+ options = arguments[1]
+ options[:joins] == {:param_values => :param_name}
+ }.returns([@resource])
+
+ @collector.evaluate.should be_false
+ end
+
it "should only search for exported resources with the matching type" do
Puppet::Rails::Resource.stubs(:find).with { |*arguments|
- options = arguments[3]
+ options = arguments[1]
options[:conditions][0].include?("(exported=? AND restype=?)") and options[:conditions][1] == true and options[:conditions][2] == "Mytype"
}.returns([@resource])
@@ -536,7 +547,7 @@ describe Puppet::Parser::Collector, "when building its ActiveRecord query for co
it "should include the export query if one is provided" do
@collector.equery = "test = true"
Puppet::Rails::Resource.stubs(:find).with { |*arguments|
- options = arguments[3]
+ options = arguments[1]
options[:conditions][0].include?("test = true")
}.returns([@resource])
diff --git a/spec/unit/parser/functions/require.rb b/spec/unit/parser/functions/require.rb
index 24c9ecc64..577a52a42 100755
--- a/spec/unit/parser/functions/require.rb
+++ b/spec/unit/parser/functions/require.rb
@@ -31,6 +31,12 @@ describe "the require function" do
@scope.function_require("myclass")
end
+ it "should verify the 'include' function is loaded" do
+ Puppet::Parser::Functions.expects(:function).with(:include).returns(:function_include)
+ @scope.stubs(:function_include)
+ @scope.function_require("myclass")
+ end
+
it "should include the class but not add a dependency if used on a client not at least version 0.25" do
@resource.expects(:metaparam_compatibility_mode?).returns true
@scope.expects(:warning)
diff --git a/spec/unit/parser/resource.rb b/spec/unit/parser/resource.rb
index 0a67c4b54..3f08de958 100755
--- a/spec/unit/parser/resource.rb
+++ b/spec/unit/parser/resource.rb
@@ -25,7 +25,7 @@ describe Puppet::Parser::Resource do
params = args[:params] || {:one => "yay", :three => "rah"}
if args[:params] == :none
args.delete(:params)
- else
+ elsif not args[:params].is_a? Array
args[:params] = paramify(args[:source], params)
end
@@ -483,5 +483,18 @@ describe Puppet::Parser::Resource do
result = @parser_resource.to_resource
result[:fee].should == ["a", Puppet::Resource::Reference.new(:file, "/my/file1"), Puppet::Resource::Reference.new(:file, "/my/file2")]
end
+
+ it "should fail if the same param is declared twice" do
+ lambda do
+ @parser_resource = mkresource :source => @source, :params => [
+ Puppet::Parser::Resource::Param.new(
+ :name => :foo, :value => "bar", :source => @source
+ ),
+ Puppet::Parser::Resource::Param.new(
+ :name => :foo, :value => "baz", :source => @source
+ )
+ ]
+ end.should raise_error(Puppet::ParseError)
+ end
end
end
diff --git a/spec/unit/parser/resource/reference.rb b/spec/unit/parser/resource/reference.rb
index e082136c5..064c51b20 100755
--- a/spec/unit/parser/resource/reference.rb
+++ b/spec/unit/parser/resource/reference.rb
@@ -40,10 +40,15 @@ describe Puppet::Parser::Resource::Reference do
ref.to_s.should == "File[/tmp/yay]"
end
- it "should canonize resource references" do
+ it "should canonize resource reference types" do
ref = @type.new(:type => "foo::bar", :title => "/tmp/yay")
ref.to_s.should == "Foo::Bar[/tmp/yay]"
end
+
+ it "should canonize resource reference values" do
+ ref = @type.new(:type => "file", :title => "/tmp/yay/")
+ ref.to_s.should == "File[/tmp/yay]"
+ end
end
describe Puppet::Parser::Resource::Reference, " when modeling defined types" do
diff --git a/spec/unit/parser/scope.rb b/spec/unit/parser/scope.rb
index 0859eadb4..d7800e4b3 100755
--- a/spec/unit/parser/scope.rb
+++ b/spec/unit/parser/scope.rb
@@ -43,7 +43,7 @@ describe Puppet::Parser::Scope do
describe "and the variable is qualified" do
before do
@parser = Puppet::Parser::Parser.new()
- @compiler = Puppet::Parser::Compiler.new(stub("node", :name => "foonode"), @parser)
+ @compiler = Puppet::Parser::Compiler.new(stub("node", :name => "foonode", :classes => []), @parser)
@scope.compiler = @compiler
@scope.parser = @parser
end