diff options
| author | Luke Kanies <luke@madstop.com> | 2007-12-31 14:37:03 -0600 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2007-12-31 14:37:03 -0600 |
| commit | 33e319a8be8e35fbe4a9ecb7e3185453b8239a83 (patch) | |
| tree | 15cb3788a9a3c783463e2cc129a7cf03c77498a0 /spec/unit | |
| parent | 68cde4f1babe3ebf61ffe215c6328faf7818d40f (diff) | |
| download | puppet-33e319a8be8e35fbe4a9ecb7e3185453b8239a83.tar.gz puppet-33e319a8be8e35fbe4a9ecb7e3185453b8239a83.tar.xz puppet-33e319a8be8e35fbe4a9ecb7e3185453b8239a83.zip | |
Added builtin support for all Nagios resource types.
I use Naginator to parse and generate the files, with
ParsedFile to handle record management and the like.
Note that each resource type itself is just a call to
a Factory method, since everything is just based on Naginator.
Given that, all of the tests are in a single unit/ral/types/nagios.rb
file, since I used a factory to generate them, too. This is probably
either unnecessary or insufficient, but it's as far as I'm
willing to go in testing them, and it did actually catch a few
bugs.
Diffstat (limited to 'spec/unit')
| -rwxr-xr-x | spec/unit/ral/types/nagios.rb | 55 | ||||
| -rwxr-xr-x | spec/unit/util/nagios_maker.rb | 24 |
2 files changed, 79 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 index 145f8633a..0454b6503 100755 --- a/spec/unit/util/nagios_maker.rb +++ b/spec/unit/util/nagios_maker.rb @@ -63,6 +63,30 @@ describe Puppet::Util::NagiosMaker do @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 |
