summaryrefslogtreecommitdiffstats
path: root/test/lib
diff options
context:
space:
mode:
Diffstat (limited to 'test/lib')
-rwxr-xr-xtest/lib/puppettest.rb24
-rw-r--r--test/lib/puppettest/certificates.rb4
-rw-r--r--test/lib/puppettest/exetest.rb8
-rw-r--r--test/lib/puppettest/fakes.rb8
-rw-r--r--test/lib/puppettest/filetesting.rb20
-rw-r--r--test/lib/puppettest/parsertesting.rb24
-rw-r--r--test/lib/puppettest/railstesting.rb8
-rw-r--r--test/lib/puppettest/runnable_test.rb4
-rw-r--r--test/lib/puppettest/support/assertions.rb8
-rw-r--r--test/lib/puppettest/support/helpers.rb8
-rwxr-xr-xtest/lib/puppettest/support/resources.rb4
-rw-r--r--test/lib/puppettest/support/utils.rb16
-rw-r--r--test/lib/puppettest/testcase.rb4
-rw-r--r--test/lib/rake/puppet_test_loader.rb4
14 files changed, 36 insertions, 108 deletions
diff --git a/test/lib/puppettest.rb b/test/lib/puppettest.rb
index 9bcbff9c1..38bb04298 100755
--- a/test/lib/puppettest.rb
+++ b/test/lib/puppettest.rb
@@ -113,9 +113,7 @@ module PuppetTest
end
def exampledir(*args)
- unless defined?(@@exampledir)
- @@exampledir = File.join(basedir, "examples")
- end
+ @@exampledir = File.join(basedir, "examples") unless defined?(@@exampledir)
if args.empty?
return @@exampledir
@@ -134,9 +132,7 @@ module PuppetTest
def libsetup
curlibs = ENV["RUBYLIB"].split(":")
$LOAD_PATH.reject do |dir| dir =~ /^\/usr/ end.each do |dir|
- unless curlibs.include?(dir)
- curlibs << dir
- end
+ curlibs << dir unless curlibs.include?(dir)
end
ENV["RUBYLIB"] = curlibs.join(":")
@@ -169,9 +165,7 @@ module PuppetTest
end
def setup
- unless ENV["PATH"].split(File::PATH_SEPARATOR).include?("/usr/sbin")
- ENV["PATH"] += File::PATH_SEPARATOR + "/usr/sbin"
- end
+ ENV["PATH"] += File::PATH_SEPARATOR + "/usr/sbin" unless ENV["PATH"].split(File::PATH_SEPARATOR).include?("/usr/sbin")
@memoryatstart = Puppet::Util.memory
if defined?(@@testcount)
@@testcount += 1
@@ -198,9 +192,7 @@ module PuppetTest
Puppet[:confdir] = @configpath
Puppet[:vardir] = @configpath
- unless File.exists?(@configpath)
- Dir.mkdir(@configpath)
- end
+ Dir.mkdir(@configpath) unless File.exists?(@configpath)
@@tmpfiles << @configpath << tmpdir()
@@tmppids = []
@@ -212,9 +204,7 @@ module PuppetTest
# If we're running under rake, then disable debugging and such.
#if rake? or ! Puppet[:debug]
#if defined?($puppet_debug) or ! rake?
- if textmate?
- Puppet[:color] = false
- end
+ Puppet[:color] = false if textmate?
Puppet::Util::Log.newdestination(@logs)
if defined? $console
Puppet.info @method_name
@@ -319,9 +309,7 @@ module PuppetTest
@memoryatend = Puppet::Util.memory
diff = @memoryatend - @memoryatstart
- if diff > 1000
- Puppet.info "#{self.class}##{@method_name} memory growth (#{@memoryatstart} to #{@memoryatend}): #{diff}"
- end
+ Puppet.info "#{self.class}##{@method_name} memory growth (#{@memoryatstart} to #{@memoryatend}): #{diff}" if diff > 1000
# reset all of the logs
Puppet::Util::Log.close_all
diff --git a/test/lib/puppettest/certificates.rb b/test/lib/puppettest/certificates.rb
index 4f643b2d5..198ec96c4 100644
--- a/test/lib/puppettest/certificates.rb
+++ b/test/lib/puppettest/certificates.rb
@@ -8,9 +8,7 @@ module PuppetTest::Certificates
def mkPassFile()
keyfile = File.join(@dir, "tmpkeyfile")
@@tmpfiles << keyfile
- unless FileTest.exists?(@dir)
- system("mkdir -p #{@dir}")
- end
+ system("mkdir -p #{@dir}") unless FileTest.exists?(@dir)
File.open(keyfile, "w", 0600) { |f|
f.print "as;dklj23rlkjzdflij23wr"
}
diff --git a/test/lib/puppettest/exetest.rb b/test/lib/puppettest/exetest.rb
index c07615245..78f391ddd 100644
--- a/test/lib/puppettest/exetest.rb
+++ b/test/lib/puppettest/exetest.rb
@@ -18,12 +18,8 @@ module PuppetTest::ExeTest
end
def setbindir
- unless ENV["PATH"].split(":").include?(bindir)
- ENV["PATH"] = [bindir, ENV["PATH"]].join(":")
- end
- unless ENV["PATH"].split(":").include?(sbindir)
- ENV["PATH"] = [sbindir, ENV["PATH"]].join(":")
- end
+ ENV["PATH"] = [bindir, ENV["PATH"]].join(":") unless ENV["PATH"].split(":").include?(bindir)
+ ENV["PATH"] = [sbindir, ENV["PATH"]].join(":") unless ENV["PATH"].split(":").include?(sbindir)
end
def setlibdir
diff --git a/test/lib/puppettest/fakes.rb b/test/lib/puppettest/fakes.rb
index c0e0bd899..2db045ab5 100644
--- a/test/lib/puppettest/fakes.rb
+++ b/test/lib/puppettest/fakes.rb
@@ -35,9 +35,7 @@ module PuppetTest
def []=(param, value)
param = symbolize(param)
- unless @realresource.valid_parameter?(param)
- raise Puppet::DevError, "Invalid attribute #{param} for #{@realresource.name}"
- end
+ raise Puppet::DevError, "Invalid attribute #{param} for #{@realresource.name}" unless @realresource.valid_parameter?(param)
if @realresource.attrtype(param) == :property
@should[param] = value
else
@@ -157,9 +155,7 @@ module PuppetTest
def store(hash)
hash.each do |n, v|
method = n.to_s + "="
- if respond_to? method
- send(method, v)
- end
+ send(method, v) if respond_to? method
end
end
end
diff --git a/test/lib/puppettest/filetesting.rb b/test/lib/puppettest/filetesting.rb
index 3c869f5cf..2ecfce58f 100644
--- a/test/lib/puppettest/filetesting.rb
+++ b/test/lib/puppettest/filetesting.rb
@@ -22,9 +22,7 @@ module PuppetTest::FileTesting
ret = []
num.times { |index|
item = list[rand(list.length)]
- if set.include?(item)
- redo
- end
+ redo if set.include?(item)
ret.push item
}
@@ -32,17 +30,11 @@ module PuppetTest::FileTesting
end
def mkranddirsandfiles(dirs = nil,files = nil,depth = 3)
- if depth < 0
- return
- end
+ return if depth < 0
- unless dirs
- dirs = %w{This Is A Set Of Directories}
- end
+ dirs = %w{This Is A Set Of Directories} unless dirs
- unless files
- files = %w{and this is a set of files}
- end
+ files = %w{and this is a set of files} unless files
tfiles = randlist(files)
tdirs = randlist(dirs)
@@ -128,9 +120,7 @@ module PuppetTest::FileTesting
path = File.join(dir,file)
stat = File.stat(dir)
if checked < 10 and (i % 3) == 2
- unless yield path
- next
- end
+ next unless yield path
checked += 1
end
}
diff --git a/test/lib/puppettest/parsertesting.rb b/test/lib/puppettest/parsertesting.rb
index 2211d17be..a23bd5601 100644
--- a/test/lib/puppettest/parsertesting.rb
+++ b/test/lib/puppettest/parsertesting.rb
@@ -21,9 +21,7 @@ module PuppetTest::ParserTesting
end
def initialize(val = nil)
- if val
- @evaluate = val
- end
+ @evaluate = val if val
end
def reset
@@ -66,9 +64,7 @@ module PuppetTest::ParserTesting
compiler ||= mkcompiler
compiler.topscope.source = (parser.find_hostclass("", "") || parser.newclass(""))
- unless compiler.topscope.source
- raise "Could not find source for scope"
- end
+ raise "Could not find source for scope" unless compiler.topscope.source
# Make the 'main' stuff
compiler.send(:evaluate_main)
compiler.topscope
@@ -97,9 +93,7 @@ module PuppetTest::ParserTesting
end
def resourcedef(type, title, params)
- unless title.is_a?(AST)
- title = stringobj(title)
- end
+ title = stringobj(title) unless title.is_a?(AST)
assert_nothing_raised("Could not create #{type} #{title}") {
return AST::Resource.new(
@@ -221,9 +215,7 @@ module PuppetTest::ParserTesting
def resourceparam(param, value)
# Allow them to pass non-strings in
- if value.is_a?(String)
- value = stringobj(value)
- end
+ value = stringobj(value) if value.is_a?(String)
assert_nothing_raised("Could not create param #{param}") {
return AST::ResourceParam.new(
@@ -249,9 +241,7 @@ module PuppetTest::ParserTesting
end
def varobj(name, value)
- unless value.is_a? AST
- value = stringobj(value)
- end
+ value = stringobj(value) unless value.is_a? AST
assert_nothing_raised("Could not create #{name} code") {
return AST::VarDef.new(
@@ -403,9 +393,7 @@ module PuppetTest::ParserTesting
obj["mode"] = "644"
# Yield, if they want
- if block_given?
- yield(obj, i, j)
- end
+ yield(obj, i, j) if block_given?
resources << obj
end
diff --git a/test/lib/puppettest/railstesting.rb b/test/lib/puppettest/railstesting.rb
index 3af593762..2240c739a 100644
--- a/test/lib/puppettest/railstesting.rb
+++ b/test/lib/puppettest/railstesting.rb
@@ -8,9 +8,7 @@ module PuppetTest::RailsTesting
# If we don't clean up the connection list, then the rails
# lib will still think it's connected.
- if Puppet.features.rails?
- ActiveRecord::Base.clear_active_connections!
- end
+ ActiveRecord::Base.clear_active_connections! if Puppet.features.rails?
end
def railsinit
@@ -18,9 +16,7 @@ module PuppetTest::RailsTesting
end
def railsteardown
- if Puppet[:dbadapter] != "sqlite3"
- Puppet::Rails.teardown
- end
+ Puppet::Rails.teardown if Puppet[:dbadapter] != "sqlite3"
end
def railsresource(type = "file", title = "/tmp/testing", params = {})
diff --git a/test/lib/puppettest/runnable_test.rb b/test/lib/puppettest/runnable_test.rb
index 6fcd9c6dc..ac2fb7b2e 100644
--- a/test/lib/puppettest/runnable_test.rb
+++ b/test/lib/puppettest/runnable_test.rb
@@ -23,9 +23,7 @@ module PuppetTest
# is used directly by Rspec and is not intended for develper use.
#
def runnable?
- if superclass.respond_to?(:runnable?) and not superclass.runnable?
- return false
- end
+ return false if superclass.respond_to?(:runnable?) and not superclass.runnable?
confines.each do |message, is_runnable|
is_runnable = is_runnable.call if is_runnable.respond_to?(:call)
diff --git a/test/lib/puppettest/support/assertions.rb b/test/lib/puppettest/support/assertions.rb
index 528c7b8db..b918e28f6 100644
--- a/test/lib/puppettest/support/assertions.rb
+++ b/test/lib/puppettest/support/assertions.rb
@@ -42,12 +42,8 @@ module PuppetTest
comp = nil
msg = nil
- unless events.is_a? Array
- raise Puppet::DevError, "Incorrect call of assert_events"
- end
- if resources[-1].is_a? String
- msg = resources.pop
- end
+ raise Puppet::DevError, "Incorrect call of assert_events" unless events.is_a? Array
+ msg = resources.pop if resources[-1].is_a? String
config = resources2catalog(*resources)
transaction = Puppet::Transaction.new(config)
diff --git a/test/lib/puppettest/support/helpers.rb b/test/lib/puppettest/support/helpers.rb
index 5b1872dfb..4a3a53095 100644
--- a/test/lib/puppettest/support/helpers.rb
+++ b/test/lib/puppettest/support/helpers.rb
@@ -5,17 +5,13 @@ module PuppetTest
# UID of nobody.
def nonrootuser
Etc.passwd { |user|
- if user.uid != Puppet::Util::SUIDManager.uid and user.uid > 0 and user.uid < 255
- return user
- end
+ return user if user.uid != Puppet::Util::SUIDManager.uid and user.uid > 0 and user.uid < 255
}
end
def nonrootgroup
Etc.group { |group|
- if group.gid != Puppet::Util::SUIDManager.gid and group.gid > 0 and group.gid < 255
- return group
- end
+ return group if group.gid != Puppet::Util::SUIDManager.gid and group.gid > 0 and group.gid < 255
}
end
end
diff --git a/test/lib/puppettest/support/resources.rb b/test/lib/puppettest/support/resources.rb
index 865995507..6b771dda8 100755
--- a/test/lib/puppettest/support/resources.rb
+++ b/test/lib/puppettest/support/resources.rb
@@ -15,9 +15,7 @@ module PuppetTest::Support::Resources
def treenode(config, name, *resources)
comp = tree_container name
resources.each do |resource|
- if resource.is_a?(String)
- resource = tree_resource(resource)
- end
+ resource = tree_resource(resource) if resource.is_a?(String)
config.add_edge(comp, resource)
config.add_resource resource unless config.resource(resource.ref)
end
diff --git a/test/lib/puppettest/support/utils.rb b/test/lib/puppettest/support/utils.rb
index 06ce3ad4a..61ab6e754 100644
--- a/test/lib/puppettest/support/utils.rb
+++ b/test/lib/puppettest/support/utils.rb
@@ -26,9 +26,7 @@ module PuppetTest::Support::Utils
def resources2catalog(*resources)
if resources[0].is_a?(Puppet::Resource::Catalog)
config = resources.shift
- unless resources.empty?
- resources.each { |r| config.add_resource r }
- end
+ resources.each { |r| config.add_resource r } unless resources.empty?
elsif resources[0].is_a?(Puppet::Type.type(:component))
raise ArgumentError, "resource2config() no longer accpts components"
comp = resources.shift
@@ -55,18 +53,14 @@ module PuppetTest::Support::Utils
else
puts id
end
- unless defined?(@me)
- raise "Could not retrieve user name; 'id' did not work"
- end
+ raise "Could not retrieve user name; 'id' did not work" unless defined?(@me)
end
# Define a variable that contains a group I'm in.
def set_mygroup
# retrieve the user name
group = %x{groups}.chomp.split(/ /)[0]
- unless group
- raise "Could not find group to set in @mygroup"
- end
+ raise "Could not find group to set in @mygroup" unless group
@mygroup = group
end
@@ -93,9 +87,7 @@ module PuppetTest::Support::Utils
ary = [PuppetTest.basedir, "test"]
ary += name.split("/")
file = File.join(ary)
- unless FileTest.exists?(file)
- raise Puppet::DevError, "No fakedata file #{file}"
- end
+ raise Puppet::DevError, "No fakedata file #{file}" unless FileTest.exists?(file)
return file
end
diff --git a/test/lib/puppettest/testcase.rb b/test/lib/puppettest/testcase.rb
index 3521589bf..de088a468 100644
--- a/test/lib/puppettest/testcase.rb
+++ b/test/lib/puppettest/testcase.rb
@@ -20,9 +20,7 @@ class PuppetTest::TestCase < Test::Unit::TestCase
elsif self.runnable?
return super
else
- if defined? $console
- puts "Skipping #{name}: #{@messages.join(", ")}"
- end
+ puts "Skipping #{name}: #{@messages.join(", ")}" if defined? $console
suite = Test::Unit::TestSuite.new(name)
return suite
end
diff --git a/test/lib/rake/puppet_test_loader.rb b/test/lib/rake/puppet_test_loader.rb
index be3319ccc..17d29591f 100644
--- a/test/lib/rake/puppet_test_loader.rb
+++ b/test/lib/rake/puppet_test_loader.rb
@@ -10,7 +10,5 @@ args.each { |f| require f unless f =~ /^-/ }
runner = Test::Unit::AutoRunner.new(false)
runner.process_args
-unless runner.run
- exit 14
-end
+exit 14 unless runner.run