diff options
| author | Luke Kanies <luke@reductivelabs.com> | 2010-01-29 20:57:21 -0600 |
|---|---|---|
| committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
| commit | 7089446697ad550c22012bc2b5572030727d67e1 (patch) | |
| tree | 40d160f11839fe6e20311186ded4e621d23e1242 /spec/unit/parser/functions | |
| parent | 4871c909cd28c82b64d0b62d8a27e62737d8733d (diff) | |
| download | puppet-7089446697ad550c22012bc2b5572030727d67e1.tar.gz puppet-7089446697ad550c22012bc2b5572030727d67e1.tar.xz puppet-7089446697ad550c22012bc2b5572030727d67e1.zip | |
Removing Resource::Reference classes
This commit is hopefully less messy than it
first appears, but it's certainly cross-cutting.
The reason for all of this is that we previously only
looked up builtin resource types from outside the parser,
but now that the defined resource types are available globally
via environments, we can push that lookup code to Resource.
Once we do that, however, we have to have environment and
namespace information in every resource.
Here I remove the Resource::Reference classes (except
the AST class), and use Resource instances instead. I
did this because the shared code between the two classes
got incredibly complicated, such that they should have had
a hierarchical relationship disallowed by their constants.
This complexity convinced me just to get rid of References
entirely.
I also make Puppet::Parser::Resource a subclass
of Puppet::Resource.
There are still broken tests in test/, but this was a big
enough commit I wanted to get it in.
Signed-off-by: Luke Kanies <luke@reductivelabs.com>
Diffstat (limited to 'spec/unit/parser/functions')
| -rwxr-xr-x | spec/unit/parser/functions/defined.rb | 50 | ||||
| -rwxr-xr-x | spec/unit/parser/functions/require.rb | 2 | ||||
| -rwxr-xr-x | spec/unit/parser/functions/tag.rb | 24 |
3 files changed, 75 insertions, 1 deletions
diff --git a/spec/unit/parser/functions/defined.rb b/spec/unit/parser/functions/defined.rb new file mode 100755 index 000000000..0da8c4a31 --- /dev/null +++ b/spec/unit/parser/functions/defined.rb @@ -0,0 +1,50 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../../spec_helper' + +describe "the 'defined' function" do + + before :each do + @scope = Puppet::Parser::Scope.new() + @compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("foo")) + @scope.compiler = @compiler + end + + it "should exist" do + Puppet::Parser::Functions.function("defined").should == "function_defined" + end + + it "should be true when the name is defined as a class" do + @scope.known_resource_types.add Puppet::Resource::Type.new(:hostclass, "yayness") + @scope.function_defined("yayness").should be_true + end + + it "should be true when the name is defined as a definition" do + @scope.known_resource_types.add Puppet::Resource::Type.new(:definition, "yayness") + @scope.function_defined("yayness").should be_true + end + + it "should be true when the name is defined as a builtin type" do + @scope.function_defined("file").should be_true + end + + + it "should be true when any of the provided names are defined" do + @scope.known_resource_types.add Puppet::Resource::Type.new(:definition, "yayness") + @scope.function_defined(["meh", "yayness", "booness"]).should be_true + end + + it "should be false when a single given name is not defined" do + @scope.function_defined("meh").should be_false + end + + it "should be false when none of the names are defined" do + @scope.function_defined(["meh", "yayness", "booness"]).should be_false + end + + it "should be true when a resource reference is provided and the resource is in the catalog" do + resource = Puppet::Resource.new("file", "/my/file") + @compiler.add_resource(@scope, resource) + @scope.function_defined(resource).should be_true + end +end diff --git a/spec/unit/parser/functions/require.rb b/spec/unit/parser/functions/require.rb index 924990a5d..1d9ce931c 100755 --- a/spec/unit/parser/functions/require.rb +++ b/spec/unit/parser/functions/require.rb @@ -28,7 +28,7 @@ describe "the require function" do end it "should set the 'require' prarameter on the resource to a resource reference" do - @resource.expects(:set_parameter).with { |name, value| name == :require and value[0].is_a?(Puppet::Parser::Resource::Reference) } + @resource.expects(:set_parameter).with { |name, value| name == :require and value[0].is_a?(Puppet::Resource) } @scope.stubs(:function_include) @scope.function_require("myclass") end diff --git a/spec/unit/parser/functions/tag.rb b/spec/unit/parser/functions/tag.rb new file mode 100755 index 000000000..5fb467e59 --- /dev/null +++ b/spec/unit/parser/functions/tag.rb @@ -0,0 +1,24 @@ +#! /usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../../spec_helper' + +describe "the 'tag' function" do + + before :each do + @scope = Puppet::Parser::Scope.new() + end + + it "should exist" do + Puppet::Parser::Functions.function(:tag).should == "function_tag" + end + + it "should tag the resource with any provided tags" do + resource = Puppet::Parser::Resource.new(:file, "/file", :scope => @scope) + @scope.expects(:resource).returns resource + + @scope.function_tag ["one", "two"] + + resource.should be_tagged("one") + resource.should be_tagged("two") + end +end |
