summaryrefslogtreecommitdiffstats
path: root/test/puppet/defaults.rb
blob: 2557140e6e7e69fc106bf025ac3bd63f86fdf219 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
if __FILE__ == $0
    $:.unshift '..'
    $:.unshift '../../lib'
    $puppetbase = ".."
end

require 'puppet'
require 'puppettest'
require 'test/unit'

# $Id$

class TestPuppetDefaults < Test::Unit::TestCase
    include TestPuppet
    @@dirs = %w{rrddir confdir vardir logdir statedir}
    @@files = %w{statefile manifest masterlog}
    @@normals = %w{puppetport masterport server}
    @@booleans = %w{rrdgraph noop}

    def testVersion
        assert( Puppet.version =~ /^[0-9]+(\.[0-9]+)*$/ )
    end

    def testStringOrParam
        [@@dirs,@@files,@@booleans].flatten.each { |param|
            assert_nothing_raised { Puppet[param] }
            assert_nothing_raised { Puppet[param.intern] }
        }
    end

    def test_valuesForEach
        [@@dirs,@@files,@@booleans].flatten.each { |param|
            param = param.intern
            assert_nothing_raised { Puppet[param] }
        }
    end

    def testValuesForEach
        [@@dirs,@@files,@@booleans].flatten.each { |param|
            assert_nothing_raised { Puppet[param] }
        }
    end

    if __FILE__ == $0
        def disabled_testContained
            confdir = Regexp.new(Puppet[:confdir])
            vardir = Regexp.new(Puppet[:vardir])
            [@@dirs,@@files].flatten.each { |param|
                value = Puppet[param]

                unless value =~ confdir or value =~ vardir
                    assert_nothing_raised { raise "%s is in wrong dir: %s" %
                        [param,value] }
                end
            }
        end
    end

    def testArgumentTypes
        assert_raise(ArgumentError) { Puppet[["string"]] }
        assert_raise(ArgumentError) { Puppet[[:symbol]] }
    end

    def testFailOnBogusArgs
        [0, "ashoweklj", ";"].each { |param|
            assert_raise(ArgumentError, "No error on %s" % param) { Puppet[param] }
        }
    end

    # we don't want user defaults in /, or root defaults in ~
    def testDefaultsInCorrectRoots
        notval = nil
        if Process.uid == 0
            notval = Regexp.new(File.expand_path("~"))
        else
            notval = /^\/var|^\/etc/
        end
        [@@dirs,@@files].flatten.each { |param|
            value = Puppet[param]

            unless value !~ notval
                assert_nothing_raised { raise "%s is incorrectly set to %s" %
                    [param,value] }
            end
        }
    end

    def test_settingdefaults
        testvals = {
            :fakeparam => "$confdir/yaytest",
            :anotherparam => "$vardir/goodtest",
            :string => "a yay string",
            :boolean => true
        }

        testvals.each { |param, default|
            assert_nothing_raised {
                Puppet.setdefaults("testing", param => [default, "a value"])
            }
        }
    end
end