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
105
106
107
|
#!/usr/bin/env ruby
$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/
require 'puppettest'
class TestConfFiles < Test::Unit::TestCase
include PuppetTest
@@gooddata = [
{
"fun" => {
"a" => "b",
"c" => "d",
"e" => "f"
},
"yay" => {
"aa" => "bk",
"ca" => "dk",
"ea" => "fk"
},
"boo" => {
"eb" => "fb"
},
},
{
"puppet" => {
"yay" => "rah"
},
"booh" => {
"okay" => "rah"
},
"back" => {
"yayness" => "rah"
},
}
]
def data2config(data)
str = ""
if data.include?("puppet")
# because we're modifying it
data = data.dup
str += "[puppet]\n"
data["puppet"].each { |var, value|
str += "%s = %s\n" % [var, value]
}
data.delete("puppet")
end
data.each { |type, settings|
str += "[%s]\n" % type
settings.each { |var, value|
str += "%s = %s\n" % [var, value]
}
}
return str
end
def sampledata
if block_given?
@@gooddata.each { |hash| yield hash }
else
return @@gooddata[0]
end
end
def test_readconfig
path = tempfile()
sampledata { |data|
config = Puppet::Util::Settings.new
data.each { |section, hash|
hash.each { |param, value|
config.setdefaults(section, param => [value, value])
}
}
# Write it out as a config file
File.open(path, "w") { |f| f.print data2config(data) }
assert_nothing_raised {
config.parse(path)
}
data.each { |section, hash|
hash.each { |var, value|
assert_equal(
data[section][var],
config[var],
"Got different values at %s/%s" % [section, var]
)
}
}
}
end
# Make sure that basic config generation works; this also ensures
# that the default config is free of simple typos etc.
def test_genconfig
assert_nothing_raised {
Puppet::settings::to_config
}
end
end
|