summaryrefslogtreecommitdiffstats
path: root/test/lib/puppettest/support
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2010-07-09 18:12:17 -0700
committerMarkus Roberts <Markus@reality.com>2010-07-09 18:12:17 -0700
commit3180b9d9b2c844dade1d361326600f7001ec66dd (patch)
tree98fe7c5ac7eb942aac9c39f019a17b0b3f5a57f4 /test/lib/puppettest/support
parent543225970225de5697734bfaf0a6eee996802c04 (diff)
downloadpuppet-3180b9d9b2c844dade1d361326600f7001ec66dd.tar.gz
puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.tar.xz
puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.zip
Code smell: Two space indentation
Replaced 106806 occurances of ^( +)(.*$) with The ruby community almost universally (i.e. everyone but Luke, Markus, and the other eleven people who learned ruby in the 1900s) uses two-space indentation. 3 Examples: The code: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") becomes: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") The code: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object becomes: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object The code: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end becomes: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end
Diffstat (limited to 'test/lib/puppettest/support')
-rw-r--r--test/lib/puppettest/support/assertions.rb94
-rw-r--r--test/lib/puppettest/support/helpers.rb24
-rwxr-xr-xtest/lib/puppettest/support/resources.rb46
-rw-r--r--test/lib/puppettest/support/utils.rb276
4 files changed, 220 insertions, 220 deletions
diff --git a/test/lib/puppettest/support/assertions.rb b/test/lib/puppettest/support/assertions.rb
index 8426869eb..7f326b119 100644
--- a/test/lib/puppettest/support/assertions.rb
+++ b/test/lib/puppettest/support/assertions.rb
@@ -4,63 +4,63 @@ require 'fileutils'
module PuppetTest
- include PuppetTest::Support::Utils
- def assert_logged(level, regex, msg = nil)
- # Skip verifying logs that we're not supposed to send.
- return unless Puppet::Util::Log.sendlevel?(level)
- r = @logs.detect { |l| l.level == level and l.message =~ regex }
- @logs.clear
- assert(r, msg)
- end
+ include PuppetTest::Support::Utils
+ def assert_logged(level, regex, msg = nil)
+ # Skip verifying logs that we're not supposed to send.
+ return unless Puppet::Util::Log.sendlevel?(level)
+ r = @logs.detect { |l| l.level == level and l.message =~ regex }
+ @logs.clear
+ assert(r, msg)
+ end
- def assert_uid_gid(uid, gid, filename)
- flunk "Must be uid 0 to run these tests" unless Process.uid == 0
+ def assert_uid_gid(uid, gid, filename)
+ flunk "Must be uid 0 to run these tests" unless Process.uid == 0
- fork do
- Puppet::Util::SUIDManager.gid = gid
- Puppet::Util::SUIDManager.uid = uid
- # FIXME: use the tempfile method from puppettest.rb
- system("mkfifo #{filename}")
- f = File.open(filename, "w")
- f << "#{Puppet::Util::SUIDManager.uid}\n#{Puppet::Util::SUIDManager.gid}\n"
- yield if block_given?
- end
+ fork do
+ Puppet::Util::SUIDManager.gid = gid
+ Puppet::Util::SUIDManager.uid = uid
+ # FIXME: use the tempfile method from puppettest.rb
+ system("mkfifo #{filename}")
+ f = File.open(filename, "w")
+ f << "#{Puppet::Util::SUIDManager.uid}\n#{Puppet::Util::SUIDManager.gid}\n"
+ yield if block_given?
+ end
- # avoid a race.
- true while !File.exists? filename
+ # avoid a race.
+ true while !File.exists? filename
- f = File.open(filename, "r")
+ f = File.open(filename, "r")
- a = f.readlines
- assert_equal(uid, a[0].chomp.to_i, "UID was incorrect")
- assert_equal(gid, a[1].chomp.to_i, "GID was incorrect")
- FileUtils.rm(filename)
- end
+ a = f.readlines
+ assert_equal(uid, a[0].chomp.to_i, "UID was incorrect")
+ assert_equal(gid, a[1].chomp.to_i, "GID was incorrect")
+ FileUtils.rm(filename)
+ end
- def assert_events(events, *resources)
- trans = nil
- comp = nil
- msg = nil
+ def assert_events(events, *resources)
+ trans = nil
+ comp = nil
+ msg = nil
- raise Puppet::DevError, "Incorrect call of assert_events" unless events.is_a? Array
- msg = resources.pop if resources[-1].is_a? String
+ 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)
+ config = resources2catalog(*resources)
+ transaction = Puppet::Transaction.new(config)
- run_events(:evaluate, transaction, events, msg)
+ run_events(:evaluate, transaction, events, msg)
- transaction
- end
+ transaction
+ end
- # A simpler method that just applies what we have.
- def assert_apply(*resources)
- config = resources2catalog(*resources)
+ # A simpler method that just applies what we have.
+ def assert_apply(*resources)
+ config = resources2catalog(*resources)
- events = nil
- assert_nothing_raised("Failed to evaluate") {
- events = config.apply.events
- }
- events
- end
+ events = nil
+ assert_nothing_raised("Failed to evaluate") {
+ events = config.apply.events
+ }
+ events
+ end
end
diff --git a/test/lib/puppettest/support/helpers.rb b/test/lib/puppettest/support/helpers.rb
index 4a3a53095..75c699f72 100644
--- a/test/lib/puppettest/support/helpers.rb
+++ b/test/lib/puppettest/support/helpers.rb
@@ -1,18 +1,18 @@
require 'puppettest'
module PuppetTest
- # NOTE: currently both of these will produce bogus results on Darwin due to the wonderful
- # UID of nobody.
- def nonrootuser
- Etc.passwd { |user|
- return user if user.uid != Puppet::Util::SUIDManager.uid and user.uid > 0 and user.uid < 255
- }
- end
+ # NOTE: currently both of these will produce bogus results on Darwin due to the wonderful
+ # UID of nobody.
+ def nonrootuser
+ Etc.passwd { |user|
+ return user if user.uid != Puppet::Util::SUIDManager.uid and user.uid > 0 and user.uid < 255
+ }
+ end
- def nonrootgroup
- Etc.group { |group|
- return group if group.gid != Puppet::Util::SUIDManager.gid and group.gid > 0 and group.gid < 255
- }
- end
+ def nonrootgroup
+ Etc.group { |group|
+ 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 0eec20aae..2b922bb1e 100755
--- a/test/lib/puppettest/support/resources.rb
+++ b/test/lib/puppettest/support/resources.rb
@@ -4,32 +4,32 @@
# Copyright (c) 2006. All rights reserved.
module PuppetTest::Support::Resources
- def tree_resource(name)
- Puppet::Type.type(:file).new :title => name, :path => "/tmp/#{name}", :mode => 0755
- end
+ def tree_resource(name)
+ Puppet::Type.type(:file).new :title => name, :path => "/tmp/#{name}", :mode => 0755
+ end
- def tree_container(name)
- Puppet::Type::Component.create :name => name, :type => "yay"
- end
+ def tree_container(name)
+ Puppet::Type::Component.create :name => name, :type => "yay"
+ end
- def treenode(config, name, *resources)
- comp = tree_container name
- resources.each do |resource|
- resource = tree_resource(resource) if resource.is_a?(String)
- config.add_edge(comp, resource)
- config.add_resource resource unless config.resource(resource.ref)
- end
- comp
+ def treenode(config, name, *resources)
+ comp = tree_container name
+ resources.each do |resource|
+ resource = tree_resource(resource) if resource.is_a?(String)
+ config.add_edge(comp, resource)
+ config.add_resource resource unless config.resource(resource.ref)
end
+ comp
+ end
- def mktree
- catalog = Puppet::Resource::Catalog.new do |config|
- one = treenode(config, "one", "a", "b")
- two = treenode(config, "two", "c", "d")
- middle = treenode(config, "middle", "e", "f", two)
- top = treenode(config, "top", "g", "h", middle, one)
- end
-
- catalog
+ def mktree
+ catalog = Puppet::Resource::Catalog.new do |config|
+ one = treenode(config, "one", "a", "b")
+ two = treenode(config, "two", "c", "d")
+ middle = treenode(config, "middle", "e", "f", two)
+ top = treenode(config, "top", "g", "h", middle, one)
end
+
+ catalog
+ end
end
diff --git a/test/lib/puppettest/support/utils.rb b/test/lib/puppettest/support/utils.rb
index 466798abe..edc81d3d6 100644
--- a/test/lib/puppettest/support/utils.rb
+++ b/test/lib/puppettest/support/utils.rb
@@ -3,153 +3,153 @@ require 'puppettest'
module PuppetTest::Support
end
module PuppetTest::Support::Utils
- def gcdebug(type)
- Puppet.warning "#{type}: #{ObjectSpace.each_object(type) { |o| }}"
+ def gcdebug(type)
+ Puppet.warning "#{type}: #{ObjectSpace.each_object(type) { |o| }}"
+ end
+
+ #
+ # TODO: I think this method needs to be renamed to something a little more
+ # explanatory.
+ #
+
+ def newobj(type, name, hash)
+ transport = Puppet::TransObject.new(name, "file")
+ transport[:path] = path
+ transport[:ensure] = "file"
+ assert_nothing_raised {
+ file = transport.to_ral
+ }
+ end
+
+ # Turn a list of resources, or possibly a catalog and some resources,
+ # into a catalog object.
+ def resources2catalog(*resources)
+ if resources[0].is_a?(Puppet::Resource::Catalog)
+ config = resources.shift
+ 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
+ comp.delve
+ else
+ config = Puppet::Resource::Catalog.new
+ resources.each { |res| config.add_resource res }
end
-
- #
- # TODO: I think this method needs to be renamed to something a little more
- # explanatory.
- #
-
- def newobj(type, name, hash)
- transport = Puppet::TransObject.new(name, "file")
- transport[:path] = path
- transport[:ensure] = "file"
- assert_nothing_raised {
- file = transport.to_ral
- }
- end
-
- # Turn a list of resources, or possibly a catalog and some resources,
- # into a catalog object.
- def resources2catalog(*resources)
- if resources[0].is_a?(Puppet::Resource::Catalog)
- config = resources.shift
- 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
- comp.delve
- else
- config = Puppet::Resource::Catalog.new
- resources.each { |res| config.add_resource res }
- end
- config
- end
-
- # stop any services that might be hanging around
- def stopservices
- end
-
- # TODO: rewrite this to use the 'etc' module.
-
- # Define a variable that contains the name of my user.
- def setme
- # retrieve the user name
- id = %x{id}.chomp
- if id =~ /uid=\d+\(([^\)]+)\)/
- @me = $1
- else
- puts id
- 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]
- raise "Could not find group to set in @mygroup" unless group
- @mygroup = group
- end
-
- def run_events(type, trans, events, msg)
- case type
- when :evaluate, :rollback # things are hunky-dory
- else
- raise Puppet::DevError, "Incorrect run_events type"
- end
-
- method = type
-
- trans.send(method)
- newevents = trans.events.reject { |e| e.status == 'failure' }.collect { |e|
- e.name
- }
-
- assert_equal(events, newevents, "Incorrect #{type} #{msg} events")
-
- trans
- end
-
- def fakefile(name)
- ary = [PuppetTest.basedir, "test"]
- ary += name.split("/")
- file = File.join(ary)
- raise Puppet::DevError, "No fakedata file #{file}" unless FileTest.exists?(file)
- file
- end
-
- # wrap how to retrieve the masked mode
- def filemode(file)
- File.stat(file).mode & 007777
+ config
+ end
+
+ # stop any services that might be hanging around
+ def stopservices
+ end
+
+ # TODO: rewrite this to use the 'etc' module.
+
+ # Define a variable that contains the name of my user.
+ def setme
+ # retrieve the user name
+ id = %x{id}.chomp
+ if id =~ /uid=\d+\(([^\)]+)\)/
+ @me = $1
+ else
+ puts id
end
-
- def memory
- Puppet::Util.memory
+ 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]
+ raise "Could not find group to set in @mygroup" unless group
+ @mygroup = group
+ end
+
+ def run_events(type, trans, events, msg)
+ case type
+ when :evaluate, :rollback # things are hunky-dory
+ else
+ raise Puppet::DevError, "Incorrect run_events type"
end
- # a list of files that we can parse for testing
- def textfiles
- textdir = datadir "snippets"
- Dir.entries(textdir).reject { |f|
- f =~ /^\./ or f =~ /fail/
- }.each { |f|
- yield File.join(textdir, f)
- }
+ method = type
+
+ trans.send(method)
+ newevents = trans.events.reject { |e| e.status == 'failure' }.collect { |e|
+ e.name
+ }
+
+ assert_equal(events, newevents, "Incorrect #{type} #{msg} events")
+
+ trans
+ end
+
+ def fakefile(name)
+ ary = [PuppetTest.basedir, "test"]
+ ary += name.split("/")
+ file = File.join(ary)
+ raise Puppet::DevError, "No fakedata file #{file}" unless FileTest.exists?(file)
+ file
+ end
+
+ # wrap how to retrieve the masked mode
+ def filemode(file)
+ File.stat(file).mode & 007777
+ end
+
+ def memory
+ Puppet::Util.memory
+ end
+
+ # a list of files that we can parse for testing
+ def textfiles
+ textdir = datadir "snippets"
+ Dir.entries(textdir).reject { |f|
+ f =~ /^\./ or f =~ /fail/
+ }.each { |f|
+ yield File.join(textdir, f)
+ }
+ end
+
+ def failers
+ textdir = datadir "failers"
+ # only parse this one file now
+ files = Dir.entries(textdir).reject { |file|
+ file =~ %r{\.swp}
+ }.reject { |file|
+ file =~ %r{\.disabled}
+ }.collect { |file|
+ File.join(textdir,file)
+ }.find_all { |file|
+ FileTest.file?(file)
+ }.sort.each { |file|
+ Puppet.debug "Processing #{file}"
+ yield file
+ }
+ end
+
+ def mk_catalog(*resources)
+ if resources[0].is_a?(String)
+ name = resources.shift
+ else
+ name = :testing
end
-
- def failers
- textdir = datadir "failers"
- # only parse this one file now
- files = Dir.entries(textdir).reject { |file|
- file =~ %r{\.swp}
- }.reject { |file|
- file =~ %r{\.disabled}
- }.collect { |file|
- File.join(textdir,file)
- }.find_all { |file|
- FileTest.file?(file)
- }.sort.each { |file|
- Puppet.debug "Processing #{file}"
- yield file
- }
+ config = Puppet::Resource::Catalog.new :testing do |conf|
+ resources.each { |resource| conf.add_resource resource }
end
- def mk_catalog(*resources)
- if resources[0].is_a?(String)
- name = resources.shift
- else
- name = :testing
- end
- config = Puppet::Resource::Catalog.new :testing do |conf|
- resources.each { |resource| conf.add_resource resource }
- end
-
- config
- end
+ config
+ end
end
module PuppetTest
- include PuppetTest::Support::Utils
-
- def fakedata(dir,pat='*')
- glob = "#{basedir}/test/#{dir}/#{pat}"
- files = Dir.glob(glob,File::FNM_PATHNAME)
- raise Puppet::DevError, "No fakedata matching #{glob}" if files.empty?
- files
- end
- module_function :fakedata
+ include PuppetTest::Support::Utils
+
+ def fakedata(dir,pat='*')
+ glob = "#{basedir}/test/#{dir}/#{pat}"
+ files = Dir.glob(glob,File::FNM_PATHNAME)
+ raise Puppet::DevError, "No fakedata matching #{glob}" if files.empty?
+ files
+ end
+ module_function :fakedata
end