summaryrefslogtreecommitdiffstats
path: root/test/util
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2010-07-09 18:05:04 -0700
committerMarkus Roberts <Markus@reality.com>2010-07-09 18:05:04 -0700
commit9ee56f2e67be973da49b1d3f21de1bf87de35e6f (patch)
treeddab8c01509f47664c52c8a6b165bb5a974f138f /test/util
parent051bd98751d9d4bc97f93f66723d9b7a00c0cfb4 (diff)
downloadpuppet-9ee56f2e67be973da49b1d3f21de1bf87de35e6f.tar.gz
puppet-9ee56f2e67be973da49b1d3f21de1bf87de35e6f.tar.xz
puppet-9ee56f2e67be973da49b1d3f21de1bf87de35e6f.zip
Code smell: Inconsistent indentation and related formatting issues
* Replaced 163 occurances of defined\? +([@a-zA-Z_.0-9?=]+) with defined?(\1) This makes detecting subsequent patterns easier. 3 Examples: The code: if ! defined? @parse_config becomes: if ! defined?(@parse_config) The code: return @option_parser if defined? @option_parser becomes: return @option_parser if defined?(@option_parser) The code: if defined? @local and @local becomes: if defined?(@local) and @local * Eliminate trailing spaces. Replaced 428 occurances of ^(.*?) +$ with \1 1 file was skipped. test/ral/providers/host/parsed.rb because 0 * Replace leading tabs with an appropriate number of spaces. Replaced 306 occurances of ^(\t+)(.*) with Tabs are not consistently expanded in all environments. * Don't arbitrarily wrap on sprintf (%) operator. Replaced 143 occurances of (.*['"] *%) +(.*) with Splitting the line does nothing to aid clarity and hinders further refactorings. 3 Examples: The code: raise Puppet::Error, "Cannot create %s: basedir %s is a file" % [dir, File.join(path)] becomes: raise Puppet::Error, "Cannot create %s: basedir %s is a file" % [dir, File.join(path)] The code: Puppet.err "Will not start without authorization file %s" % Puppet[:authconfig] becomes: Puppet.err "Will not start without authorization file %s" % Puppet[:authconfig] The code: $stderr.puts "Could not find host for PID %s with status %s" % [pid, $?.exitstatus] becomes: $stderr.puts "Could not find host for PID %s with status %s" % [pid, $?.exitstatus] * Don't break short arrays/parameter list in two. Replaced 228 occurances of (.*) +(.*) with 3 Examples: The code: puts @format.wrap(type.provider(prov).doc, :indent => 4, :scrub => true) becomes: puts @format.wrap(type.provider(prov).doc, :indent => 4, :scrub => true) The code: assert(FileTest.exists?(daily), "Did not make daily graph for %s" % type) becomes: assert(FileTest.exists?(daily), "Did not make daily graph for %s" % type) The code: assert(prov.target_object(:first).read !~ /^notdisk/, "Did not remove thing from disk") becomes: assert(prov.target_object(:first).read !~ /^notdisk/, "Did not remove thing from disk") * If arguments must wrap, treat them all equally Replaced 510 occurances of lines ending in things like ...(foo, or ...(bar(1,3), with \1 \2 3 Examples: The code: midscope.to_hash(false), becomes: assert_equal( The code: botscope.to_hash(true), becomes: # bottomscope, then checking that we see the right stuff. The code: :path => link, becomes: * Replaced 4516 occurances of ^( *)(.*) with The present code base is supposed to use four-space indentation. In some places we failed to maintain that standard. These should be fixed regardless of the 2 vs. 4 space question. 15 Examples: The code: def run_comp(cmd) puts cmd results = [] old_sync = $stdout.sync $stdout.sync = true line = [] begin open("| #{cmd}", "r") do |f| until f.eof? do c = f.getc becomes: def run_comp(cmd) puts cmd results = [] old_sync = $stdout.sync $stdout.sync = true line = [] begin open("| #{cmd}", "r") do |f| until f.eof? do c = f.getc The code: s.gsub!(/.{4}/n, '\\\\u\&') } string.force_encoding(Encoding::UTF_8) string rescue Iconv::Failure => e raise GeneratorError, "Caught #{e.class}: #{e}" end else def utf8_to_pson(string) # :nodoc: string = string.gsub(/["\\\x0-\x1f]/) { MAP[$&] } string.gsub!(/( becomes: s.gsub!(/.{4}/n, '\\\\u\&') } string.force_encoding(Encoding::UTF_8) string rescue Iconv::Failure => e raise GeneratorError, "Caught #{e.class}: #{e}" end else def utf8_to_pson(string) # :nodoc: string = string.gsub(/["\\\x0-\x1f]/) { MAP[$&] } string.gsub!(/( The code: end } rvalues: rvalue | rvalues comma rvalue { if val[0].instance_of?(AST::ASTArray) result = val[0].push(val[2]) else result = ast AST::ASTArray, :children => [val[0],val[2]] end } becomes: end } rvalues: rvalue | rvalues comma rvalue { if val[0].instance_of?(AST::ASTArray) result = val[0].push(val[2]) else result = ast AST::ASTArray, :children => [val[0],val[2]] end } The code: #passwdproc = proc { @password } keytext = @key.export( OpenSSL::Cipher::DES.new(:EDE3, :CBC), @password ) File.open(@keyfile, "w", 0400) { |f| f << keytext } becomes: # passwdproc = proc { @password } keytext = @key.export( OpenSSL::Cipher::DES.new(:EDE3, :CBC), @password ) File.open(@keyfile, "w", 0400) { |f| f << keytext } The code: end def to_manifest "%s { '%s':\n%s\n}" % [self.type.to_s, self.name, @params.collect { |p, v| if v.is_a? Array " #{p} => [\'#{v.join("','")}\']" else " #{p} => \'#{v}\'" end }.join(",\n") becomes: end def to_manifest "%s { '%s':\n%s\n}" % [self.type.to_s, self.name, @params.collect { |p, v| if v.is_a? Array " #{p} => [\'#{v.join("','")}\']" else " #{p} => \'#{v}\'" end }.join(",\n") The code: via the augeas tool. Requires: - augeas to be installed (http://www.augeas.net) - ruby-augeas bindings Sample usage with a string:: augeas{\"test1\" : context => \"/files/etc/sysconfig/firstboot\", changes => \"set RUN_FIRSTBOOT YES\", becomes: via the augeas tool. Requires: - augeas to be installed (http://www.augeas.net) - ruby-augeas bindings Sample usage with a string:: augeas{\"test1\" : context => \"/files/etc/sysconfig/firstboot\", changes => \"set RUN_FIRSTBOOT YES\", The code: names.should_not be_include("root") end describe "when generating a purgeable resource" do it "should be included in the generated resources" do Puppet::Type.type(:host).stubs(:instances).returns [@purgeable_resource] @resources.generate.collect { |r| r.ref }.should include(@purgeable_resource.ref) end end describe "when the instance's do not have an ensure property" do becomes: names.should_not be_include("root") end describe "when generating a purgeable resource" do it "should be included in the generated resources" do Puppet::Type.type(:host).stubs(:instances).returns [@purgeable_resource] @resources.generate.collect { |r| r.ref }.should include(@purgeable_resource.ref) end end describe "when the instance's do not have an ensure property" do The code: describe "when the instance's do not have an ensure property" do it "should not be included in the generated resources" do @no_ensure_resource = Puppet::Type.type(:exec).new(:name => '/usr/bin/env echo') Puppet::Type.type(:host).stubs(:instances).returns [@no_ensure_resource] @resources.generate.collect { |r| r.ref }.should_not include(@no_ensure_resource.ref) end end describe "when the instance's ensure property does not accept absent" do it "should not be included in the generated resources" do @no_absent_resource = Puppet::Type.type(:service).new(:name => 'foobar') becomes: describe "when the instance's do not have an ensure property" do it "should not be included in the generated resources" do @no_ensure_resource = Puppet::Type.type(:exec).new(:name => '/usr/bin/env echo') Puppet::Type.type(:host).stubs(:instances).returns [@no_ensure_resource] @resources.generate.collect { |r| r.ref }.should_not include(@no_ensure_resource.ref) end end describe "when the instance's ensure property does not accept absent" do it "should not be included in the generated resources" do @no_absent_resource = Puppet::Type.type(:service).new(:name => 'foobar') The code: func = nil assert_nothing_raised do func = Puppet::Parser::AST::Function.new( :name => "template", :ftype => :rvalue, :arguments => AST::ASTArray.new( :children => [stringobj(template)] ) becomes: func = nil assert_nothing_raised do func = Puppet::Parser::AST::Function.new( :name => "template", :ftype => :rvalue, :arguments => AST::ASTArray.new( :children => [stringobj(template)] ) The code: assert( @store.allowed?("hostname.madstop.com", "192.168.1.50"), "hostname not allowed") assert( ! @store.allowed?("name.sub.madstop.com", "192.168.0.50"), "subname name allowed") becomes: assert( @store.allowed?("hostname.madstop.com", "192.168.1.50"), "hostname not allowed") assert( ! @store.allowed?("name.sub.madstop.com", "192.168.0.50"), "subname name allowed") The code: assert_nothing_raised { server = Puppet::Network::Handler.fileserver.new( :Local => true, :Config => false ) } becomes: assert_nothing_raised { server = Puppet::Network::Handler.fileserver.new( :Local => true, :Config => false ) } The code: 'yay', { :failonfail => false, :uid => @user.uid, :gid => @user.gid } ).returns('output') output = Puppet::Util::SUIDManager.run_and_capture 'yay', @user.uid, @user.gid becomes: 'yay', { :failonfail => false, :uid => @user.uid, :gid => @user.gid } ).returns('output') output = Puppet::Util::SUIDManager.run_and_capture 'yay', @user.uid, @user.gid The code: ).times(1) pkg.provider.expects( :aptget ).with( '-y', '-q', 'remove', 'faff' becomes: ).times(1) pkg.provider.expects( :aptget ).with( '-y', '-q', 'remove', 'faff' The code: johnny one two billy three four\n" # Just parse and generate, to make sure it's isomorphic. assert_nothing_raised do assert_equal(text, @parser.to_file(@parser.parse(text)), "parsing was not isomorphic") end end def test_valid_attrs becomes: johnny one two billy three four\n" # Just parse and generate, to make sure it's isomorphic. assert_nothing_raised do assert_equal(text, @parser.to_file(@parser.parse(text)), "parsing was not isomorphic") end end def test_valid_attrs The code: "testing", :onboolean => [true, "An on bool"], :string => ["a string", "A string arg"] ) result = [] should = [] assert_nothing_raised("Add args failed") do @config.addargs(result) end @config.each do |name, element| becomes: "testing", :onboolean => [true, "An on bool"], :string => ["a string", "A string arg"] ) result = [] should = [] assert_nothing_raised("Add args failed") do @config.addargs(result) end @config.each do |name, element|
Diffstat (limited to 'test/util')
-rwxr-xr-xtest/util/classgen.rb39
-rwxr-xr-xtest/util/fileparsing.rb164
-rwxr-xr-xtest/util/inifile.rb43
-rwxr-xr-xtest/util/log.rb27
-rwxr-xr-xtest/util/package.rb3
-rwxr-xr-xtest/util/settings.rb146
-rwxr-xr-xtest/util/storage.rb5
-rwxr-xr-xtest/util/subclass_loader.rb11
-rwxr-xr-xtest/util/utiltest.rb59
9 files changed, 315 insertions, 182 deletions
diff --git a/test/util/classgen.rb b/test/util/classgen.rb
index 24908069d..83b64813c 100755
--- a/test/util/classgen.rb
+++ b/test/util/classgen.rb
@@ -55,14 +55,20 @@ class TestPuppetUtilClassGen < Test::Unit::TestCase
# Now make sure we can choose our own constant
assert_nothing_raised do
- const = sub.send(:handleclassconst, newklass, klass.name,
+
+ const = sub.send(
+ :handleclassconst, newklass, klass.name,
+
:constant => "Fooness")
end
assert(defined?(Baseconst::Fooness), "Specified constant was not defined")
# And make sure prefixes work
assert_nothing_raised do
- const = sub.send(:handleclassconst, newklass, klass.name,
+
+ const = sub.send(
+ :handleclassconst, newklass, klass.name,
+
:prefix => "Test")
end
assert(defined?(Baseconst::TestGenconst), "prefix was not used")
@@ -111,7 +117,10 @@ class TestPuppetUtilClassGen < Test::Unit::TestCase
assert(!klass.one, "'one' was already set")
- assert_nothing_raised do sub.send(:initclass, klass,
+
+ assert_nothing_raised do sub.send(
+ :initclass, klass,
+
:attributes => {:one => :a, :two => :b}) end
assert_equal(:a, klass.one, "Class was initialized incorrectly")
@@ -135,7 +144,10 @@ class TestPuppetUtilClassGen < Test::Unit::TestCase
assert(! klass.respond_to?(:extended), "Class already responds to extended")
assert(! klass.new.respond_to?(:included), "Class already responds to included")
- assert_nothing_raised do sub.send(:initclass, klass,
+
+ assert_nothing_raised do sub.send(
+ :initclass, klass,
+
:include => incl, :extend => ext)
end
@@ -150,8 +162,7 @@ class TestPuppetUtilClassGen < Test::Unit::TestCase
name = "yayness"
klass = nil
assert_nothing_raised {
- klass = GenTest.genclass(name, :array => array,
- :hash => hash, :parent => FakeBase) do
+ klass = GenTest.genclass(name, :array => array, :hash => hash, :parent => FakeBase) do
class << self
attr_accessor :name
end
@@ -160,9 +171,15 @@ class TestPuppetUtilClassGen < Test::Unit::TestCase
assert(klass.respond_to?(:name=), "Class did not execute block")
- assert(hash.include?(klass.name),
+
+ assert(
+ hash.include?(klass.name),
+
"Class did not get added to hash")
- assert(array.include?(klass),
+
+ assert(
+ array.include?(klass),
+
"Class did not get added to array")
assert_equal(klass.superclass, FakeBase, "Parent class was wrong")
end
@@ -209,10 +226,8 @@ class TestPuppetUtilClassGen < Test::Unit::TestCase
assert(mod.respond_to?(:yaytest), "Class did not execute block")
assert_instance_of(Module, mod)
- assert(hash.include?(mod.name),
- "Class did not get added to hash")
- assert(array.include?(mod),
- "Class did not get added to array")
+ assert(hash.include?(mod.name), "Class did not get added to hash")
+ assert(array.include?(mod), "Class did not get added to array")
end
def test_genconst_string
diff --git a/test/util/fileparsing.rb b/test/util/fileparsing.rb
index c88bcb23a..097254a50 100755
--- a/test/util/fileparsing.rb
+++ b/test/util/fileparsing.rb
@@ -21,21 +21,22 @@ class TestUtilFileParsing < Test::Unit::TestCase
end
def test_lines
- assert_equal("\n", @parser.line_separator,
- "Default separator was incorrect")
+ assert_equal("\n", @parser.line_separator, "Default separator was incorrect")
{"\n" => ["one two\nthree four", "one two\nthree four\n"],
- "\t" => ["one two\tthree four", "one two\tthree four\t"],
+ "\t" => ["one two\tthree four", "one two\tthree four\t"],
}.each do |sep, tests|
assert_nothing_raised do
@parser.line_separator = sep
end
- assert_equal(sep, @parser.line_separator,
- "Did not set separator")
+
+ assert_equal(
+ sep, @parser.line_separator,
+
+ "Did not set separator")
tests.each do |test|
- assert_equal(["one two", "three four"], @parser.lines(test),
- "Incorrectly parsed %s" % test.inspect)
+ assert_equal(["one two", "three four"], @parser.lines(test), "Incorrectly parsed %s" % test.inspect)
end
end
end
@@ -72,8 +73,11 @@ class TestUtilFileParsing < Test::Unit::TestCase
# Make sure it matches
assert_nothing_raised do
- assert_equal({:record_type => :comment, :line => comment},
- @parser.parse_line(comment))
+
+ assert_equal(
+ {:record_type => :comment, :line => comment},
+
+ @parser.parse_line(comment))
end
# But not something else
@@ -88,14 +92,20 @@ class TestUtilFileParsing < Test::Unit::TestCase
# The comment should still match
assert_nothing_raised do
- assert_equal({:record_type => :comment, :line => comment},
- @parser.parse_line(comment))
+
+ assert_equal(
+ {:record_type => :comment, :line => comment},
+
+ @parser.parse_line(comment))
end
# As should our new line type
assert_nothing_raised do
- assert_equal({:record_type => :blank, :line => ""},
- @parser.parse_line(""))
+
+ assert_equal(
+ {:record_type => :blank, :line => ""},
+
+ @parser.parse_line(""))
end
end
@@ -141,13 +151,11 @@ class TestUtilFileParsing < Test::Unit::TestCase
end
assert_nothing_raised("Did not parse old comment") do
- assert_equal({:record_type => :comment, :line => comment},
- @parser.parse_line(comment))
+ assert_equal({:record_type => :comment, :line => comment}, @parser.parse_line(comment))
end
comment = '" another type of comment'
assert_nothing_raised("Did not parse new comment") do
- assert_equal({:record_type => :comment2, :line => comment},
- @parser.parse_line(comment))
+ assert_equal({:record_type => :comment2, :line => comment}, @parser.parse_line(comment))
end
# Now define two overlapping record types and make sure we keep the
@@ -158,8 +166,7 @@ class TestUtilFileParsing < Test::Unit::TestCase
end
assert_nothing_raised do
- assert_equal({:record_type => :one, :line => "yayness"},
- @parser.parse_line("yayness"))
+ assert_equal({:record_type => :one, :line => "yayness"}, @parser.parse_line("yayness"))
end
end
@@ -182,8 +189,7 @@ class TestUtilFileParsing < Test::Unit::TestCase
end
# Make sure out tab line gets matched
- tabshould = {:record_type => :tabs, :name => "tab", :first => "separated",
- :second => "content"}
+ tabshould = {:record_type => :tabs, :name => "tab", :first => "separated", :second => "content"}
assert_nothing_raised do
assert_equal(tabshould, @parser.handle_record_line(tabrecord, tabs))
end
@@ -195,8 +201,7 @@ class TestUtilFileParsing < Test::Unit::TestCase
end
# Now make sure both lines parse correctly
- spaceshould = {:record_type => :spaces, :name => "space",
- :first => "separated", :second => "content"}
+ spaceshould = {:record_type => :spaces, :name => "space", :first => "separated", :second => "content"}
assert_nothing_raised do
assert_equal(tabshould, @parser.handle_record_line(tabrecord, tabs))
@@ -243,8 +248,7 @@ class TestUtilFileParsing < Test::Unit::TestCase
ordered_records = order.collect { |name| records[name] }
# Make sure we default to a trailing separator
- assert_equal(true, @parser.trailing_separator,
- "Did not default to a trailing separtor")
+ assert_equal(true, @parser.trailing_separator, "Did not default to a trailing separtor")
# Start without a trailing separator
@parser.trailing_separator = false
@@ -280,7 +284,10 @@ class TestUtilFileParsing < Test::Unit::TestCase
result = nil
assert_nothing_raised do
- result = @parser.to_line(:record_type => :record,
+
+ result = @parser.to_line(
+ :record_type => :record,
+
:one => "a", :two => :absent, :three => "b")
end
@@ -289,15 +296,17 @@ class TestUtilFileParsing < Test::Unit::TestCase
# Now try using a different replacement character
record.absent = "*" # Because cron is a pain in my ass
assert_nothing_raised do
- result = @parser.to_line(:record_type => :record,
- :one => "a", :two => :absent, :three => "b")
+ result = @parser.to_line(:record_type => :record, :one => "a", :two => :absent, :three => "b")
end
assert_equal("a * b", result, "Absent was not correctly replaced")
# Make sure we deal correctly with the string 'absent'
assert_nothing_raised do
- result = @parser.to_line(:record_type => :record,
+
+ result = @parser.to_line(
+ :record_type => :record,
+
:one => "a", :two => "b", :three => 'absent')
end
@@ -305,7 +314,10 @@ class TestUtilFileParsing < Test::Unit::TestCase
# And, of course, make sure we can swap things around.
assert_nothing_raised do
- result = @parser.to_line(:record_type => :record,
+
+ result = @parser.to_line(
+ :record_type => :record,
+
:one => "a", :two => "b", :three => :absent)
end
@@ -318,14 +330,15 @@ class TestUtilFileParsing < Test::Unit::TestCase
# Check parsing first
result = @parser.parse_line(start)
[:one, :two].each do |param|
- assert_equal(record[param], result[param],
+
+ assert_equal(
+ record[param], result[param],
+
"Did not correctly parse %s" % start.inspect)
end
# And generating
- assert_equal(final, @parser.to_line(result),
- "Did not correctly generate %s from %s" %
- [final.inspect, record.inspect])
+ assert_equal(final, @parser.to_line(result), "Did not correctly generate %s from %s" % [final.inspect, record.inspect])
end
# First try it with symmetric characters
@@ -361,23 +374,32 @@ class TestUtilFileParsing < Test::Unit::TestCase
johnny one two
billy three four\n"
- # Just parse and generate, to make sure it's isomorphic.
- assert_nothing_raised do
- assert_equal(text, @parser.to_file(@parser.parse(text)),
- "parsing was not isomorphic")
+# Just parse and generate, to make sure it's isomorphic.
+assert_nothing_raised do
+ assert_equal(text, @parser.to_file(@parser.parse(text)),
+ "parsing was not isomorphic")
end
end
def test_valid_attrs
@parser.record_line :record, :fields => %w{one two three}
- assert(@parser.valid_attr?(:record, :one),
+
+ assert(
+ @parser.valid_attr?(:record, :one),
+
"one was considered invalid")
- assert(@parser.valid_attr?(:record, :ensure),
+
+ assert(
+ @parser.valid_attr?(:record, :ensure),
+
"ensure was considered invalid")
- assert(! @parser.valid_attr?(:record, :four),
+
+ assert(
+ ! @parser.valid_attr?(:record, :four),
+
"four was considered valid")
end
@@ -433,11 +455,9 @@ billy three four\n"
assert(result, "Did not get a result back for '%s'" % line)
should.each do |field|
if field == :alias and line =~ /null/
- assert_equal(%w{sink null}, result[field],
- "Field %s was not right in '%s'" % [field, line])
+ assert_equal(%w{sink null}, result[field], "Field %s was not right in '%s'" % [field, line])
else
- assert_equal(values[field], result[field],
- "Field %s was not right in '%s'" % [field, line])
+ assert_equal(values[field], result[field], "Field %s was not right in '%s'" % [field, line])
end
end
end
@@ -457,9 +477,9 @@ billy three four\n"
end
{ "a b c d" => [],
- "a b * d" => [:three],
- "a b * *" => [:three, :four],
- "a b c *" => [:four]
+ "a b * d" => [:three],
+ "a b * *" => [:three, :four],
+ "a b c *" => [:four]
}.each do |line, absentees|
record = nil
assert_nothing_raised do
@@ -495,7 +515,10 @@ billy three four\n"
:optional => %w{three four}
end
- assert_equal("a b ",
+
+ assert_equal(
+ "a b ",
+
@parser.to_line(:record_type => :record, :one => "a", :two => "b")
)
@@ -508,7 +531,10 @@ billy three four\n"
:rts => true
end
- assert_equal("a b",
+
+ assert_equal(
+ "a b",
+
@parser.to_line(:record_type => :record, :one => "a", :two => "b")
)
@@ -522,7 +548,10 @@ billy three four\n"
:rts => /[ *]+$/
end
- assert_equal("a b",
+
+ assert_equal(
+ "a b",
+
@parser.to_line(:record_type => :record, :one => "a", :two => "b")
)
end
@@ -536,7 +565,10 @@ billy three four\n"
assert_nothing_raised do
result = @parser.send(:parse_line, "Name One Two Three")
end
- assert_equal("Two Three", result[:two],
+
+ assert_equal(
+ "Two Three", result[:two],
+
"Did not roll up last fields by default")
@parser = FParser.new
@@ -548,7 +580,10 @@ billy three four\n"
assert_nothing_raised do
result = @parser.send(:parse_line, "Name One Two Three")
end
- assert_equal("Two", result[:two],
+
+ assert_equal(
+ "Two", result[:two],
+
"Rolled up last fields when rollup => false")
end
@@ -560,7 +595,10 @@ billy three four\n"
end
end
- assert(record.respond_to?(:process),
+
+ assert(
+ record.respond_to?(:process),
+
"Block was not used with text line")
assert_equal("YAYNESS", record.process("yayness")[:line],
@@ -616,8 +654,7 @@ class TestUtilFileRecord < Test::Unit::TestCase
assert_nothing_raised do
record = Record.new(:record, :fields => %w{one two})
end
- assert_equal([:one, :two], record.fields,
- "Did not symbolize fields")
+ assert_equal([:one, :two], record.fields, "Did not symbolize fields")
# Make sure we fail on invalid fields
[:record_type, :target, :on_disk].each do |field|
@@ -634,9 +671,8 @@ class TestUtilFileRecord < Test::Unit::TestCase
end
record = Record.new(:record, :fields => %w{fields})
- {:absent => "", :separator => /\s+/, :joiner => " ",
- :optional => []}.each do |field, default|
- assert_equal(default, record.send(field), "%s was not default" % field)
+ {:absent => "", :separator => /\s+/, :joiner => " ", :optional => []}.each do |field, default|
+ assert_equal(default, record.send(field), "%s was not default" % field)
end
end
@@ -650,10 +686,16 @@ class TestUtilFileRecord < Test::Unit::TestCase
line = "This is a line"
- assert(record.respond_to?(:process),
+
+ assert(
+ record.respond_to?(:process),
+
"Record did not define :process method")
- assert_equal(line.upcase, record.process(line),
+
+ assert_equal(
+ line.upcase, record.process(line),
+
"Record did not process line correctly")
end
diff --git a/test/util/inifile.rb b/test/util/inifile.rb
index 8ce52ee8d..b4d7f9353 100755
--- a/test/util/inifile.rb
+++ b/test/util/inifile.rb
@@ -29,22 +29,28 @@ class TestFileType < Test::Unit::TestCase
@file['main']['key2'] = 'newvalue2'
@file['main']['key3'] = 'newvalue3'
text = s.format
- assert_equal("[main]\nkey1=value1\n# Comment\nkey2=newvalue2\nkey3=newvalue3\n",
- s.format)
+
+ assert_equal(
+ "[main]\nkey1=value1\n# Comment\nkey2=newvalue2\nkey3=newvalue3\n",
+
+ s.format)
end
def test_multi
fmain = mkfile("[main]\nkey1=main.value1\n# Comment\nkey2=main.value2")
fsub = mkfile("[sub1]\nkey1=sub1 value1\n\n" +
- "[sub2]\nkey1=sub2.value1")
+ "[sub2]\nkey1=sub2.value1")
main_mtime = File::stat(fmain).mtime
assert_nothing_raised {
@file.read(fmain)
@file.read(fsub)
}
main = get_section('main')
- assert_entries(main,
- { 'key1' => 'main.value1', 'key2' => 'main.value2' })
+
+ assert_entries(
+ main,
+
+ { 'key1' => 'main.value1', 'key2' => 'main.value2' })
sub1 = get_section('sub1')
assert_entries(sub1, { 'key1' => 'sub1 value1' })
sub2 = get_section('sub2')
@@ -60,14 +66,17 @@ class TestFileType < Test::Unit::TestCase
assert( File.exists?(fsub) )
assert_equal(main_mtime, File::stat(fmain).mtime)
subtext = File.read(fsub)
- assert_equal("[sub1]\nkey1=sub1 newvalue1\n\n" +
- "[sub2]\nkey1=sub2.value1\nkey2=sub2 newvalue2\n",
- subtext)
+
+ assert_equal(
+ "[sub1]\nkey1=sub1 newvalue1\n\n" +
+ "[sub2]\nkey1=sub2.value1\nkey2=sub2 newvalue2\n",
+
+ subtext)
end
def test_format_nil
fname = mkfile("[main]\nkey1=value1\n# Comment\nkey2=value2\n" +
- "# Comment2\n")
+ "# Comment2\n")
assert_nothing_raised {
@file.read(fname)
}
@@ -75,8 +84,11 @@ class TestFileType < Test::Unit::TestCase
s['key2'] = nil
s['key3'] = nil
text = s.format
- assert_equal("[main]\nkey1=value1\n# Comment\n# Comment2\n",
- s.format)
+
+ assert_equal(
+ "[main]\nkey1=value1\n# Comment\n# Comment2\n",
+
+ s.format)
end
def test_whitespace
@@ -107,9 +119,12 @@ class TestFileType < Test::Unit::TestCase
def assert_entries(section, hash)
hash.each do |k, v|
- assert_equal(v, section[k],
- "Expected <#{v}> for #{section.name}[#{k}] " +
- "but got <#{section[k]}>")
+
+ assert_equal(
+ v, section[k],
+
+ "Expected <#{v}> for #{section.name}[#{k}] " +
+ "but got <#{section[k]}>")
end
end
diff --git a/test/util/log.rb b/test/util/log.rb
index b28d601e9..5fb30cf05 100755
--- a/test/util/log.rb
+++ b/test/util/log.rb
@@ -35,9 +35,12 @@ class TestLog < Test::Unit::TestCase
levels.collect { |level|
next if level == :alert
assert_nothing_raised() {
- Puppet::Util::Log.new(
+
+ Puppet::Util::Log.new(
+
:level => level,
:source => "Test",
+
:message => "Unit test for %s" % level
)
}
@@ -118,8 +121,11 @@ class TestLog < Test::Unit::TestCase
Puppet::Util::Log.newdestination :syslog
assert_nothing_raised {
- Puppet::Util::Log.new(
+
+ Puppet::Util::Log.new(
+
:level => :info,
+
:message => "A message with %s in it"
)
}
@@ -128,8 +134,11 @@ class TestLog < Test::Unit::TestCase
# Verify that the error and source are always strings
def test_argsAreStrings
msg = nil
- file = Puppet::Type.type(:file).new(
+
+ file = Puppet::Type.type(:file).new(
+
:path => tempfile(),
+
:check => %w{owner group}
)
assert_nothing_raised {
@@ -169,11 +178,9 @@ class TestLog < Test::Unit::TestCase
Puppet::Util::Log.close(:console)
Puppet::Util::Log.newdestination(file)
Puppet.warning "A test"
- assert(File.read(file) !~ /A test/,
- "File defualted to autoflush")
+ assert(File.read(file) !~ /A test/, "File defualted to autoflush")
Puppet::Util::Log.flush
- assert(File.read(file) =~ /A test/,
- "File did not flush")
+ assert(File.read(file) =~ /A test/, "File did not flush")
Puppet::Util::Log.close(file)
# Now try one with autoflush enabled
@@ -181,8 +188,7 @@ class TestLog < Test::Unit::TestCase
file = tempfile
Puppet::Util::Log.newdestination(file)
Puppet.warning "A test"
- assert(File.read(file) =~ /A test/,
- "File did not autoflush")
+ assert(File.read(file) =~ /A test/, "File did not autoflush")
Puppet::Util::Log.close(file)
end
@@ -206,8 +212,7 @@ class TestLog < Test::Unit::TestCase
# Now reopen the log
Puppet::Util::Log.reopen
Puppet.warning "Reopen test"
- assert(File.read(file) =~ /Reopen test/,
- "File did not reopen")
+ assert(File.read(file) =~ /Reopen test/, "File did not reopen")
Puppet::Util::Log.close(file)
end
end
diff --git a/test/util/package.rb b/test/util/package.rb
index b77850d4b..c252db1d8 100755
--- a/test/util/package.rb
+++ b/test/util/package.rb
@@ -11,8 +11,7 @@ class TestPuppetUtilPackage < Test::Unit::TestCase
include Puppet::Util::Package
def test_versioncmp
- ary = %w{ 1.1.6 2.3 1.1a 3.0 1.5 1 2.4 1.1-4
- 2.3.1 1.2 2.3.0 1.1-3 2.4b 2.4 2.40.2 2.3a.1 3.1 0002 1.1-5 1.1.a 1.06}
+ ary = %w{ 1.1.6 2.3 1.1a 3.0 1.5 1 2.4 1.1-4 2.3.1 1.2 2.3.0 1.1-3 2.4b 2.4 2.40.2 2.3a.1 3.1 0002 1.1-5 1.1.a 1.06}
newary = nil
assert_nothing_raised do
diff --git a/test/util/settings.rb b/test/util/settings.rb
index 272ced9f5..354a5d7fc 100755
--- a/test/util/settings.rb
+++ b/test/util/settings.rb
@@ -20,17 +20,23 @@ class TestSettings < Test::Unit::TestCase
def set_configs(config = nil)
config ||= @config
- config.setdefaults("main",
+
+ config.setdefaults(
+ "main",
:one => ["a", "one"],
:two => ["a", "two"],
:yay => ["/default/path", "boo"],
:mkusers => [true, "uh, yeah"],
+
:name => ["testing", "a"]
)
- config.setdefaults("section1",
+
+ config.setdefaults(
+ "section1",
:attr => ["a", "one"],
:attrdir => ["/another/dir", "two"],
+
:attr3 => ["$attrdir/maybe", "boo"]
)
end
@@ -183,13 +189,13 @@ class TestSettings < Test::Unit::TestCase
def test_parse_file
text = %{
-one = this is a test
-two = another test
-owner = root
-group = root
-yay = /a/path
+ one = this is a test
+ two = another test
+ owner = root
+ group = root
+ yay = /a/path
-[main]
+ [main]
four = five
six = seven
@@ -241,10 +247,13 @@ yay = /a/path
c = mkconfig
assert_nothing_raised {
- @config.setdefaults("testing",
+
+ @config.setdefaults(
+ "testing",
:onboolean => [true, "An on bool"],
:offboolean => [false, "An off bool"],
:string => ["a string", "A string arg"],
+
:file => ["/path/to/file", "A file arg"]
)
}
@@ -270,8 +279,7 @@ yay = /a/path
arg = val
end
- assert_nothing_raised("Could not handle arg %s with value %s" %
- [opt, val]) {
+ assert_nothing_raised("Could not handle arg %s with value %s" % [opt, val]) {
@config.handlearg(opt, arg)
}
@@ -280,12 +288,15 @@ yay = /a/path
end
def test_addargs
- @config.setdefaults("testing",
- :onboolean => [true, "An on bool"],
- :offboolean => [false, "An off bool"],
- :string => ["a string", "A string arg"],
- :file => ["/path/to/file", "A file arg"]
- )
+
+ @config.setdefaults(
+ "testing",
+ :onboolean => [true, "An on bool"],
+ :offboolean => [false, "An off bool"],
+ :string => ["a string", "A string arg"],
+
+ :file => ["/path/to/file", "A file arg"]
+ )
should = []
@config.each { |name, element|
@@ -303,10 +314,13 @@ yay = /a/path
def test_addargs_functional
@config = Puppet::Util::Settings.new
- @config.setdefaults("testing",
- :onboolean => [true, "An on bool"],
- :string => ["a string", "A string arg"]
- )
+
+ @config.setdefaults(
+ "testing",
+ :onboolean => [true, "An on bool"],
+
+ :string => ["a string", "A string arg"]
+ )
result = []
should = []
assert_nothing_raised("Add args failed") do
@@ -430,7 +444,10 @@ yay = /a/path
config = mkconfig
file = tempfile()
- config.setdefaults(:mysection,
+
+ config.setdefaults(
+ :mysection,
+
:mydir => [file, "a file"]
)
@@ -442,7 +459,10 @@ yay = /a/path
assert(FileTest.directory?(file), "Directory did not get created")
- assert_equal("yayness", Puppet[:tags],
+
+ assert_equal(
+ "yayness", Puppet[:tags],
+
"Tags got changed during config")
end
@@ -457,7 +477,10 @@ yay = /a/path
val = config[:url]
}
- assert_equal("http://yayness/rahness", val,
+
+ assert_equal(
+ "http://yayness/rahness", val,
+
"Settings got messed up")
end
@@ -485,8 +508,11 @@ yay = /a/path
}
elem = config.setting(name)
- assert_instance_of(type, elem,
- "%s got created as wrong type" % value.inspect)
+
+ assert_instance_of(
+ type, elem,
+
+ "%s got created as wrong type" % value.inspect)
end
end
@@ -506,12 +532,12 @@ yay = /a/path
none = one
middle = mid"quote
}
- }
+ }
- config.setdefaults(:mysection, :config => [file, "eh"])
+ config.setdefaults(:mysection, :config => [file, "eh"])
- assert_nothing_raised {
- config.parse
+ assert_nothing_raised {
+ config.parse
}
%w{singleq doubleq none}.each do |p|
@@ -574,8 +600,11 @@ yay = /a/path
def test_no_modify_root
config = mkconfig
- config.setdefaults(:yay,
+
+ config.setdefaults(
+ :yay,
:mydir => {:default => tempfile(),
+
:mode => 0644,
:owner => "root",
:group => "service",
@@ -643,25 +672,37 @@ yay = /a/path
end
def test_multiple_interpolations
- @config.setdefaults(:section,
+
+ @config.setdefaults(
+ :section,
:one => ["oneval", "yay"],
:two => ["twoval", "yay"],
+
:three => ["$one/$two", "yay"]
)
- assert_equal("oneval/twoval", @config[:three],
+
+ assert_equal(
+ "oneval/twoval", @config[:three],
+
"Did not interpolate multiple variables")
end
# Make sure we can replace ${style} var names
def test_curly_replacements
- @config.setdefaults(:section,
+
+ @config.setdefaults(
+ :section,
:one => ["oneval", "yay"],
:two => ["twoval", "yay"],
+
:three => ["$one/${two}/${one}/$two", "yay"]
)
- assert_equal("oneval/twoval/oneval/twoval", @config[:three],
+
+ assert_equal(
+ "oneval/twoval/oneval/twoval", @config[:three],
+
"Did not interpolate curlied variables")
end
@@ -682,16 +723,25 @@ yay = /a/path
def test_celement_short_name_not_duplicated
config = mkconfig
assert_nothing_raised("Could not create celement with short name.") do
- config.setdefaults(:main,
- :one => { :default => "blah", :desc => "anything", :short => "o" })
+
+ config.setdefaults(
+ :main,
+
+ :one => { :default => "blah", :desc => "anything", :short => "o" })
end
assert_nothing_raised("Could not create second celement with short name.") do
- config.setdefaults(:main,
- :two => { :default => "blah", :desc => "anything", :short => "i" })
+
+ config.setdefaults(
+ :main,
+
+ :two => { :default => "blah", :desc => "anything", :short => "i" })
end
assert_raise(ArgumentError, "Could create second celement with duplicate short name.") do
- config.setdefaults(:main,
- :three => { :default => "blah", :desc => "anything", :short => "i" })
+
+ config.setdefaults(
+ :main,
+
+ :three => { :default => "blah", :desc => "anything", :short => "i" })
end
# make sure that when the above raises an expection that the config is not included
assert(!config.include?(:three), "Invalid configuration item was retained")
@@ -706,12 +756,18 @@ yay = /a/path
assert_equal([["--foo", "-n", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args")
element = BooleanSetting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new
- assert_equal([["--foo", GetoptLong::NO_ARGUMENT], ["--no-foo", GetoptLong::NO_ARGUMENT]],
- element.getopt_args, "Did not produce appropriate getopt args")
+
+ assert_equal(
+ [["--foo", GetoptLong::NO_ARGUMENT], ["--no-foo", GetoptLong::NO_ARGUMENT]],
+
+ element.getopt_args, "Did not produce appropriate getopt args")
element.short = "n"
- assert_equal([["--foo", "-n", GetoptLong::NO_ARGUMENT],["--no-foo", GetoptLong::NO_ARGUMENT]],
- element.getopt_args, "Did not produce appropriate getopt args")
+
+ assert_equal(
+ [["--foo", "-n", GetoptLong::NO_ARGUMENT],["--no-foo", GetoptLong::NO_ARGUMENT]],
+
+ element.getopt_args, "Did not produce appropriate getopt args")
end
end
diff --git a/test/util/storage.rb b/test/util/storage.rb
index b0efff317..2259a59d2 100755
--- a/test/util/storage.rb
+++ b/test/util/storage.rb
@@ -12,8 +12,11 @@ class TestStorage < Test::Unit::TestCase
path = tempfile()
File.open(path, "w") { |f| f.puts :yayness }
- f = Puppet::Type.type(:file).new(
+
+ f = Puppet::Type.type(:file).new(
+
:name => path,
+
:check => %w{checksum type}
)
diff --git a/test/util/subclass_loader.rb b/test/util/subclass_loader.rb
index 0efd636f4..ca2522dbf 100755
--- a/test/util/subclass_loader.rb
+++ b/test/util/subclass_loader.rb
@@ -15,7 +15,7 @@ class TestPuppetUtilSubclassLoader < Test::Unit::TestCase
def mk_subclass(name, path, parent)
# Make a fake client
- unless defined? @basedir
+ unless defined?(@basedir)
@basedir ||= tempfile()
$: << @basedir
cleanup { $:.delete(@basedir) if $:.include?(@basedir) }
@@ -40,8 +40,7 @@ class TestPuppetUtilSubclassLoader < Test::Unit::TestCase
fake = LoadTest.faker(:fake)
end
assert_nothing_raised do
- assert_equal(fake, LoadTest.fake,
- "Did not get subclass back from main method")
+ assert_equal(fake, LoadTest.fake, "Did not get subclass back from main method")
end
assert(fake, "did not load subclass")
@@ -83,10 +82,8 @@ class TestPuppetUtilSubclassLoader < Test::Unit::TestCase
end
assert(othersub, "did not get other sub")
assert(mainsub, "did not get main sub")
- assert(othersub.ancestors.include?(OtherLoader),
- "othersub is not a subclass of otherloader")
- assert(mainsub.ancestors.include?(LoadTest),
- "mainsub is not a subclass of loadtest")
+ assert(othersub.ancestors.include?(OtherLoader), "othersub is not a subclass of otherloader")
+ assert(mainsub.ancestors.include?(LoadTest), "mainsub is not a subclass of loadtest")
end
end
diff --git a/test/util/utiltest.rb b/test/util/utiltest.rb
index 62179084f..82016f3aa 100755
--- a/test/util/utiltest.rb
+++ b/test/util/utiltest.rb
@@ -78,8 +78,7 @@ class TestPuppetUtil < Test::Unit::TestCase
end
[:yay, "cool"].each do |var|
- assert_equal(inst.hash[var], inst[var],
- "Var %s did not take" % var)
+ assert_equal(inst.hash[var], inst[var], "Var %s did not take" % var)
end
assert_nothing_raised do
@@ -88,8 +87,7 @@ class TestPuppetUtil < Test::Unit::TestCase
end
[:Yay, "Cool"].each do |var|
- assert_equal(inst.hash[var], inst[var],
- "Var %s did not take" % var)
+ assert_equal(inst.hash[var], inst[var], "Var %s did not take" % var)
end
end
@@ -191,31 +189,34 @@ class TestPuppetUtil < Test::Unit::TestCase
end
def test_lang_environ_in_execute
- orig_lang = ENV["LANG"]
- orig_lc_all = ENV["LC_ALL"]
- orig_lc_messages = ENV["LC_MESSAGES"]
- orig_language = ENV["LANGUAGE"]
-
- cleanup do
- ENV["LANG"] = orig_lang
- ENV["LC_ALL"] = orig_lc_all
- ENV["LC_MESSAGES"] = orig_lc_messages
- ENV["LANGUAGE"] = orig_lc_messages
- end
-
- # Mmm, we love gettext(3)
- ENV["LANG"] = "en_US"
- ENV["LC_ALL"] = "en_US"
- ENV["LC_MESSAGES"] = "en_US"
- ENV["LANGUAGE"] = "en_US"
-
- %w{LANG LC_ALL LC_MESSAGES LANGUAGE}.each do |env|
- assert_equal('C',
- Puppet::Util.execute(['ruby', '-e', "print ENV['#{env}']"]),
- "Environment var #{env} wasn't set to 'C'")
-
- assert_equal 'en_US', ENV[env], "Environment var #{env} not set back correctly"
- end
+ orig_lang = ENV["LANG"]
+ orig_lc_all = ENV["LC_ALL"]
+ orig_lc_messages = ENV["LC_MESSAGES"]
+ orig_language = ENV["LANGUAGE"]
+
+ cleanup do
+ ENV["LANG"] = orig_lang
+ ENV["LC_ALL"] = orig_lc_all
+ ENV["LC_MESSAGES"] = orig_lc_messages
+ ENV["LANGUAGE"] = orig_lc_messages
+ end
+
+ # Mmm, we love gettext(3)
+ ENV["LANG"] = "en_US"
+ ENV["LC_ALL"] = "en_US"
+ ENV["LC_MESSAGES"] = "en_US"
+ ENV["LANGUAGE"] = "en_US"
+
+ %w{LANG LC_ALL LC_MESSAGES LANGUAGE}.each do |env|
+
+ assert_equal(
+ 'C',
+ Puppet::Util.execute(['ruby', '-e', "print ENV['#{env}']"]),
+
+ "Environment var #{env} wasn't set to 'C'")
+
+ assert_equal 'en_US', ENV[env], "Environment var #{env} not set back correctly"
+ end
end