summaryrefslogtreecommitdiffstats
path: root/spec/unit
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-12-31 15:12:12 -0600
committerLuke Kanies <luke@madstop.com>2007-12-31 15:12:12 -0600
commit1dfcb63e0f9de1fd2f15c98ee9a6f242e3fb9325 (patch)
tree2a68cf9ed5718789b69f8fdadbffc39f382d5421 /spec/unit
parent4e8bc40ad7a9c128e778dbafda6dadbade215c94 (diff)
parent33e319a8be8e35fbe4a9ecb7e3185453b8239a83 (diff)
downloadpuppet-1dfcb63e0f9de1fd2f15c98ee9a6f242e3fb9325.tar.gz
puppet-1dfcb63e0f9de1fd2f15c98ee9a6f242e3fb9325.tar.xz
puppet-1dfcb63e0f9de1fd2f15c98ee9a6f242e3fb9325.zip
Merge branch 'nagios' into 0.24.x
Diffstat (limited to 'spec/unit')
-rwxr-xr-xspec/unit/ral/types/nagios.rb55
-rwxr-xr-xspec/unit/util/nagios_maker.rb128
2 files changed, 183 insertions, 0 deletions
diff --git a/spec/unit/ral/types/nagios.rb b/spec/unit/ral/types/nagios.rb
new file mode 100755
index 000000000..8aca7d401
--- /dev/null
+++ b/spec/unit/ral/types/nagios.rb
@@ -0,0 +1,55 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+require 'puppet/external/nagios'
+
+Nagios::Base.eachtype do |name, nagios_type|
+ puppet_type = Puppet::Type.type("nagios_" + name.to_s)
+
+ describe puppet_type do
+ it "should be defined as a Puppet resource type" do
+ puppet_type.should_not be_nil
+ end
+
+ it "should have documentation" do
+ puppet_type.instance_variable_get("@doc").should_not == ""
+ end
+
+ it "should have %s as its namevar" % nagios_type.namevar do
+ puppet_type.namevar.should == nagios_type.namevar
+ end
+
+ it "should have documentation for its %s parameter" % nagios_type.namevar do
+ puppet_type.attrclass(nagios_type.namevar).instance_variable_get("@doc").should_not be_nil
+ end
+
+ it "should have an ensure property" do
+ puppet_type.should be_validproperty(:ensure)
+ end
+
+ it "should have a target property" do
+ puppet_type.should be_validproperty(:target)
+ end
+
+ it "should have documentation for its target property" do
+ puppet_type.attrclass(:target).instance_variable_get("@doc").should_not be_nil
+ end
+
+ nagios_type.parameters.reject { |param| param == nagios_type.namevar or param.to_s =~ /^[0-9]/ }.each do |param|
+ it "should have a %s property" % param do
+ puppet_type.should be_validproperty(param)
+ end
+
+ it "should have documentation for its %s property" % param do
+ puppet_type.attrclass(param).instance_variable_get("@doc").should_not be_nil
+ end
+ end
+
+ nagios_type.parameters.find_all { |param| param.to_s =~ /^[0-9]/ }.each do |param|
+ it "should have not have a %s property" % param do
+ puppet_type.should_not be_validproperty(:param)
+ end
+ end
+ end
+end
diff --git a/spec/unit/util/nagios_maker.rb b/spec/unit/util/nagios_maker.rb
new file mode 100755
index 000000000..0454b6503
--- /dev/null
+++ b/spec/unit/util/nagios_maker.rb
@@ -0,0 +1,128 @@
+#!/usr/bin/env ruby
+#
+# Created by Luke Kanies on 2007-11-18.
+# Copyright (c) 2007. All rights reserved.
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+require 'puppet/util/nagios_maker'
+
+describe Puppet::Util::NagiosMaker do
+ before do
+ @module = Puppet::Util::NagiosMaker
+
+ @nagtype = stub 'nagios type', :parameters => [], :namevar => :name
+ Nagios::Base.stubs(:type).with(:test).returns(@nagtype)
+ end
+
+ it "should be able to create a new nagios type" do
+ @module.should respond_to(:create_nagios_type)
+ end
+
+ it "should fail if it cannot find the named Naginator type" do
+ Nagios::Base.stubs(:type).returns(nil)
+
+ lambda { @module.create_nagios_type(:no_such_type) }.should raise_error(Puppet::DevError)
+ 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
+
+ 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
+
+ type.expects(:ensurable)
+
+ 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
+
+ type.expects(:newparam).with(:name, :namevar => true)
+
+ 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
+
+ @nagtype.stubs(:parameters).returns([:one, :two])
+
+ type.expects(:newproperty).with(:one)
+ type.expects(:newproperty).with(:two)
+ type.expects(:newproperty).with(:target)
+
+ 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
+
+ @nagtype.stubs(:parameters).returns(["2dcoords".to_sym, :other])
+
+ type.expects(:newproperty).with(:other)
+ type.expects(:newproperty).with(:target)
+
+ 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
+
+ @nagtype.stubs(:parameters).returns([:one, :one])
+
+ type.expects(:newproperty).with(:one)
+ type.expects(:newproperty).with(:target)
+
+ 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
+
+ type.expects(:newproperty).with(:target)
+
+ Puppet::Type.expects(:newtype).with(:nagios_test).returns(type)
+ @module.create_nagios_type(:test)
+ end
+end
+
+describe Puppet::Util::NagiosMaker, " when creating the naginator provider" do
+ before do
+ @module = Puppet::Util::NagiosMaker
+
+ @nagtype = stub 'nagios type', :parameters => [], :namevar => :name
+ Nagios::Base.stubs(:type).with(:test).returns(@nagtype)
+
+ @type = stub 'type', :newparam => nil, :ensurable => nil, :newproperty => nil
+ Puppet::Type.stubs(:newtype).with(:nagios_test).returns(@type)
+ end
+
+ it "should add a naginator provider" do
+ @type.expects(:provide).with { |name, options| name == :naginator }
+
+ @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 }
+
+ @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" }
+
+ @module.create_nagios_type(:test)
+ end
+end