summaryrefslogtreecommitdiffstats
path: root/spec/unit/parser/resource.rb
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-01-19 13:40:40 -0800
committerLuke Kanies <luke@madstop.com>2008-01-19 13:40:40 -0800
commitf98be4a7198326b26f1072c401b3e337f340db40 (patch)
tree36a3f5637a175bc7da7acb639857bf2c2ca9f0c3 /spec/unit/parser/resource.rb
parent2cbab2c6916d6bd7c5ad01b137b3469eeea8d3e4 (diff)
downloadpuppet-f98be4a7198326b26f1072c401b3e337f340db40.tar.gz
puppet-f98be4a7198326b26f1072c401b3e337f340db40.tar.xz
puppet-f98be4a7198326b26f1072c401b3e337f340db40.zip
Fixing #976 -- both the full name of qualified classes and
the class parts are now added as tags. I've also created a Tagging module that we should push throughout the rest of the system that uses tags.
Diffstat (limited to 'spec/unit/parser/resource.rb')
-rwxr-xr-xspec/unit/parser/resource.rb60
1 files changed, 60 insertions, 0 deletions
diff --git a/spec/unit/parser/resource.rb b/spec/unit/parser/resource.rb
index 3d048f7e6..319d8f7d8 100755
--- a/spec/unit/parser/resource.rb
+++ b/spec/unit/parser/resource.rb
@@ -4,6 +4,7 @@ require File.dirname(__FILE__) + '/../../spec_helper'
# LAK: FIXME This is just new tests for resources; I have
# not moved all tests over yet.
+
describe Puppet::Parser::Resource, " when evaluating" do
before do
@type = Puppet::Parser::Resource
@@ -86,4 +87,63 @@ describe Puppet::Parser::Resource, " when finishing" do
@resource["require"].sort.should == %w{container1 container2 resource1 resource2}
end
+
+ it "should add any tags from the scope resource" do
+ scope_resource = stub 'scope_resource', :tags => %w{one two}
+ @scope.stubs(:resource).returns(scope_resource)
+
+ @resource.class.publicize_methods(:add_scope_tags) { @resource.add_scope_tags }
+
+ @resource.tags.should be_include("one")
+ @resource.tags.should be_include("two")
+ end
+end
+
+describe Puppet::Parser::Resource, "when being tagged" do
+ before do
+ @scope_resource = stub 'scope_resource', :tags => %w{srone srtwo}
+ @scope = stub 'scope', :resource => @scope_resource
+ @resource = Puppet::Parser::Resource.new(:type => "file", :title => "yay", :scope => @scope, :source => mock('source'))
+ end
+
+ it "should get tagged with the resource type" do
+ @resource.tags.should be_include("file")
+ end
+
+ it "should get tagged with the title" do
+ @resource.tags.should be_include("yay")
+ end
+
+ it "should get tagged with each name in the title if the title is a qualified class name" do
+ resource = Puppet::Parser::Resource.new(:type => "file", :title => "one::two", :scope => @scope, :source => mock('source'))
+ resource.tags.should be_include("one")
+ resource.tags.should be_include("two")
+ end
+
+ it "should get tagged with each name in the type if the type is a qualified class name" do
+ resource = Puppet::Parser::Resource.new(:type => "one::two", :title => "whatever", :scope => @scope, :source => mock('source'))
+ resource.tags.should be_include("one")
+ resource.tags.should be_include("two")
+ end
+
+ it "should not get tagged with non-alphanumeric titles" do
+ resource = Puppet::Parser::Resource.new(:type => "file", :title => "this is a test", :scope => @scope, :source => mock('source'))
+ resource.tags.should_not be_include("this is a test")
+ end
+
+ it "should fail on tags containing '*' characters" do
+ lambda { @resource.tag("bad*tag") }.should raise_error(Puppet::ParseError)
+ end
+
+ it "should fail on tags starting with '-' characters" do
+ lambda { @resource.tag("-badtag") }.should raise_error(Puppet::ParseError)
+ end
+
+ it "should fail on tags containing ' ' characters" do
+ lambda { @resource.tag("bad tag") }.should raise_error(Puppet::ParseError)
+ end
+
+ it "should allow alpha tags" do
+ lambda { @resource.tag("good_tag") }.should_not raise_error(Puppet::ParseError)
+ end
end