summaryrefslogtreecommitdiffstats
path: root/spec/unit
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-02-28 14:44:39 -0600
committerLuke Kanies <luke@madstop.com>2008-02-28 14:44:39 -0600
commitfe1f4f57bf5ee0792ee645ec8e0bfddf455ea1e3 (patch)
treead62c32acd6fa7fb22a7025866d43eaea688f673 /spec/unit
parentdd17d4ca71e17deba8cf19e376e2d711fa516d92 (diff)
parentc0b5352851d3fdef20b2a432f6f06d31fdc9ce99 (diff)
downloadpuppet-fe1f4f57bf5ee0792ee645ec8e0bfddf455ea1e3.tar.gz
puppet-fe1f4f57bf5ee0792ee645ec8e0bfddf455ea1e3.tar.xz
puppet-fe1f4f57bf5ee0792ee645ec8e0bfddf455ea1e3.zip
Merge branch '0.24.x' of ssh://reductivelabs.com/opt/rl/git/puppet into 0.24.x
Diffstat (limited to 'spec/unit')
-rwxr-xr-xspec/unit/node/catalog.rb8
-rwxr-xr-xspec/unit/parser/ast/hostclass.rb8
-rwxr-xr-xspec/unit/parser/resource.rb211
-rwxr-xr-xspec/unit/ral/types/package.rb4
-rwxr-xr-xspec/unit/ral/types/service.rb15
5 files changed, 138 insertions, 108 deletions
diff --git a/spec/unit/node/catalog.rb b/spec/unit/node/catalog.rb
index b1bf5abaa..604dabbb6 100755
--- a/spec/unit/node/catalog.rb
+++ b/spec/unit/node/catalog.rb
@@ -476,17 +476,19 @@ describe Puppet::Node::Catalog, " when functioning as a resource container" do
it "should add an alias for the namevar when the title and name differ on isomorphic resource types" do
resource = Puppet::Type.type(:file).create :path => "/something", :title => "other", :content => "blah"
+ resource.expects(:isomorphic?).returns(true)
@catalog.add_resource(resource)
@catalog.resource(:file, "other").should equal(resource)
@catalog.resource(:file, "/something").ref.should == resource.ref
end
it "should not add an alias for the namevar when the title and name differ on non-isomorphic resource types" do
- resource = Puppet::Type.type(:exec).create :command => "/bin/true", :title => "other"
+ resource = Puppet::Type.type(:file).create :path => "/something", :title => "other", :content => "blah"
+ resource.expects(:isomorphic?).returns(false)
@catalog.add_resource(resource)
- @catalog.resource(:exec, resource.title).should equal(resource)
+ @catalog.resource(:file, resource.title).should equal(resource)
# We can't use .should here, because the resources respond to that method.
- if @catalog.resource(:exec, resource.name)
+ if @catalog.resource(:file, resource.name)
raise "Aliased non-isomorphic resource"
end
end
diff --git a/spec/unit/parser/ast/hostclass.rb b/spec/unit/parser/ast/hostclass.rb
index a53c3b092..0abc174d9 100755
--- a/spec/unit/parser/ast/hostclass.rb
+++ b/spec/unit/parser/ast/hostclass.rb
@@ -42,6 +42,12 @@ describe Puppet::Parser::AST::HostClass do
@top.evaluate(@scope)
end
+ it "should return the existing resource when not creating a new one" do
+ @compiler.catalog.expects(:resource).with(:class, "top").returns("something")
+ @compiler.catalog.expects(:add_resource).never
+ @top.evaluate(@scope).should == "something"
+ end
+
it "should not create a new parent resource if one already exists and it has a parent class" do
@top.evaluate(@scope)
@@ -126,4 +132,4 @@ describe Puppet::Parser::AST::HostClass do
@compiler.class_scope(@middle).namespaces.should be_include(@top.namespace)
end
end
-end \ No newline at end of file
+end
diff --git a/spec/unit/parser/resource.rb b/spec/unit/parser/resource.rb
index a5a49e2a6..035590341 100755
--- a/spec/unit/parser/resource.rb
+++ b/spec/unit/parser/resource.rb
@@ -5,145 +5,160 @@ 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
+describe Puppet::Parser::Resource do
before do
- @type = Puppet::Parser::Resource
-
@parser = Puppet::Parser::Parser.new :Code => ""
@source = @parser.newclass ""
- @definition = @parser.newdefine "mydefine"
- @class = @parser.newclass "myclass"
- @nodedef = @parser.newnode("mynode")[0]
@node = Puppet::Node.new("yaynode")
@compiler = Puppet::Parser::Compiler.new(@node, @parser)
@scope = @compiler.topscope
end
- it "should evaluate the associated AST definition" do
- res = @type.new(:type => "mydefine", :title => "whatever", :scope => @scope, :source => @source)
- @definition.expects(:evaluate_code).with(res)
-
- res.evaluate
+ it "should be isomorphic if it is builtin and models an isomorphic type" do
+ Puppet::Type.type(:file).expects(:isomorphic?).returns(true)
+ @resource = Puppet::Parser::Resource.new(:type => "file", :title => "whatever", :scope => @scope, :source => @source).isomorphic?.should be_true
end
- it "should evaluate the associated AST class" do
- res = @type.new(:type => "class", :title => "myclass", :scope => @scope, :source => @source)
- @class.expects(:evaluate_code).with(res)
- res.evaluate
+ it "should not be isomorphic if it is builtin and models a non-isomorphic type" do
+ Puppet::Type.type(:file).expects(:isomorphic?).returns(false)
+ @resource = Puppet::Parser::Resource.new(:type => "file", :title => "whatever", :scope => @scope, :source => @source).isomorphic?.should be_false
end
- it "should evaluate the associated AST node" do
- res = @type.new(:type => "node", :title => "mynode", :scope => @scope, :source => @source)
- @nodedef.expects(:evaluate_code).with(res)
- res.evaluate
+ it "should be isomorphic if it is not builtin" do
+ @parser.newdefine "whatever"
+ @resource = Puppet::Parser::Resource.new(:type => "whatever", :title => "whatever", :scope => @scope, :source => @source).isomorphic?.should be_true
end
-end
-describe Puppet::Parser::Resource, " when finishing" do
- before do
- @parser = Puppet::Parser::Parser.new :Code => ""
- @source = @parser.newclass ""
- @definition = @parser.newdefine "mydefine"
- @class = @parser.newclass "myclass"
- @nodedef = @parser.newnode("mynode")[0]
- @node = Puppet::Node.new("yaynode")
- @compiler = Puppet::Parser::Compiler.new(@node, @parser)
- @scope = @compiler.topscope
+ describe "when evaluating" do
+ before do
+ @type = Puppet::Parser::Resource
- @resource = Puppet::Parser::Resource.new(:type => "mydefine", :title => "whatever", :scope => @scope, :source => @source)
- end
+ @definition = @parser.newdefine "mydefine"
+ @class = @parser.newclass "myclass"
+ @nodedef = @parser.newnode("mynode")[0]
+ end
- it "should copy metaparams from its scope" do
- @scope.setvar("noop", "true")
+ it "should evaluate the associated AST definition" do
+ res = @type.new(:type => "mydefine", :title => "whatever", :scope => @scope, :source => @source)
+ @definition.expects(:evaluate_code).with(res)
- @resource.class.publicize_methods(:add_metaparams) { @resource.add_metaparams }
+ res.evaluate
+ end
- @resource["noop"].should == "true"
+ it "should evaluate the associated AST class" do
+ res = @type.new(:type => "class", :title => "myclass", :scope => @scope, :source => @source)
+ @class.expects(:evaluate_code).with(res)
+ res.evaluate
+ end
+
+ it "should evaluate the associated AST node" do
+ res = @type.new(:type => "node", :title => "mynode", :scope => @scope, :source => @source)
+ @nodedef.expects(:evaluate_code).with(res)
+ res.evaluate
+ end
end
- it "should not copy metaparams that it already has" do
- @resource.class.publicize_methods(:set_parameter) { @resource.set_parameter("noop", "false") }
- @scope.setvar("noop", "true")
+ describe "when finishing" do
+ before do
+ @definition = @parser.newdefine "mydefine"
+ @class = @parser.newclass "myclass"
+ @nodedef = @parser.newnode("mynode")[0]
- @resource.class.publicize_methods(:add_metaparams) { @resource.add_metaparams }
+ @resource = Puppet::Parser::Resource.new(:type => "mydefine", :title => "whatever", :scope => @scope, :source => @source)
+ end
- @resource["noop"].should == "false"
- end
+ it "should copy metaparams from its scope" do
+ @scope.setvar("noop", "true")
- it "should stack relationship metaparams from its container if it already has them" do
- @resource.class.publicize_methods(:set_parameter) { @resource.set_parameter("require", "resource") }
- @scope.setvar("require", "container")
+ @resource.class.publicize_methods(:add_metaparams) { @resource.add_metaparams }
- @resource.class.publicize_methods(:add_metaparams) { @resource.add_metaparams }
+ @resource["noop"].should == "true"
+ end
- @resource["require"].sort.should == %w{container resource}
- end
+ it "should not copy metaparams that it already has" do
+ @resource.class.publicize_methods(:set_parameter) { @resource.set_parameter("noop", "false") }
+ @scope.setvar("noop", "true")
- it "should flatten the array resulting from stacking relationship metaparams" do
- @resource.class.publicize_methods(:set_parameter) { @resource.set_parameter("require", ["resource1", "resource2"]) }
- @scope.setvar("require", %w{container1 container2})
+ @resource.class.publicize_methods(:add_metaparams) { @resource.add_metaparams }
- @resource.class.publicize_methods(:add_metaparams) { @resource.add_metaparams }
+ @resource["noop"].should == "false"
+ end
- @resource["require"].sort.should == %w{container1 container2 resource1 resource2}
- end
+ it "should stack relationship metaparams from its container if it already has them" do
+ @resource.class.publicize_methods(:set_parameter) { @resource.set_parameter("require", "resource") }
+ @scope.setvar("require", "container")
- 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_metaparams) { @resource.add_metaparams }
- @resource.class.publicize_methods(:add_scope_tags) { @resource.add_scope_tags }
+ @resource["require"].sort.should == %w{container resource}
+ end
- @resource.tags.should be_include("one")
- @resource.tags.should be_include("two")
- end
-end
+ it "should flatten the array resulting from stacking relationship metaparams" do
+ @resource.class.publicize_methods(:set_parameter) { @resource.set_parameter("require", ["resource1", "resource2"]) }
+ @scope.setvar("require", %w{container1 container2})
-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
+ @resource.class.publicize_methods(:add_metaparams) { @resource.add_metaparams }
- it "should get tagged with the resource type" do
- @resource.tags.should be_include("file")
- end
+ @resource["require"].sort.should == %w{container1 container2 resource1 resource2}
+ end
- it "should get tagged with the title" do
- @resource.tags.should be_include("yay")
- 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)
- 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
+ @resource.class.publicize_methods(:add_scope_tags) { @resource.add_scope_tags }
- 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")
+ @resource.tags.should be_include("one")
+ @resource.tags.should be_include("two")
+ end
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
+ describe "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 fail on tags containing '*' characters" do
- lambda { @resource.tag("bad*tag") }.should raise_error(Puppet::ParseError)
- end
+ it "should get tagged with the resource type" do
+ @resource.tags.should be_include("file")
+ end
- it "should fail on tags starting with '-' characters" do
- lambda { @resource.tag("-badtag") }.should raise_error(Puppet::ParseError)
- end
+ it "should get tagged with the title" do
+ @resource.tags.should be_include("yay")
+ end
- it "should fail on tags containing ' ' characters" do
- lambda { @resource.tag("bad tag") }.should raise_error(Puppet::ParseError)
- 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)
+ it "should allow alpha tags" do
+ lambda { @resource.tag("good_tag") }.should_not raise_error(Puppet::ParseError)
+ end
end
end
diff --git a/spec/unit/ral/types/package.rb b/spec/unit/ral/types/package.rb
index 785d2eb37..5d96dc4ae 100755
--- a/spec/unit/ral/types/package.rb
+++ b/spec/unit/ral/types/package.rb
@@ -94,8 +94,8 @@ describe Puppet::Type::Package, "when validating attribute values" do
proc { Puppet::Type::Package.create(:name => "yay", :ensure => "1.0") }.should raise_error(Puppet::Error)
end
- it "should only accept files and URLs as values to :source" do
- proc { Puppet::Type::Package.create(:name => "yay", :source => "stuff") }.should raise_error(Puppet::Error)
+ it "should accept any string as an argument to :source" do
+ proc { Puppet::Type::Package.create(:name => "yay", :source => "stuff") }.should_not raise_error(Puppet::Error)
end
after { Puppet::Type::Package.clear }
diff --git a/spec/unit/ral/types/service.rb b/spec/unit/ral/types/service.rb
index 981d38a15..0f00992fa 100755
--- a/spec/unit/ral/types/service.rb
+++ b/spec/unit/ral/types/service.rb
@@ -15,7 +15,7 @@ describe Puppet::Type::Service do
end
describe Puppet::Type::Service, "when validating attributes" do
- [:name, :binary, :hasstatus, :path, :pattern, :start, :restart, :stop, :status, :hasrestart].each do |param|
+ [:name, :binary, :hasstatus, :path, :pattern, :start, :restart, :stop, :status, :hasrestart, :control].each do |param|
it "should have a #{param} parameter" do
Puppet::Type::Service.attrtype(param).should == :param
end
@@ -30,7 +30,7 @@ end
describe Puppet::Type::Service, "when validating attribute values" do
before do
- @provider = stub 'provider', :class => Puppet::Type::Service.defaultprovider, :clear => nil
+ @provider = stub 'provider', :class => Puppet::Type::Service.defaultprovider, :clear => nil, :controllable? => false
Puppet::Type::Service.defaultprovider.stubs(:new).returns(@provider)
end
@@ -132,16 +132,23 @@ describe Puppet::Type::Service, "when setting default attribute values" do
svc[:path].should == ["testing"]
end
- it "should default to the binary for the pattern if one is provided" do
+ it "should default 'pattern' to the binary if one is provided" do
svc = Puppet::Type::Service.create(:name => "other", :binary => "/some/binary")
svc[:pattern].should == "/some/binary"
end
- it "should default to the name for the pattern if no pattern is provided" do
+ it "should default 'pattern' to the name if no pattern is provided" do
svc = Puppet::Type::Service.create(:name => "other")
svc[:pattern].should == "other"
end
+ it "should default 'control' to the upcased service name with periods replaced by underscores if the provider supports the 'controllable' feature" do
+ provider = stub 'provider', :controllable? => true, :class => Puppet::Type::Service.defaultprovider, :clear => nil
+ Puppet::Type::Service.defaultprovider.stubs(:new).returns(provider)
+ svc = Puppet::Type::Service.create(:name => "nfs.client")
+ svc[:control].should == "NFS_CLIENT_START"
+ end
+
after { Puppet::Type::Service.clear }
end