summaryrefslogtreecommitdiffstats
path: root/spec/unit
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit')
-rwxr-xr-xspec/unit/other/transaction.rb33
-rwxr-xr-xspec/unit/parser/ast/astarray.rb4
-rwxr-xr-xspec/unit/parser/ast/resource.rb103
-rwxr-xr-xspec/unit/parser/collector.rb8
-rwxr-xr-xspec/unit/parser/functions/realize.rb51
-rw-r--r--spec/unit/provider/naginator.rb58
-rwxr-xr-xspec/unit/provider/parsedfile.rb50
-rwxr-xr-xspec/unit/transaction.rb213
-rw-r--r--spec/unit/type/file/selinux.rb6
-rwxr-xr-xspec/unit/type/user.rb10
-rwxr-xr-xspec/unit/util/nagios_maker.rb66
11 files changed, 333 insertions, 269 deletions
diff --git a/spec/unit/other/transaction.rb b/spec/unit/other/transaction.rb
deleted file mode 100755
index d2ac26869..000000000
--- a/spec/unit/other/transaction.rb
+++ /dev/null
@@ -1,33 +0,0 @@
-#!/usr/bin/env ruby
-
-require File.dirname(__FILE__) + '/../../spec_helper'
-
-require 'puppet/transaction'
-
-describe Puppet::Transaction, " when determining tags" do
- before do
- @config = Puppet::Resource::Catalog.new
- @transaction = Puppet::Transaction.new(@config)
- end
-
- it "should default to the tags specified in the :tags setting" do
- Puppet.expects(:[]).with(:tags).returns("one")
- @transaction.tags.should == %w{one}
- end
-
- it "should split tags based on ','" do
- Puppet.expects(:[]).with(:tags).returns("one,two")
- @transaction.tags.should == %w{one two}
- end
-
- it "should use any tags set after creation" do
- Puppet.expects(:[]).with(:tags).never
- @transaction.tags = %w{one two}
- @transaction.tags.should == %w{one two}
- end
-
- it "should always convert assigned tags to an array" do
- @transaction.tags = "one::two"
- @transaction.tags.should == %w{one::two}
- end
-end
diff --git a/spec/unit/parser/ast/astarray.rb b/spec/unit/parser/ast/astarray.rb
index f1c28ce47..b3026fe1e 100755
--- a/spec/unit/parser/ast/astarray.rb
+++ b/spec/unit/parser/ast/astarray.rb
@@ -49,7 +49,7 @@ describe Puppet::Parser::AST::ASTArray do
operator.evaluate(@scope).should == [123]
end
- it "should flatten the results of children evaluation" do
+ it "should not flatten the results of children evaluation" do
item1 = stub "item1", :is_a? => true
item2 = stub "item2"
item2.stubs(:is_a?).with(Puppet::Parser::AST).returns(true)
@@ -59,7 +59,7 @@ describe Puppet::Parser::AST::ASTArray do
item1.expects(:safeevaluate).with(@scope).returns([123])
operator = Puppet::Parser::AST::ASTArray.new :children => [item2]
- operator.evaluate(@scope).should == [123]
+ operator.evaluate(@scope).should == [[123]]
end
diff --git a/spec/unit/parser/ast/resource.rb b/spec/unit/parser/ast/resource.rb
new file mode 100755
index 000000000..b257cb116
--- /dev/null
+++ b/spec/unit/parser/ast/resource.rb
@@ -0,0 +1,103 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+describe Puppet::Parser::AST::Resource do
+ ast = Puppet::Parser::AST
+
+ before :each do
+ @title = stub_everything 'title'
+ @compiler = stub_everything 'compiler'
+ @scope = Puppet::Parser::Scope.new(:compiler => @compiler)
+ @param1 = stub_everything 'parameter', :is_a? => true
+ @scope.stubs(:resource).returns(stub_everything)
+ @params = ast::ASTArray.new( :children => [@param1])
+ @resource = ast::Resource.new(:title => @title, :type => "Resource", :params => @params )
+ @resource.stubs(:qualified_type).returns("Resource")
+ Puppet::Parser::Resource.stubs(:new).returns(stub_everything)
+ end
+
+ it "should evaluate all its parameters" do
+ @param1.expects(:safeevaluate).with(@scope)
+
+ @resource.evaluate(@scope)
+ end
+
+ it "should evaluate its title" do
+
+ @title.expects(:safeevaluate).with(@scope)
+
+ @resource.evaluate(@scope)
+ end
+
+ it "should flatten the titles array" do
+ titles = stub 'titles'
+ title_array = stub 'title_array', :is_a? => true
+
+ titles.stubs(:safeevaluate).with(@scope).returns(title_array)
+
+ title_array.expects(:flatten).returns([])
+
+ @resource.title = titles
+ @resource.evaluate(@scope)
+ end
+
+ it "should create one resource objects per title" do
+ titles = stub 'titles'
+ title_array = stub 'title_array', :is_a? => true
+
+ title_array.stubs(:flatten).returns([@title])
+ titles.stubs(:safeevaluate).with(@scope).returns(title_array)
+
+ Puppet::Parser::Resource.expects(:new).with { |hash| hash[:title] == @title }
+
+ @resource.title = titles
+ @resource.evaluate(@scope)
+ end
+
+ it "should handover resources to the compiler" do
+ resource = stub 'resource'
+ titles = stub 'titles'
+ title_array = stub 'title_array', :is_a? => true
+
+ title_array.stubs(:flatten).returns([@title])
+ titles.stubs(:safeevaluate).with(@scope).returns(title_array)
+ Puppet::Parser::Resource.stubs(:new).returns(resource)
+
+ @compiler.expects(:add_resource).with(@scope, resource)
+
+ @resource.title = titles
+ @resource.evaluate(@scope)
+ end
+
+ it "should return the newly created resources" do
+ resource = stub 'resource'
+ titles = stub 'titles'
+ title_array = stub 'title_array', :is_a? => true
+
+ title_array.stubs(:flatten).returns([@title])
+ titles.stubs(:safeevaluate).with(@scope).returns(title_array)
+ Puppet::Parser::Resource.stubs(:new).returns(resource)
+
+ @compiler.stubs(:add_resource).with(resource)
+
+ @resource.title = titles
+ @resource.evaluate(@scope).should == [resource]
+ end
+
+ it "should generate virtual resources if it is virtual" do
+ @resource.virtual = true
+
+ Puppet::Parser::Resource.expects(:new).with { |hash| hash[:virtual] == true }
+
+ @resource.evaluate(@scope)
+ end
+
+ it "should generate virtual and exported resources if it is exported" do
+ @resource.exported = true
+
+ Puppet::Parser::Resource.expects(:new).with { |hash| hash[:virtual] == true and hash[:exported] == true }
+
+ @resource.evaluate(@scope)
+ end
+end
diff --git a/spec/unit/parser/collector.rb b/spec/unit/parser/collector.rb
index edd74e25f..f92b881c8 100755
--- a/spec/unit/parser/collector.rb
+++ b/spec/unit/parser/collector.rb
@@ -240,10 +240,10 @@ describe Puppet::Parser::Collector, "when collecting exported resources" do
one = stub 'one', :type => "Mytype", :virtual? => true, :exported? => true
two = stub 'two', :type => "Mytype", :virtual? => true, :exported? => true
- one.expects(:exported=).with(false)
- one.expects(:virtual=).with(false)
- two.expects(:exported=).with(false)
- two.expects(:virtual=).with(false)
+ one.stubs(:exported=)
+ one.stubs(:virtual=)
+ two.stubs(:exported=)
+ two.stubs(:virtual=)
@compiler.expects(:resources).returns([one, two])
diff --git a/spec/unit/parser/functions/realize.rb b/spec/unit/parser/functions/realize.rb
new file mode 100755
index 000000000..d9c94b143
--- /dev/null
+++ b/spec/unit/parser/functions/realize.rb
@@ -0,0 +1,51 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+describe "the realize function" do
+
+ before :each do
+ @collector = stub_everything 'collector'
+ @scope = Puppet::Parser::Scope.new()
+ @compiler = stub 'compiler'
+ @compiler.stubs(:add_collection).with(@collector)
+ @scope.stubs(:compiler).returns(@compiler)
+ end
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("realize").should == "function_realize"
+ end
+
+ it "should create a Collector when called" do
+
+ Puppet::Parser::Collector.expects(:new).returns(@collector)
+
+ @scope.function_realize("test")
+ end
+
+ it "should assign the passed-in resources to the collector" do
+ Puppet::Parser::Collector.stubs(:new).returns(@collector)
+
+ @collector.expects(:resources=).with(["test"])
+
+ @scope.function_realize("test")
+ end
+
+ it "should flatten the resources assigned to the collector" do
+ Puppet::Parser::Collector.stubs(:new).returns(@collector)
+
+ @collector.expects(:resources=).with(["test"])
+
+ @scope.function_realize([["test"]])
+ end
+
+ it "should let the compiler know this collector" do
+ Puppet::Parser::Collector.stubs(:new).returns(@collector)
+ @collector.stubs(:resources=).with(["test"])
+
+ @compiler.expects(:add_collection).with(@collector)
+
+ @scope.function_realize("test")
+ end
+
+end
diff --git a/spec/unit/provider/naginator.rb b/spec/unit/provider/naginator.rb
new file mode 100644
index 000000000..d0d43aa4b
--- /dev/null
+++ b/spec/unit/provider/naginator.rb
@@ -0,0 +1,58 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+require 'puppet/provider/naginator'
+
+describe Puppet::Provider::Naginator do
+ before do
+ @resource_type = stub 'resource_type', :name => :nagios_test
+ @class = Class.new(Puppet::Provider::Naginator)
+
+ @class.stubs(:resource_type).returns @resource_type
+ end
+
+ it "should be able to look up the associated Nagios type" do
+ nagios_type = mock "nagios_type"
+ nagios_type.stubs :attr_accessor
+ Nagios::Base.expects(:type).with(:test).returns nagios_type
+
+ @class.nagios_type.should equal(nagios_type)
+ end
+
+ it "should use the Nagios type to determine whether an attribute is valid" do
+ nagios_type = mock "nagios_type"
+ nagios_type.stubs :attr_accessor
+ Nagios::Base.expects(:type).with(:test).returns nagios_type
+
+ nagios_type.expects(:parameters).returns [:foo, :bar]
+
+ @class.valid_attr?(:test, :foo).should be_true
+ end
+
+ it "should use Naginator to parse configuration snippets" do
+ parser = mock 'parser'
+ parser.expects(:parse).with("my text").returns "my instances"
+ Nagios::Parser.expects(:new).returns(parser)
+
+ @class.parse("my text").should == "my instances"
+ end
+
+ it "should join Nagios::Base records with '\\n' when asked to convert them to text" do
+ @class.expects(:header).returns "myheader\n"
+
+ @class.to_file([:one, :two]).should == "myheader\none\ntwo"
+ end
+
+ it "should be able to prefetch instance from configuration files" do
+ @class.should respond_to(:prefetch)
+ end
+
+ it "should be able to generate a list of instances" do
+ @class.should respond_to(:instances)
+ end
+
+ it "should never skip records" do
+ @class.should_not be_skip_record("foo")
+ end
+end
diff --git a/spec/unit/provider/parsedfile.rb b/spec/unit/provider/parsedfile.rb
new file mode 100755
index 000000000..05e9de3ab
--- /dev/null
+++ b/spec/unit/provider/parsedfile.rb
@@ -0,0 +1,50 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+require 'puppet/provider/parsedfile'
+
+# Most of the tests for this are still in test/ral/provider/parsedfile.rb.
+describe Puppet::Provider::ParsedFile do
+ before do
+ @class = Class.new(Puppet::Provider::ParsedFile)
+ end
+
+ describe "when looking up records loaded from disk" do
+ it "should return nil if no records have been loaded" do
+ @class.record?("foo").should be_nil
+ end
+ end
+
+ describe "when generating a list of instances" do
+ it "should return an instance for each record parsed from all of the registered targets" do
+ @class.expects(:targets).returns %w{/one /two}
+ @class.stubs(:skip_record?).returns false
+ one = [:uno1, :uno2]
+ two = [:dos1, :dos2]
+ @class.expects(:prefetch_target).with("/one").returns one
+ @class.expects(:prefetch_target).with("/two").returns two
+
+ results = []
+ (one + two).each do |inst|
+ results << inst.to_s + "_instance"
+ @class.expects(:new).with(inst).returns(results[-1])
+ end
+
+ @class.instances.should == results
+ end
+
+ it "should skip specified records" do
+ @class.expects(:targets).returns %w{/one}
+ @class.expects(:skip_record?).with(:uno).returns false
+ @class.expects(:skip_record?).with(:dos).returns true
+ one = [:uno, :dos]
+ @class.expects(:prefetch_target).returns one
+
+ @class.expects(:new).with(:uno).returns "eh"
+ @class.expects(:new).with(:dos).never
+
+ @class.instances
+ end
+ end
+end
diff --git a/spec/unit/transaction.rb b/spec/unit/transaction.rb
index 2aa0df37b..554d20ce9 100755
--- a/spec/unit/transaction.rb
+++ b/spec/unit/transaction.rb
@@ -1,212 +1,33 @@
-#!/usr/bin/env ruby"
+#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../spec_helper'
require 'puppet/transaction'
-describe Puppet::Transaction do
+describe Puppet::Transaction, " when determining tags" do
before do
- @generator_class = mkgenerator
- @generator = mkgenerator.new(:name => "foo")
-
- @catalog = Puppet::Resource::Catalog.new
- @catalog.add_resource @generator
-
- @report = stub_everything 'report'
- Puppet::Transaction::Report.stubs(:new).returns(@report)
-
- @transaction = Puppet::Transaction.new(@catalog)
+ @config = Puppet::Resource::Catalog.new
+ @transaction = Puppet::Transaction.new(@config)
end
- after do
- Puppet::Type.rmtype(:generator)
+ it "should default to the tags specified in the :tags setting" do
+ Puppet.expects(:[]).with(:tags).returns("one")
+ @transaction.tags.should == %w{one}
end
- describe "when generating resources" do
-
- it "should call the generate() method on all resources" do
- @generator.expects(:generate)
- @transaction.generate
- end
-
- it "should add all generated resources to the catalog" do
- one = @generator_class.new :name => "one"
- two = @generator_class.new :name => "two"
- @generator.expects(:generate).returns [one, two]
- @transaction.generate
-
- @catalog.resource(:generator, "one").should equal(one)
- @catalog.resource(:generator, "two").should equal(two)
- end
-
- it "should generate and add resources from the generated resources" do
- one = @generator_class.new :name => "one"
- two = @generator_class.new :name => "two"
- @generator.expects(:generate).returns [one]
- one.expects(:generate).returns [two]
- @transaction.generate
-
- @catalog.resource(:generator, "two").should equal(two)
- end
-
- it "should add an edge in the relationship graph between the generating and generated resource" do
- one = @generator_class.new :name => "one"
- two = @generator_class.new :name => "two"
- @generator.expects(:generate).returns [one]
- one.expects(:generate).returns [two]
- @transaction.generate
-
- @catalog.relationship_graph.should be_edge(@generator, one)
- @catalog.relationship_graph.should be_edge(one, two)
- end
-
- it "should finish all non-conflicting resources" do
- one = @generator_class.new :name => "one"
- one.expects(:finish)
- @generator.expects(:generate).returns [one]
- @transaction.generate
- end
-
- describe "mid-transaction" do
- it "should call the eval_generate() method on the resource" do
- @generator.expects(:eval_generate)
- @transaction.eval_generate(@generator)
- end
-
- it "should add all generated resources to the catalog" do
- one = @generator_class.new :name => "one"
- two = @generator_class.new :name => "two"
- @generator.expects(:eval_generate).returns [one, two]
- @transaction.eval_generate(@generator)
-
- @catalog.resource(:generator, "one").should equal(one)
- @catalog.resource(:generator, "two").should equal(two)
- end
-
- it "should add an edge in the relationship graph between the generating and generated resource" do
- one = @generator_class.new :name => "one"
- @generator.expects(:eval_generate).returns [one]
- @transaction.eval_generate(@generator)
-
- @catalog.relationship_graph.should be_edge(@generator, one)
- end
-
- it "should not recursively eval_generate resources" do
- one = @generator_class.new :name => "one"
- two = @generator_class.new :name => "two"
- @generator.expects(:eval_generate).returns [one]
- one.expects(:eval_generate).never
- @transaction.eval_generate(@generator)
- end
-
- it "should finish all non-conflicting resources" do
- one = @generator_class.new :name => "one"
- one.expects(:finish)
- @generator.expects(:eval_generate).returns [one]
- @transaction.eval_generate(@generator)
- end
- end
-
+ it "should split tags based on ','" do
+ Puppet.expects(:[]).with(:tags).returns("one,two")
+ @transaction.tags.should == %w{one two}
end
- describe "when generating a report" do
-
- before :each do
- Puppet.stubs(:[]).with(:report).returns(true)
- end
-
- it "should create a Puppet::Transaction::Report when the Transaction is created" do
- Puppet::Transaction::Report.expects(:new).returns(@report)
-
- Puppet::Transaction.new(@catalog)
- end
-
- it "should return a Puppet::Transaction::Report" do
- @transaction.generate_report.should == @report
- end
-
- it "should have a metric for resources" do
- @report.expects(:newmetric).with { |metric,hash| metric == :resources }
-
- @transaction.generate_report
- end
-
- it "should have a metric for time" do
- @report.expects(:newmetric).with { |metric,hash| metric == :time }
-
- @transaction.generate_report
- end
-
- it "should have a metric for changes" do
- @report.expects(:newmetric).with { |metric,hash| metric == :changes }
-
- @transaction.generate_report
- end
-
- it "should store the current time" do
- now = stub 'time'
- Time.stubs(:now).returns(now)
-
- @report.expects(:time=).with(now)
-
- @transaction.generate_report
- end
-
- end
-
- describe "when sending a report" do
-
- before :each do
- @transaction.stubs(:generate_report).returns(@report)
- Puppet.stubs(:[]).with(:report).returns(true)
- Puppet.stubs(:[]).with(:rrdgraph).returns(false)
- Puppet.stubs(:[]).with(:summarize).returns(false)
- end
-
- it "should ask the transaction for a report" do
- @transaction.expects(:generate_report)
-
- @transaction.send_report
- end
-
- it "should ask the report for a graph if rrdgraph is enable" do
- Puppet.stubs(:[]).with(:rrdgraph).returns(true)
-
- @report.expects(:graph)
-
- @transaction.send_report
- end
-
-
- it "should call report.save" do
- @report.expects(:save)
-
- @transaction.send_report
- end
-
+ it "should use any tags set after creation" do
+ Puppet.expects(:[]).with(:tags).never
+ @transaction.tags = %w{one two}
+ @transaction.tags.should == %w{one two}
end
- def mkgenerator
- # Create a bogus type that generates new instances with shorter names
- type = Puppet::Type.newtype(:generator) do
- newparam(:name, :namevar => true)
-
- # Stub methods.
- def generate
- end
-
- def eval_generate
- end
-
- def finished?
- @finished
- end
-
- def finish
- @finished = true
- end
- end
-
- return type
+ it "should always convert assigned tags to an array" do
+ @transaction.tags = "one::two"
+ @transaction.tags.should == %w{one::two}
end
end
diff --git a/spec/unit/type/file/selinux.rb b/spec/unit/type/file/selinux.rb
index c81270ab0..bf3315bf9 100644
--- a/spec/unit/type/file/selinux.rb
+++ b/spec/unit/type/file/selinux.rb
@@ -73,6 +73,12 @@ Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f
@sel.expects(:set_selinux_context).with("/my/file", ["newone"], param)
@sel.sync
end
+
+ it "should do nothing for insync? if no SELinux support" do
+ @sel.should = %{newcontext}
+ @sel.expects(:selinux_support?).returns false
+ @sel.insync?("oldcontext").should == true
+ end
end
end
diff --git a/spec/unit/type/user.rb b/spec/unit/type/user.rb
index 5d84591da..2e8616ce8 100755
--- a/spec/unit/type/user.rb
+++ b/spec/unit/type/user.rb
@@ -38,6 +38,10 @@ describe user do
it "should have a valid provider" do
user.new(:name => "foo").provider.class.ancestors.should be_include(Puppet::Provider)
end
+
+ it "should fail if a ':' is included in the password" do
+ lambda { user.create(:name => "foo", :password => 'some:thing') }.should raise_error(Puppet::Error)
+ end
end
properties = [:ensure, :uid, :gid, :home, :comment, :shell, :password, :groups, :roles, :auths, :profiles, :project, :keys]
@@ -179,6 +183,12 @@ describe user do
@gid = user.attrclass(:gid).new(:resource => @resource, :should => %w{foo bar})
end
+ it "should return true if no 'should' values are set" do
+ @gid = user.attrclass(:gid).new(:resource => @resource)
+
+ @gid.must be_insync(500)
+ end
+
it "should return true if any of the specified groups are equal to the current integer" do
Puppet::Util.expects(:gid).with("foo").returns 300
Puppet::Util.expects(:gid).with("bar").returns 500
diff --git a/spec/unit/util/nagios_maker.rb b/spec/unit/util/nagios_maker.rb
index b75439400..1e1aefcae 100755
--- a/spec/unit/util/nagios_maker.rb
+++ b/spec/unit/util/nagios_maker.rb
@@ -13,6 +13,9 @@ describe Puppet::Util::NagiosMaker do
@nagtype = stub 'nagios type', :parameters => [], :namevar => :name
Nagios::Base.stubs(:type).with(:test).returns(@nagtype)
+
+ @provider = stub 'provider', :nagios_type => nil
+ @type = stub 'type', :newparam => nil, :newproperty => nil, :provide => @provider, :desc => nil, :ensurable => nil
end
it "should be able to create a new nagios type" do
@@ -26,73 +29,59 @@ describe Puppet::Util::NagiosMaker do
end
it "should create a new RAL type with the provided name prefixed with 'nagios_'" do
- type = stub 'type', :newparam => nil, :newproperty => nil, :ensurable => nil, :provide => nil, :desc => nil
-
- Puppet::Type.expects(:newtype).with(:nagios_test).returns(type)
+ Puppet::Type.expects(:newtype).with(:nagios_test).returns(@type)
@module.create_nagios_type(:test)
end
it "should mark the created type as ensurable" do
- type = stub 'type', :newparam => nil, :newproperty => nil, :provide => nil, :desc => nil
+ @type.expects(:ensurable)
- type.expects(:ensurable)
-
- Puppet::Type.expects(:newtype).with(:nagios_test).returns(type)
+ Puppet::Type.expects(:newtype).with(:nagios_test).returns(@type)
@module.create_nagios_type(:test)
end
it "should create a namevar parameter for the nagios type's name parameter" do
- type = stub 'type', :newproperty => nil, :ensurable => nil, :provide => nil, :desc => nil
-
- type.expects(:newparam).with(:name, :namevar => true)
+ @type.expects(:newparam).with(:name, :namevar => true)
- Puppet::Type.expects(:newtype).with(:nagios_test).returns(type)
+ Puppet::Type.expects(:newtype).with(:nagios_test).returns(@type)
@module.create_nagios_type(:test)
end
it "should create a property for all non-namevar parameters" do
- type = stub 'type', :newparam => nil, :ensurable => nil, :provide => nil, :desc => nil
-
@nagtype.stubs(:parameters).returns([:one, :two])
- type.expects(:newproperty).with(:one)
- type.expects(:newproperty).with(:two)
- type.expects(:newproperty).with(:target)
+ @type.expects(:newproperty).with(:one)
+ @type.expects(:newproperty).with(:two)
+ @type.expects(:newproperty).with(:target)
- Puppet::Type.expects(:newtype).with(:nagios_test).returns(type)
+ Puppet::Type.expects(:newtype).with(:nagios_test).returns(@type)
@module.create_nagios_type(:test)
end
it "should skip parameters that start with integers" do
- type = stub 'type', :newparam => nil, :ensurable => nil, :provide => nil, :desc => nil
-
@nagtype.stubs(:parameters).returns(["2dcoords".to_sym, :other])
- type.expects(:newproperty).with(:other)
- type.expects(:newproperty).with(:target)
+ @type.expects(:newproperty).with(:other)
+ @type.expects(:newproperty).with(:target)
- Puppet::Type.expects(:newtype).with(:nagios_test).returns(type)
+ Puppet::Type.expects(:newtype).with(:nagios_test).returns(@type)
@module.create_nagios_type(:test)
end
it "should deduplicate the parameter list" do
- type = stub 'type', :newparam => nil, :ensurable => nil, :provide => nil, :desc => nil
-
@nagtype.stubs(:parameters).returns([:one, :one])
- type.expects(:newproperty).with(:one)
- type.expects(:newproperty).with(:target)
+ @type.expects(:newproperty).with(:one)
+ @type.expects(:newproperty).with(:target)
- Puppet::Type.expects(:newtype).with(:nagios_test).returns(type)
+ Puppet::Type.expects(:newtype).with(:nagios_test).returns(@type)
@module.create_nagios_type(:test)
end
it "should create a target property" do
- type = stub 'type', :newparam => nil, :ensurable => nil, :provide => nil, :desc => nil
+ @type.expects(:newproperty).with(:target)
- type.expects(:newproperty).with(:target)
-
- Puppet::Type.expects(:newtype).with(:nagios_test).returns(type)
+ Puppet::Type.expects(:newtype).with(:nagios_test).returns(@type)
@module.create_nagios_type(:test)
end
end
@@ -100,6 +89,7 @@ end
describe Puppet::Util::NagiosMaker, " when creating the naginator provider" do
before do
@module = Puppet::Util::NagiosMaker
+ @provider = stub 'provider', :nagios_type => nil
@nagtype = stub 'nagios type', :parameters => [], :namevar => :name
Nagios::Base.stubs(:type).with(:test).returns(@nagtype)
@@ -109,19 +99,27 @@ describe Puppet::Util::NagiosMaker, " when creating the naginator provider" do
end
it "should add a naginator provider" do
- @type.expects(:provide).with { |name, options| name == :naginator }
+ @type.expects(:provide).with { |name, options| name == :naginator }.returns @provider
@module.create_nagios_type(:test)
end
it "should set Puppet::Provider::Naginator as the parent class of the provider" do
- @type.expects(:provide).with { |name, options| options[:parent] == Puppet::Provider::Naginator }
+ @type.expects(:provide).with { |name, options| options[:parent] == Puppet::Provider::Naginator }.returns @provider
@module.create_nagios_type(:test)
end
it "should use /etc/nagios/$name.cfg as the default target" do
- @type.expects(:provide).with { |name, options| options[:default_target] == "/etc/nagios/nagios_test.cfg" }
+ @type.expects(:provide).with { |name, options| options[:default_target] == "/etc/nagios/nagios_test.cfg" }.returns @provider
+
+ @module.create_nagios_type(:test)
+ end
+
+ it "should trigger the lookup of the Nagios class" do
+ @type.expects(:provide).returns @provider
+
+ @provider.expects(:nagios_type)
@module.create_nagios_type(:test)
end