summaryrefslogtreecommitdiffstats
path: root/spec/unit/type/nagios_spec.rb
blob: 2c26d3a7763da6fafbffe4cbdd782ec9943f192e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env ruby

require File.dirname(__FILE__) + '/../../spec_helper'

require 'puppet/external/nagios'

describe "Nagios resource types" do
    Nagios::Base.eachtype do |name, nagios_type|
        puppet_type = Puppet::Type.type("nagios_" + name.to_s)

        it "should have a valid type for #{name}" do
            puppet_type.should_not be_nil
        end

        next unless puppet_type

        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 key attribute" % nagios_type.namevar do
                puppet_type.key_attributes.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
end