summaryrefslogtreecommitdiffstats
path: root/test/ral/manager
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/ral/manager
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/ral/manager')
-rwxr-xr-xtest/ral/manager/attributes.rb27
-rwxr-xr-xtest/ral/manager/provider.rb3
-rwxr-xr-xtest/ral/manager/type.rb81
3 files changed, 79 insertions, 32 deletions
diff --git a/test/ral/manager/attributes.rb b/test/ral/manager/attributes.rb
index 5ddd27f97..4502a3258 100755
--- a/test/ral/manager/attributes.rb
+++ b/test/ral/manager/attributes.rb
@@ -43,13 +43,14 @@ class TestTypeAttributes < Test::Unit::TestCase
if param == :property
assert(inst.property(param), "did not get obj for %s" % param)
- assert_equal(true, inst.should(param),
+
+ assert_equal(
+ true, inst.should(param),
+
"should value did not get set")
else
- assert_equal(true, inst[param],
- "did not get correct value for %s from symbol" % param)
- assert_equal(true, inst[param.to_s],
- "did not get correct value for %s from string" % param)
+ assert_equal(true, inst[param], "did not get correct value for %s from symbol" % param)
+ assert_equal(true, inst[param.to_s], "did not get correct value for %s from string" % param)
end
end
end
@@ -94,7 +95,10 @@ class TestTypeAttributes < Test::Unit::TestCase
assert(klass, "did not get class for %s" % name)
obj = yield inst, klass
assert_instance_of(klass, obj, "did not get object back")
- assert_equal("value", inst.value(klass.name),
+
+ assert_equal(
+ "value", inst.value(klass.name),
+
"value was not correct from value method")
assert_equal("value", obj.value, "value was not correct")
end
@@ -159,8 +163,7 @@ class TestTypeAttributes < Test::Unit::TestCase
end
aliases.each do |new, old|
- assert_equal(old, type.attr_alias(new), "did not return alias info for %s" %
- new)
+ assert_equal(old, type.attr_alias(new), "did not return alias info for %s" % new)
end
assert_nil(type.attr_alias(:name), "got invalid alias info for name")
@@ -176,11 +179,13 @@ class TestTypeAttributes < Test::Unit::TestCase
case old
when :one # param
- assert_equal(val, inst[new],
+
+ assert_equal(
+ val, inst[new],
+
"Incorrect alias value for %s in []" % new)
else
- assert_equal(val, inst.should(new),
- "Incorrect alias value for %s in should" % new)
+ assert_equal(val, inst.should(new), "Incorrect alias value for %s in should" % new)
end
assert_equal(val, inst.value(new), "Incorrect alias value for %s" % new)
assert_equal(val, inst.value(old), "Incorrect orig value for %s" % old)
diff --git a/test/ral/manager/provider.rb b/test/ral/manager/provider.rb
index 48d6f2dce..82c27b6c6 100755
--- a/test/ral/manager/provider.rb
+++ b/test/ral/manager/provider.rb
@@ -37,8 +37,7 @@ class TestTypeProviders < Test::Unit::TestCase
# Make sure the provider is always the first parameter created.
def test_provider_sorting
should = [:name, :ensure]
- assert_equal(should, @type.allattrs.reject { |p| ! should.include?(p) },
- "Got wrong order of parameters")
+ assert_equal(should, @type.allattrs.reject { |p| ! should.include?(p) }, "Got wrong order of parameters")
@type.provide(:yay) { }
should = [:name, :provider, :ensure]
diff --git a/test/ral/manager/type.rb b/test/ral/manager/type.rb
index 662339419..04ecf95ea 100755
--- a/test/ral/manager/type.rb
+++ b/test/ral/manager/type.rb
@@ -10,16 +10,18 @@ class TestType < Test::Unit::TestCase
def test_typemethods
Puppet::Type.eachtype { |type|
name = nil
- assert_nothing_raised("Searching for name for %s caused failure" %
- type.to_s) {
+ assert_nothing_raised("Searching for name for %s caused failure" % type.to_s) {
name = type.name
}
assert(name, "Could not find name for %s" % type.to_s)
- assert_equal(
+
+ assert_equal(
+
type,
Puppet::Type.type(name),
+
"Failed to retrieve %s by name" % name
)
@@ -29,13 +31,19 @@ class TestType < Test::Unit::TestCase
#end
assert_nothing_raised {
- assert_not_nil(
+
+ assert_not_nil(
+
type.properties,
+
"Properties for %s are nil" % name
)
- assert_not_nil(
+
+ assert_not_nil(
+
type.validproperties,
+
"Valid properties for %s are nil" % name
)
}
@@ -43,8 +51,11 @@ class TestType < Test::Unit::TestCase
end
def test_aliases_are_added_to_catalog
- resource = Puppet::Type.type(:file).new(
+
+ resource = Puppet::Type.type(:file).new(
+
:name => "/path/to/some/missing/file",
+
:ensure => "file"
)
resource.stubs(:path).returns("")
@@ -60,8 +71,11 @@ class TestType < Test::Unit::TestCase
end
def test_aliasing_fails_without_a_catalog
- resource = Puppet::Type.type(:file).new(
+
+ resource = Puppet::Type.type(:file).new(
+
:name => "/no/such/file",
+
:ensure => "file"
)
@@ -73,8 +87,11 @@ class TestType < Test::Unit::TestCase
def test_ensuredefault
user = nil
assert_nothing_raised {
- user = Puppet::Type.type(:user).new(
+
+ user = Puppet::Type.type(:user).new(
+
:name => "pptestAA",
+
:check => [:uid]
)
}
@@ -83,8 +100,11 @@ class TestType < Test::Unit::TestCase
assert(! user.property(:ensure), "User got an ensure property")
assert_nothing_raised {
- user = Puppet::Type.type(:user).new(
+
+ user = Puppet::Type.type(:user).new(
+
:name => "pptestAB",
+
:comment => "Testingness"
)
}
@@ -92,8 +112,11 @@ class TestType < Test::Unit::TestCase
assert(user.property(:ensure), "User did not add ensure property")
assert_nothing_raised {
- user = Puppet::Type.type(:user).new(
+
+ user = Puppet::Type.type(:user).new(
+
:name => "pptestBC",
+
:comment => "A fake user"
)
}
@@ -108,7 +131,10 @@ class TestType < Test::Unit::TestCase
end
}
- assert(Puppet::Type.respond_to?(:newmytype),
+
+ assert(
+ Puppet::Type.respond_to?(:newmytype),
+
"new<type> method did not get created")
obj = nil
@@ -144,8 +170,7 @@ class TestType < Test::Unit::TestCase
newparam(:rah) do isnamevar end
end
}
- assert_equal(parammethod, Puppet::Type.method(:newparam),
- "newparam method got replaced by newtype")
+ assert_equal(parammethod, Puppet::Type.method(:newparam), "newparam method got replaced by newtype")
end
def test_newproperty_options
@@ -215,8 +240,11 @@ class TestType < Test::Unit::TestCase
path = tempfile()
assert_nothing_raised do
- file = fileclass.create(
+
+ file = fileclass.create(
+
:title => "Myfile",
+
:path => path
)
end
@@ -228,8 +256,11 @@ class TestType < Test::Unit::TestCase
# Now make sure we can specify both and still get the right answers
assert_nothing_raised do
- file = fileclass.create(
+
+ file = fileclass.create(
+
:title => "Myfile",
+
:name => path
)
end
@@ -248,15 +279,21 @@ class TestType < Test::Unit::TestCase
echo = Puppet::Util.binary "echo"
exec1 = exec2 = nil
assert_nothing_raised do
- exec1 = Puppet::Type.type(:exec).new(
+
+ exec1 = Puppet::Type.type(:exec).new(
+
:title => "exec1",
+
:command => "#{echo} funtest"
)
end
catalog.add_resource(exec1)
assert_nothing_raised do
- exec2 = Puppet::Type.type(:exec).new(
+
+ exec2 = Puppet::Type.type(:exec).new(
+
:title => "exec2",
+
:command => "#{echo} funtest"
)
end
@@ -265,16 +302,22 @@ class TestType < Test::Unit::TestCase
# Now do files, since they are. This should fail.
file1 = file2 = nil
path = tempfile()
- file1 = Puppet::Type.type(:file).new(
+
+ file1 = Puppet::Type.type(:file).new(
+
:title => "file1",
:path => path,
+
:content => "yayness"
)
catalog.add_resource(file1)
- file2 = Puppet::Type.type(:file).new(
+
+ file2 = Puppet::Type.type(:file).new(
+
:title => "file2",
:path => path,
+
:content => "rahness"
)
assert_raise(ArgumentError) { catalog.add_resource(file2) }