File: parameter.rb

package info (click to toggle)
puppet 0.20.1-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,072 kB
  • ctags: 3,365
  • sloc: ruby: 47,009; sh: 496; lisp: 143; xml: 122; makefile: 67
file content (104 lines) | stat: -rwxr-xr-x 2,228 bytes parent folder | download
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
103
104
#!/usr/bin/env ruby

$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/

require 'puppet/type'
require 'puppettest'

class TestParameter < Test::Unit::TestCase
	include PuppetTest
    
    def newparam(name = :fakeparam)
        assert_nothing_raised {
            param = Class.new(Puppet::Parameter) do
                @name = :fakeparam
            end
            param.initvars

            return param
        }
    end

    def newinst(param)
        assert_nothing_raised {
            return param.new
        }
    end

    # Test the basic newvalue stuff.
    def test_newvalue
        param = newparam()

        # Try it with both symbols and strings.
        assert_nothing_raised {
            param.newvalues(:one, "two")
        }

        inst = newinst(param)

        assert_nothing_raised {
            inst.value = "one"
        }

        assert_equal(:one, inst.value)

        assert_nothing_raised {
            inst.value = :two
        }
        assert_equal(:two, inst.value)

        assert_raise(ArgumentError) {
            inst.value = :three
        }
        assert_equal(:two, inst.value)
    end

    # Test using regexes.
    def test_regexvalues
        param = newparam

        assert_nothing_raised {
            param.newvalues(/^\d+$/)
        }
        assert(param.match?("14"))
        assert(param.match?(14))

        inst = newinst(param)

        assert_nothing_raised {
            inst.value = 14
        }

        assert_nothing_raised {
            inst.value = "14"
        }

        assert_raise(ArgumentError) {
            inst.value = "a14"
        }
    end

    # Test using both.  Equality should beat matching.
    def test_regexesandnormals
        param = newparam

        assert_nothing_raised {
            param.newvalues(:one, /^\w+$/)
        }

        inst = newinst(param)

        assert_nothing_raised {
            inst.value = "one"
        }

        assert_equal(:one, inst.value, "Value used regex instead of equality")

        assert_nothing_raised {
            inst.value = "two"
        }
        assert_equal("two", inst.value, "Matched value didn't take")
    end
end

# $Id: parameter.rb 1793 2006-10-16 22:01:40Z luke $