summaryrefslogtreecommitdiffstats
path: root/test/puppet/tc_defaults.rb
blob: e1d0124d243c6f79f81c9dc79a3d1e9c65cec6e5 (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
if __FILE__ == $0
    $:.unshift '..'
    $:.unshift '../../lib'
    $puppetbase = ".."
end

require 'puppet'
require 'test/unit'

# $Id$

class TestPuppetDefaults < Test::Unit::TestCase
    @@dirs = %w{rrddir puppetconf puppetvar logdir statedir}
    @@files = %w{logfile checksumfile 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[:puppetconf])
            vardir = Regexp.new(Puppet[:puppetvar])
            [@@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", ";", :thisisafakesymbol].each { |param|
            assert_raise(ArgumentError) { 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 in wrong dir: %s" %
                    [param,value] }
            end
        }
    end

    def test_settingdefaults
        testvals = {
            :fakeparam => [:puppetconf, "yaytest"],
            :anotherparam => proc { File.join(Puppet[:puppetvar], "goodtest") },
            :string => "a yay string",
            :boolean => true
        }

        testvals.each { |param, default|
            assert_nothing_raised {
                Puppet.setdefault(param,default)
            }
        }
    end
end