summaryrefslogtreecommitdiffstats
path: root/spec/unit
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-01-09 13:03:15 -0800
committerLuke Kanies <luke@madstop.com>2008-01-09 13:03:15 -0800
commit5bef4a55b3489a6404ee34b900621af8b784749a (patch)
tree82a03e2434597160c8a52125f2c6fd948a942291 /spec/unit
parent3cc3e0f5b21deee4fbdbcbae18fba47c7a0cbb1e (diff)
downloadpuppet-5bef4a55b3489a6404ee34b900621af8b784749a.tar.gz
puppet-5bef4a55b3489a6404ee34b900621af8b784749a.tar.xz
puppet-5bef4a55b3489a6404ee34b900621af8b784749a.zip
Another round of fixes toward making global resources work.
The only remaining failures are more complicated ones (which I'll need to not be on a plane to debug, for battery reasons) or those related to the broken directory_service providers.
Diffstat (limited to 'spec/unit')
-rwxr-xr-xspec/unit/node/catalog.rb57
-rwxr-xr-xspec/unit/other/transbucket.rb7
-rwxr-xr-xspec/unit/ral/provider/mount/parsed.rb4
-rwxr-xr-xspec/unit/ral/types/file.rb4
-rwxr-xr-xspec/unit/ral/types/interface.rb2
-rwxr-xr-xspec/unit/ral/types/mount.rb8
-rwxr-xr-xspec/unit/ral/types/package.rb9
-rwxr-xr-xspec/unit/ral/types/schedule.rb4
-rwxr-xr-xspec/unit/ral/types/service.rb10
9 files changed, 40 insertions, 65 deletions
diff --git a/spec/unit/node/catalog.rb b/spec/unit/node/catalog.rb
index 3833890f7..6f246f6b3 100755
--- a/spec/unit/node/catalog.rb
+++ b/spec/unit/node/catalog.rb
@@ -308,8 +308,6 @@ describe Puppet::Node::Catalog, " when converting to a RAL catalog" do
newconfig = nil
- Puppet::Type.allclear
-
proc { @catalog = config.to_ral }.should_not raise_error
@catalog.resource("Test[changer2]").should equal(resource)
end
@@ -323,9 +321,9 @@ end
describe Puppet::Node::Catalog, " when functioning as a resource container" do
before do
@catalog = Puppet::Node::Catalog.new("host")
- @one = stub 'resource1', :ref => "Me[one]", :catalog= => nil
- @two = stub 'resource2', :ref => "Me[two]", :catalog= => nil
- @dupe = stub 'resource3', :ref => "Me[one]", :catalog= => nil
+ @one = stub 'resource1', :ref => "Me[one]", :catalog= => nil, :title => "one", :[] => "one"
+ @two = stub 'resource2', :ref => "Me[two]", :catalog= => nil, :title => "two", :[] => "two"
+ @dupe = stub 'resource3', :ref => "Me[one]", :catalog= => nil, :title => "one", :[] => "one"
end
it "should provide a method to add one or more resources" do
@@ -437,6 +435,28 @@ describe Puppet::Node::Catalog, " when functioning as a resource container" do
@catalog.resource("me", "other").should equal(@one)
end
+ it "should ignore conflicting aliases that point to the aliased resource" do
+ @catalog.alias(@one, "other")
+ lambda { @catalog.alias(@one, "other") }.should_not raise_error
+ end
+
+ it "should create aliases for resources isomorphic resources whose names do not match their titles" do
+ resource = Puppet::Type::File.create(:title => "testing", :path => "/something")
+
+ @catalog.add_resource(resource)
+
+ @catalog.resource(:file, "/something").should equal(resource)
+ end
+
+ it "should not create aliases for resources non-isomorphic resources whose names do not match their titles" do
+ resource = Puppet::Type.type(:exec).create(:title => "testing", :command => "echo", :path => %w{/bin /usr/bin /usr/local/bin})
+
+ @catalog.add_resource(resource)
+
+ # Yay, I've already got a 'should' method
+ @catalog.resource(:exec, "echo").object_id.should == nil.object_id
+ end
+
# This test is the same as the previous, but the behaviour should be explicit.
it "should alias using the class name from the resource reference, not the resource class name" do
@catalog.add_resource @one
@@ -444,11 +464,16 @@ describe Puppet::Node::Catalog, " when functioning as a resource container" do
@catalog.resource("me", "other").should equal(@one)
end
- it "should fail to add an alias if the aliased name already exists" do
+ it "should fail to add an alias if the aliased name already exists as a resource" do
@catalog.add_resource @one
proc { @catalog.alias @two, "one" }.should raise_error(ArgumentError)
end
+ it "should fail to add an alias if the aliased name already exists as an alias" do
+ @catalog.alias(@one, "yayness")
+ proc { @catalog.alias @two, "yayness" }.should raise_error(ArgumentError)
+ end
+
it "should remove resource aliases when the target resource is removed" do
@catalog.add_resource @one
@catalog.alias(@one, "other")
@@ -457,8 +482,10 @@ describe Puppet::Node::Catalog, " when functioning as a resource container" do
@catalog.resource("me", "other").should be_nil
end
- after do
- Puppet::Type.allclear
+ it "should return aliased resources when asked for the resource by the alias" do
+ @catalog.add_resource @one
+ @catalog.alias(@one, "other")
+ @catalog.resource("Me[other]").should equal(@one)
end
end
@@ -645,14 +672,14 @@ describe Puppet::Node::Catalog, " when creating a relationship graph" do
end
it "should look up resources in the relationship graph if not found in the main catalog" do
- five = stub 'five', :ref => "File[five]", :catalog= => nil
+ five = stub 'five', :ref => "File[five]", :catalog= => nil, :title => "five", :[] => "five"
@relationships.add_resource five
@catalog.resource(five.ref).should equal(five)
end
it "should provide a method to create additional resources that also registers the resource" do
args = {:name => "/yay", :ensure => :file}
- resource = stub 'file', :ref => "File[/yay]", :catalog= => @catalog
+ resource = stub 'file', :ref => "File[/yay]", :catalog= => @catalog, :title => "/yay", :[] => "/yay"
Puppet::Type.type(:file).expects(:create).with(args).returns(resource)
@catalog.create_resource :file, args
@catalog.resource("File[/yay]").should equal(resource)
@@ -660,7 +687,7 @@ describe Puppet::Node::Catalog, " when creating a relationship graph" do
it "should provide a mechanism for creating implicit resources" do
args = {:name => "/yay", :ensure => :file}
- resource = stub 'file', :ref => "File[/yay]", :catalog= => @catalog
+ resource = stub 'file', :ref => "File[/yay]", :catalog= => @catalog, :title => "/yay", :[] => "/yay"
Puppet::Type.type(:file).expects(:create).with(args).returns(resource)
resource.expects(:implicit=).with(true)
@catalog.create_implicit_resource :file, args
@@ -669,7 +696,7 @@ describe Puppet::Node::Catalog, " when creating a relationship graph" do
it "should add implicit resources to the relationship graph if there is one" do
args = {:name => "/yay", :ensure => :file}
- resource = stub 'file', :ref => "File[/yay]", :catalog= => @catalog
+ resource = stub 'file', :ref => "File[/yay]", :catalog= => @catalog, :title => "/yay", :[] => "/yay"
resource.expects(:implicit=).with(true)
Puppet::Type.type(:file).expects(:create).with(args).returns(resource)
# build the graph
@@ -681,7 +708,7 @@ describe Puppet::Node::Catalog, " when creating a relationship graph" do
it "should remove resources created mid-transaction" do
args = {:name => "/yay", :ensure => :file}
- resource = stub 'file', :ref => "File[/yay]", :catalog= => @catalog
+ resource = stub 'file', :ref => "File[/yay]", :catalog= => @catalog, :title => "/yay", :[] => "/yay"
@transaction = mock 'transaction'
Puppet::Transaction.stubs(:new).returns(@transaction)
@transaction.stubs(:evaluate)
@@ -700,10 +727,6 @@ describe Puppet::Node::Catalog, " when creating a relationship graph" do
@catalog.remove_resource(@one)
@catalog.relationship_graph.vertex?(@one).should be_false
end
-
- after do
- Puppet::Type.allclear
- end
end
describe Puppet::Node::Catalog, " when writing dot files" do
diff --git a/spec/unit/other/transbucket.rb b/spec/unit/other/transbucket.rb
index 3904e39fe..89f48ad41 100755
--- a/spec/unit/other/transbucket.rb
+++ b/spec/unit/other/transbucket.rb
@@ -116,13 +116,11 @@ describe Puppet::TransBucket, " when generating a catalog" do
it "should only call to_type on each resource once" do
@topobj.expects(:to_type)
@bottomobj.expects(:to_type)
- Puppet::Type.allclear
@top.to_catalog
end
it "should set each TransObject's catalog before converting to a RAL resource" do
@middleobj.expects(:catalog=).with { |c| c.is_a?(Puppet::Node::Catalog) }
- Puppet::Type.allclear
@top.to_catalog
end
@@ -130,13 +128,8 @@ describe Puppet::TransBucket, " when generating a catalog" do
# each bucket is seen twice in the loop, so we have to handle the case where the config
# is set twice
@bottom.expects(:catalog=).with { |c| c.is_a?(Puppet::Node::Catalog) }.at_least_once
- Puppet::Type.allclear
@top.to_catalog
end
-
- after do
- Puppet::Type.allclear
- end
end
describe Puppet::TransBucket, " when serializing" do
diff --git a/spec/unit/ral/provider/mount/parsed.rb b/spec/unit/ral/provider/mount/parsed.rb
index 89928891a..2fd15a543 100755
--- a/spec/unit/ral/provider/mount/parsed.rb
+++ b/spec/unit/ral/provider/mount/parsed.rb
@@ -165,10 +165,6 @@ describe provider_class, " when parsing information about the root filesystem" d
@provider_class.prefetch("/" => @mount)
@mount.provider.should be_mounted
end
-
- after do
- Puppet::Type.allclear
- end
end
describe provider_class, " when mounting and unmounting" do
diff --git a/spec/unit/ral/types/file.rb b/spec/unit/ral/types/file.rb
index 1e20b06f4..5ade79012 100755
--- a/spec/unit/ral/types/file.rb
+++ b/spec/unit/ral/types/file.rb
@@ -25,8 +25,4 @@ describe Puppet::Type::File, " when used with replace=>false and content" do
it "should not be insync if the file doesnot exist" do
@file.property(:content).insync?(:nil).should be_false
end
-
- after do
- Puppet::Type::File.clear
- end
end
diff --git a/spec/unit/ral/types/interface.rb b/spec/unit/ral/types/interface.rb
index 2e0176152..e51465a0c 100755
--- a/spec/unit/ral/types/interface.rb
+++ b/spec/unit/ral/types/interface.rb
@@ -90,6 +90,4 @@ describe interface do
it "should have a target parameter" do
@class.attrtype(:target).should == :param
end
-
- after { @class.clear }
end
diff --git a/spec/unit/ral/types/mount.rb b/spec/unit/ral/types/mount.rb
index 7d01022b5..5965908cb 100755
--- a/spec/unit/ral/types/mount.rb
+++ b/spec/unit/ral/types/mount.rb
@@ -13,8 +13,6 @@ describe Puppet::Type::Mount do
mount = Puppet::Type::Mount.create(:name => "yay")
mount.should(:ensure).should be_nil
end
-
- after { Puppet::Type::Mount.clear }
end
describe Puppet::Type::Mount, "when validating attributes" do
@@ -53,8 +51,6 @@ describe Puppet::Type::Mount::Ensure, "when validating values" do
it "should support :mounted as a value to :ensure" do
Puppet::Type::Mount.create(:name => "yay", :ensure => :mounted)
end
-
- after { Puppet::Type::Mount.clear }
end
module MountEvaluationTesting
@@ -78,10 +74,6 @@ module MountEvaluationTesting
@provider.stubs(param).returns(value)
end
end
-
- def teardown
- Puppet::Type::Mount.clear
- end
end
describe Puppet::Type::Mount::Ensure, "when retrieving its current state" do
diff --git a/spec/unit/ral/types/package.rb b/spec/unit/ral/types/package.rb
index f14a792b9..e9e3b9e4e 100755
--- a/spec/unit/ral/types/package.rb
+++ b/spec/unit/ral/types/package.rb
@@ -29,8 +29,6 @@ describe Puppet::Type::Package do
pkg = Puppet::Type::Package.create(:name => "yay")
pkg.should(:ensure).should == :present
end
-
- after { Puppet::Type::Package.clear }
end
describe Puppet::Type::Package, "when validating attributes" do
@@ -97,8 +95,6 @@ describe Puppet::Type::Package, "when validating attribute values" do
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)
end
-
- after { Puppet::Type::Package.clear }
end
module PackageEvaluationTesting
@@ -114,11 +110,6 @@ module PackageEvaluationTesting
def setprops(properties)
@provider.stubs(:properties).returns(properties)
end
-
- def teardown
- @catalog.clear(true)
- Puppet::Type::Package.clear
- end
end
describe Puppet::Type::Package, "when it should be purged" do
diff --git a/spec/unit/ral/types/schedule.rb b/spec/unit/ral/types/schedule.rb
index 73b3a0bd1..856a73186 100755
--- a/spec/unit/ral/types/schedule.rb
+++ b/spec/unit/ral/types/schedule.rb
@@ -43,10 +43,6 @@ module ScheduleTesting
def sec(method, count)
diff(:sec, 1, method, count)
end
-
- def teardown
- Puppet::Type::Schedule.clear
- end
end
describe Puppet::Type::Schedule do
diff --git a/spec/unit/ral/types/service.rb b/spec/unit/ral/types/service.rb
index 981d38a15..3944f146c 100755
--- a/spec/unit/ral/types/service.rb
+++ b/spec/unit/ral/types/service.rb
@@ -117,8 +117,6 @@ describe Puppet::Type::Service, "when validating attribute values" do
svc = Puppet::Type::Service.create(:name => "yay", :path => ["/one:/two", "/three:/four"])
svc[:path].should == %w{/one /two /three /four}
end
-
- after { Puppet::Type::Service.clear }
end
describe Puppet::Type::Service, "when setting default attribute values" do
@@ -141,8 +139,6 @@ describe Puppet::Type::Service, "when setting default attribute values" do
svc = Puppet::Type::Service.create(:name => "other")
svc[:pattern].should == "other"
end
-
- after { Puppet::Type::Service.clear }
end
describe Puppet::Type::Service, "when retrieving the host's current state" do
@@ -162,8 +158,6 @@ describe Puppet::Type::Service, "when retrieving the host's current state" do
@service[:enable] = true
@service.property(:enable).retrieve.should == :yepper
end
-
- after { Puppet::Type::Service.clear }
end
describe Puppet::Type::Service, "when changing the host" do
@@ -210,8 +204,6 @@ describe Puppet::Type::Service, "when changing the host" do
@service.property(:ensure).sync
end
-
- after { Puppet::Type::Service.clear }
end
describe Puppet::Type::Service, "when refreshing the service" do
@@ -244,6 +236,4 @@ describe Puppet::Type::Service, "when refreshing the service" do
@service.provider.expects(:restart)
@service.refresh
end
-
- after { Puppet::Type::Service.clear }
end