summaryrefslogtreecommitdiffstats
path: root/test/lib/puppettest
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
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')
-rw-r--r--test/lib/puppettest/certificates.rb102
-rw-r--r--test/lib/puppettest/exetest.rb214
-rw-r--r--test/lib/puppettest/fakes.rb306
-rw-r--r--test/lib/puppettest/fileparsing.rb34
-rw-r--r--test/lib/puppettest/filetesting.rb408
-rw-r--r--test/lib/puppettest/parsertesting.rb668
-rw-r--r--test/lib/puppettest/railstesting.rb74
-rw-r--r--test/lib/puppettest/reporttesting.rb20
-rw-r--r--test/lib/puppettest/resourcetesting.rb80
-rw-r--r--test/lib/puppettest/runnable_test.rb66
-rw-r--r--test/lib/puppettest/servertest.rb106
-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
-rw-r--r--test/lib/puppettest/testcase.rb30
16 files changed, 1274 insertions, 1274 deletions
diff --git a/test/lib/puppettest/certificates.rb b/test/lib/puppettest/certificates.rb
index 501e36a0f..34da6da40 100644
--- a/test/lib/puppettest/certificates.rb
+++ b/test/lib/puppettest/certificates.rb
@@ -3,56 +3,56 @@
require 'puppettest'
module PuppetTest::Certificates
- include PuppetTest
-
- def mkPassFile()
- keyfile = File.join(@dir, "tmpkeyfile")
- @@tmpfiles << keyfile
- system("mkdir -p #{@dir}") unless FileTest.exists?(@dir)
- File.open(keyfile, "w", 0600) { |f|
- f.print "as;dklj23rlkjzdflij23wr"
- }
-
- keyfile
- end
-
- def mkCA
- ca = nil
- assert_nothing_raised {
- ca = Puppet::SSLCertificates::CA.new
- }
-
- ca
- end
-
- def mkStore(ca)
- store = OpenSSL::X509::Store.new
- store.purpose = OpenSSL::X509::PURPOSE_SSL_CLIENT
- store.flags = OpenSSL::X509::V_FLAG_CRL_CHECK
- store.add_cert(ca.cert)
- store.add_crl(ca.crl)
- store
- end
-
- def mkcert(hostname)
- cert = nil
- assert_nothing_raised {
- cert = Puppet::SSLCertificates::Certificate.new(:name => hostname)
- cert.mkcsr
- }
-
- cert
- end
-
- def mksignedcert(ca = nil, hostname = nil)
- ca ||= mkCA()
- hostname ||= "ttltest.example.com"
-
- cert = nil
- assert_nothing_raised {
- cert, cacert = ca.sign(mkcert(hostname).mkcsr)
- }
- cert
- end
+ include PuppetTest
+
+ def mkPassFile()
+ keyfile = File.join(@dir, "tmpkeyfile")
+ @@tmpfiles << keyfile
+ system("mkdir -p #{@dir}") unless FileTest.exists?(@dir)
+ File.open(keyfile, "w", 0600) { |f|
+ f.print "as;dklj23rlkjzdflij23wr"
+ }
+
+ keyfile
+ end
+
+ def mkCA
+ ca = nil
+ assert_nothing_raised {
+ ca = Puppet::SSLCertificates::CA.new
+ }
+
+ ca
+ end
+
+ def mkStore(ca)
+ store = OpenSSL::X509::Store.new
+ store.purpose = OpenSSL::X509::PURPOSE_SSL_CLIENT
+ store.flags = OpenSSL::X509::V_FLAG_CRL_CHECK
+ store.add_cert(ca.cert)
+ store.add_crl(ca.crl)
+ store
+ end
+
+ def mkcert(hostname)
+ cert = nil
+ assert_nothing_raised {
+ cert = Puppet::SSLCertificates::Certificate.new(:name => hostname)
+ cert.mkcsr
+ }
+
+ cert
+ end
+
+ def mksignedcert(ca = nil, hostname = nil)
+ ca ||= mkCA()
+ hostname ||= "ttltest.example.com"
+
+ cert = nil
+ assert_nothing_raised {
+ cert, cacert = ca.sign(mkcert(hostname).mkcsr)
+ }
+ cert
+ end
end
diff --git a/test/lib/puppettest/exetest.rb b/test/lib/puppettest/exetest.rb
index 67b4b818c..5a2248dc9 100644
--- a/test/lib/puppettest/exetest.rb
+++ b/test/lib/puppettest/exetest.rb
@@ -1,125 +1,125 @@
require 'puppettest/servertest'
module PuppetTest::ExeTest
- include PuppetTest::ServerTest
-
- def setup
- super
- setbindir
- setlibdir
- end
-
- def bindir
- File.join(basedir, "bin")
+ include PuppetTest::ServerTest
+
+ def setup
+ super
+ setbindir
+ setlibdir
+ end
+
+ def bindir
+ File.join(basedir, "bin")
+ end
+
+ def sbindir
+ File.join(basedir, "sbin")
+ end
+
+ def setbindir
+ 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
+ ENV["RUBYLIB"] = $LOAD_PATH.find_all { |dir|
+ dir =~ /puppet/ or dir =~ /\.\./
+ }.join(":")
+ end
+
+ # Run a ruby command. This explicitly uses ruby to run stuff, since we
+ # don't necessarily know where our ruby binary is, dernit.
+ # Currently unused, because I couldn't get it to work.
+ def rundaemon(*cmd)
+ @ruby ||= %x{which ruby}.chomp
+ cmd = cmd.unshift(@ruby).join(" ")
+
+ out = nil
+ Dir.chdir(bindir) {
+ out = %x{#{@ruby} #{cmd}}
+ }
+ out
+ end
+
+ def startmasterd(args = "")
+ output = nil
+
+ manifest = mktestmanifest
+ args += " --manifest #{manifest}"
+ args += " --confdir #{Puppet[:confdir]}"
+ args += " --rundir #{File.join(Puppet[:vardir], "run")}"
+ args += " --vardir #{Puppet[:vardir]}"
+ args += " --certdnsnames #{Puppet[:certdnsnames]}"
+ args += " --masterport #{@@port}"
+ args += " --user #{Puppet::Util::SUIDManager.uid}"
+ args += " --group #{Puppet::Util::SUIDManager.gid}"
+ args += " --autosign true"
+
+ #if Puppet[:debug]
+ # args += " --debug"
+ #end
+
+ cmd = "puppetmasterd #{args}"
+
+
+ assert_nothing_raised {
+ output = %x{#{cmd}}.chomp
+ }
+ assert_equal("", output, "Puppetmasterd produced output #{output}")
+ assert($CHILD_STATUS == 0, "Puppetmasterd exit status was #{$CHILD_STATUS}")
+ sleep(1)
+
+ cleanup do
+ stopmasterd
+ sleep(1)
end
- def sbindir
- File.join(basedir, "sbin")
- end
+ manifest
+ end
- def setbindir
- 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 stopmasterd(running = true)
+ ps = Facter["ps"].value || "ps -ef"
- def setlibdir
- ENV["RUBYLIB"] = $LOAD_PATH.find_all { |dir|
- dir =~ /puppet/ or dir =~ /\.\./
- }.join(":")
- end
+ pidfile = File.join(Puppet[:vardir], "run", "puppetmasterd.pid")
- # Run a ruby command. This explicitly uses ruby to run stuff, since we
- # don't necessarily know where our ruby binary is, dernit.
- # Currently unused, because I couldn't get it to work.
- def rundaemon(*cmd)
- @ruby ||= %x{which ruby}.chomp
- cmd = cmd.unshift(@ruby).join(" ")
-
- out = nil
- Dir.chdir(bindir) {
- out = %x{#{@ruby} #{cmd}}
- }
- out
+ pid = nil
+ if FileTest.exists?(pidfile)
+ pid = File.read(pidfile).chomp.to_i
+ File.unlink(pidfile)
end
- def startmasterd(args = "")
- output = nil
-
- manifest = mktestmanifest
- args += " --manifest #{manifest}"
- args += " --confdir #{Puppet[:confdir]}"
- args += " --rundir #{File.join(Puppet[:vardir], "run")}"
- args += " --vardir #{Puppet[:vardir]}"
- args += " --certdnsnames #{Puppet[:certdnsnames]}"
- args += " --masterport #{@@port}"
- args += " --user #{Puppet::Util::SUIDManager.uid}"
- args += " --group #{Puppet::Util::SUIDManager.gid}"
- args += " --autosign true"
-
- #if Puppet[:debug]
- # args += " --debug"
- #end
-
- cmd = "puppetmasterd #{args}"
-
-
- assert_nothing_raised {
- output = %x{#{cmd}}.chomp
- }
- assert_equal("", output, "Puppetmasterd produced output #{output}")
- assert($CHILD_STATUS == 0, "Puppetmasterd exit status was #{$CHILD_STATUS}")
- sleep(1)
-
- cleanup do
- stopmasterd
- sleep(1)
+ return unless running
+ if running or pid
+ runningpid = nil
+ %x{#{ps}}.chomp.split(/\n/).each { |line|
+ if line =~ /ruby.+puppetmasterd/
+ next if line =~ /\.rb/ # skip the test script itself
+ next if line =~ /^puppet/ # skip masters running as 'puppet'
+ ary = line.sub(/^\s+/, '').split(/\s+/)
+ pid = ary[1].to_i
end
+ }
- manifest
end
- def stopmasterd(running = true)
- ps = Facter["ps"].value || "ps -ef"
-
- pidfile = File.join(Puppet[:vardir], "run", "puppetmasterd.pid")
-
- pid = nil
- if FileTest.exists?(pidfile)
- pid = File.read(pidfile).chomp.to_i
- File.unlink(pidfile)
- end
-
- return unless running
- if running or pid
- runningpid = nil
- %x{#{ps}}.chomp.split(/\n/).each { |line|
- if line =~ /ruby.+puppetmasterd/
- next if line =~ /\.rb/ # skip the test script itself
- next if line =~ /^puppet/ # skip masters running as 'puppet'
- ary = line.sub(/^\s+/, '').split(/\s+/)
- pid = ary[1].to_i
- end
- }
-
- end
-
- # we default to mandating that it's running, but teardown
- # doesn't require that
- if pid
- if pid == $PID
- raise Puppet::Error, "Tried to kill own pid"
- end
- begin
- Process.kill(:INT, pid)
- rescue
- # ignore it
- end
- end
+ # we default to mandating that it's running, but teardown
+ # doesn't require that
+ if pid
+ if pid == $PID
+ raise Puppet::Error, "Tried to kill own pid"
+ end
+ begin
+ Process.kill(:INT, pid)
+ rescue
+ # ignore it
+ end
end
+ end
- def teardown
- stopmasterd(false)
- super
- end
+ def teardown
+ stopmasterd(false)
+ super
+ end
end
diff --git a/test/lib/puppettest/fakes.rb b/test/lib/puppettest/fakes.rb
index a05d0f5c5..aaa711004 100644
--- a/test/lib/puppettest/fakes.rb
+++ b/test/lib/puppettest/fakes.rb
@@ -1,199 +1,199 @@
require 'puppettest'
module PuppetTest
- # A baseclass for the faketypes.
- class FakeModel
- include Puppet::Util
- class << self
- attr_accessor :name, :realresource
- @name = :fakeresource
- end
-
- def self.key_attributes
- @realresource.key_attributes
- end
+ # A baseclass for the faketypes.
+ class FakeModel
+ include Puppet::Util
+ class << self
+ attr_accessor :name, :realresource
+ @name = :fakeresource
+ end
- def self.validproperties
- Puppet::Type.type(@name).validproperties
- end
+ def self.key_attributes
+ @realresource.key_attributes
+ end
- def self.validproperty?(name)
- Puppet::Type.type(@name).validproperty?(name)
- end
+ def self.validproperties
+ Puppet::Type.type(@name).validproperties
+ end
- def self.to_s
- "Fake#{@name.to_s.capitalize}"
- end
+ def self.validproperty?(name)
+ Puppet::Type.type(@name).validproperty?(name)
+ end
- def [](param)
- if @realresource.attrtype(param) == :property
- @is[param]
- else
- @params[param]
- end
- end
+ def self.to_s
+ "Fake#{@name.to_s.capitalize}"
+ end
- def []=(param, value)
- param = symbolize(param)
- raise Puppet::DevError, "Invalid attribute #{param} for #{@realresource.name}" unless @realresource.valid_parameter?(param)
- if @realresource.attrtype(param) == :property
- @should[param] = value
- else
- @params[param] = value
- end
- end
+ def [](param)
+ if @realresource.attrtype(param) == :property
+ @is[param]
+ else
+ @params[param]
+ end
+ end
- def initialize(name)
- @realresource = Puppet::Type.type(self.class.name)
- raise "Could not find type #{self.class.name}" unless @realresource
- @is = {}
- @should = {}
- @params = {}
- self[@realresource.key_attributes.first] = name
- end
+ def []=(param, value)
+ param = symbolize(param)
+ raise Puppet::DevError, "Invalid attribute #{param} for #{@realresource.name}" unless @realresource.valid_parameter?(param)
+ if @realresource.attrtype(param) == :property
+ @should[param] = value
+ else
+ @params[param] = value
+ end
+ end
- def inspect
- "#{self.class.to_s.sub(/.+::/, '')}(#{super()})"
- end
+ def initialize(name)
+ @realresource = Puppet::Type.type(self.class.name)
+ raise "Could not find type #{self.class.name}" unless @realresource
+ @is = {}
+ @should = {}
+ @params = {}
+ self[@realresource.key_attributes.first] = name
+ end
- def is(param)
- @is[param]
- end
+ def inspect
+ "#{self.class.to_s.sub(/.+::/, '')}(#{super()})"
+ end
- def should(param)
- @should[param]
- end
+ def is(param)
+ @is[param]
+ end
- def to_hash
- hash = @params.dup
- [@is, @should].each do |h|
- h.each do |p, v|
- hash[p] = v
- end
- end
- hash
- end
+ def should(param)
+ @should[param]
+ end
- def name
- self[:name]
+ def to_hash
+ hash = @params.dup
+ [@is, @should].each do |h|
+ h.each do |p, v|
+ hash[p] = v
end
+ end
+ hash
end
- class FakeProvider
- attr_accessor :resource
- class << self
- attr_accessor :name, :resource_type, :methods
- end
+ def name
+ self[:name]
+ end
+ end
- # A very low number, so these never show up as defaults via the standard
- # algorithms.
- def self.defaultnum
- -50
- end
+ class FakeProvider
+ attr_accessor :resource
+ class << self
+ attr_accessor :name, :resource_type, :methods
+ end
- # Set up methods to fake things
- def self.apimethods(*ary)
- @resource_type.validproperties.each do |property|
- ary << property unless ary.include? property
- end
- attr_accessor(*ary)
+ # A very low number, so these never show up as defaults via the standard
+ # algorithms.
+ def self.defaultnum
+ -50
+ end
- @methods = ary
- end
+ # Set up methods to fake things
+ def self.apimethods(*ary)
+ @resource_type.validproperties.each do |property|
+ ary << property unless ary.include? property
+ end
+ attr_accessor(*ary)
- def self.default?
- false
- end
+ @methods = ary
+ end
- def self.initvars
- @calls = Hash.new do |hash, key|
- hash[key] = 0
- end
- end
+ def self.default?
+ false
+ end
- def self.source
- self.name
- end
+ def self.initvars
+ @calls = Hash.new do |hash, key|
+ hash[key] = 0
+ end
+ end
- def self.supports_parameter?(param)
- true
- end
+ def self.source
+ self.name
+ end
- def self.suitable?
- true
- end
+ def self.supports_parameter?(param)
+ true
+ end
- def clear
- @resource = nil
- end
+ def self.suitable?
+ true
+ end
- def initialize(resource)
- @resource = resource
- end
+ def clear
+ @resource = nil
+ end
- def properties
- self.class.resource_type.validproperties.inject({}) do |props, name|
- props[name] = self.send(name) || :absent
- props
- end
- end
+ def initialize(resource)
+ @resource = resource
end
- class FakeParsedProvider < FakeProvider
- def hash
- ret = {}
- instance_variables.each do |v|
- v = v.sub("@", '')
- if val = self.send(v)
- ret[v.intern] = val
- end
- end
+ def properties
+ self.class.resource_type.validproperties.inject({}) do |props, name|
+ props[name] = self.send(name) || :absent
+ props
+ end
+ end
+ end
- ret
+ class FakeParsedProvider < FakeProvider
+ def hash
+ ret = {}
+ instance_variables.each do |v|
+ v = v.sub("@", '')
+ if val = self.send(v)
+ ret[v.intern] = val
end
+ end
- def store(hash)
- hash.each do |n, v|
- method = n.to_s + "="
- send(method, v) if respond_to? method
- end
- end
+ ret
end
- @@fakeresources = {}
- @@fakeproviders = {}
+ def store(hash)
+ hash.each do |n, v|
+ method = n.to_s + "="
+ send(method, v) if respond_to? method
+ end
+ end
+ end
- def fakeresource(type, name, options = {})
- type = type.intern if type.is_a? String
- unless @@fakeresources.include? type
- @@fakeresources[type] = Class.new(FakeModel)
- @@fakeresources[type].name = type
+ @@fakeresources = {}
+ @@fakeproviders = {}
- resource = Puppet::Type.type(type)
- raise("Could not find type #{type}") unless resource
- @@fakeresources[type].realresource = resource
- end
+ def fakeresource(type, name, options = {})
+ type = type.intern if type.is_a? String
+ unless @@fakeresources.include? type
+ @@fakeresources[type] = Class.new(FakeModel)
+ @@fakeresources[type].name = type
- obj = @@fakeresources[type].new(name)
- options.each do |name, val|
- obj[name] = val
- end
- obj
+ resource = Puppet::Type.type(type)
+ raise("Could not find type #{type}") unless resource
+ @@fakeresources[type].realresource = resource
end
- module_function :fakeresource
+ obj = @@fakeresources[type].new(name)
+ options.each do |name, val|
+ obj[name] = val
+ end
+ obj
+ end
- def fakeprovider(type, resource)
- type = type.intern if type.is_a? String
- unless @@fakeproviders.include? type
- @@fakeproviders[type] = Class.new(FakeModel) do
- @name = type
- end
- end
+ module_function :fakeresource
- @@fakeproviders[type].new(resource)
+ def fakeprovider(type, resource)
+ type = type.intern if type.is_a? String
+ unless @@fakeproviders.include? type
+ @@fakeproviders[type] = Class.new(FakeModel) do
+ @name = type
+ end
end
- module_function :fakeprovider
+ @@fakeproviders[type].new(resource)
+ end
+
+ module_function :fakeprovider
end
diff --git a/test/lib/puppettest/fileparsing.rb b/test/lib/puppettest/fileparsing.rb
index 11de00220..914c4bcb3 100644
--- a/test/lib/puppettest/fileparsing.rb
+++ b/test/lib/puppettest/fileparsing.rb
@@ -1,26 +1,26 @@
module PuppetTest::FileParsing
- # Run an isomorphism test on our parsing process.
- def fakedataparse(*files)
- files.each do |file|
- @provider.stubs(:default_target).returns(file)
+ # Run an isomorphism test on our parsing process.
+ def fakedataparse(*files)
+ files.each do |file|
+ @provider.stubs(:default_target).returns(file)
- @provider.prefetch
+ @provider.prefetch
- text = @provider.to_file(@provider.target_records(file))
- text.gsub!(/^# HEADER.+\n/, '')
+ text = @provider.to_file(@provider.target_records(file))
+ text.gsub!(/^# HEADER.+\n/, '')
- yield if block_given?
+ yield if block_given?
- oldlines = File.readlines(file)
- newlines = text.chomp.split "\n"
- oldlines.zip(newlines).each do |old, new|
- if self.is_a?(Test::Unit::TestCase)
- assert_equal(old.chomp.gsub(/\s+/, ''), new.gsub(/\s+/, ''), "File was not written back out correctly")
- else
- new.gsub(/\s+/, '').should == old.chomp.gsub(/\s+/, '')
- end
- end
+ oldlines = File.readlines(file)
+ newlines = text.chomp.split "\n"
+ oldlines.zip(newlines).each do |old, new|
+ if self.is_a?(Test::Unit::TestCase)
+ assert_equal(old.chomp.gsub(/\s+/, ''), new.gsub(/\s+/, ''), "File was not written back out correctly")
+ else
+ new.gsub(/\s+/, '').should == old.chomp.gsub(/\s+/, '')
end
+ end
end
+ end
end
diff --git a/test/lib/puppettest/filetesting.rb b/test/lib/puppettest/filetesting.rb
index 79981ce9c..08babfe88 100644
--- a/test/lib/puppettest/filetesting.rb
+++ b/test/lib/puppettest/filetesting.rb
@@ -1,221 +1,221 @@
require 'puppettest'
module PuppetTest::FileTesting
- include PuppetTest
- def cycle(comp)
- trans = nil
- assert_nothing_raised {
- trans = comp.evaluate
- }
- assert_nothing_raised {
- trans.evaluate
- }
+ include PuppetTest
+ def cycle(comp)
+ trans = nil
+ assert_nothing_raised {
+ trans = comp.evaluate
+ }
+ assert_nothing_raised {
+ trans.evaluate
+ }
+ end
+
+ def randlist(list)
+ num = rand(4)
+ if num == 0
+ num = 1
end
+ set = []
- def randlist(list)
- num = rand(4)
- if num == 0
- num = 1
- end
- set = []
-
- ret = []
- num.times { |index|
- item = list[rand(list.length)]
- redo if set.include?(item)
-
- ret.push item
- }
- ret
- end
+ ret = []
+ num.times { |index|
+ item = list[rand(list.length)]
+ redo if set.include?(item)
- def mkranddirsandfiles(dirs = nil,files = nil,depth = 3)
- return if depth < 0
+ ret.push item
+ }
+ ret
+ end
- dirs ||= %w{This Is A Set Of Directories}
+ def mkranddirsandfiles(dirs = nil,files = nil,depth = 3)
+ return if depth < 0
- files ||= %w{and this is a set of files}
+ dirs ||= %w{This Is A Set Of Directories}
- tfiles = randlist(files)
- tdirs = randlist(dirs)
+ files ||= %w{and this is a set of files}
- tfiles.each { |file|
- File.open(file, "w") { |of|
- 4.times {
- of.puts rand(100)
- }
- }
- }
+ tfiles = randlist(files)
+ tdirs = randlist(dirs)
- tdirs.each { |dir|
- # it shouldn't already exist, but...
- unless FileTest.exists?(dir)
- Dir.mkdir(dir)
- FileUtils.cd(dir) {
- mkranddirsandfiles(dirs,files,depth - 1)
- }
- end
+ tfiles.each { |file|
+ File.open(file, "w") { |of|
+ 4.times {
+ of.puts rand(100)
}
- end
+ }
+ }
- def file_list(dir)
- list = nil
+ tdirs.each { |dir|
+ # it shouldn't already exist, but...
+ unless FileTest.exists?(dir)
+ Dir.mkdir(dir)
FileUtils.cd(dir) {
- list = %x{find . 2>/dev/null}.chomp.split(/\n/)
- }
- list
- end
-
- def assert_trees_equal(fromdir,todir)
- assert(FileTest.directory?(fromdir))
- assert(FileTest.directory?(todir))
-
- # verify the file list is the same
- fromlist = nil
- FileUtils.cd(fromdir) {
- fromlist = %x{find . 2>/dev/null}.chomp.split(/\n/).reject { |file|
- ! FileTest.readable?(file)
- }.sort
- }
- tolist = file_list(todir).sort
-
- fromlist.sort.zip(tolist.sort).each { |a,b|
- assert_equal(a, b, "Fromfile #{a} with length #{fromlist.length} does not match tofile #{b} with length #{tolist.length}")
+ mkranddirsandfiles(dirs,files,depth - 1)
}
- #assert_equal(fromlist,tolist)
-
- # and then do some verification that the files are actually set up
- # the same
- checked = 0
- fromlist.each_with_index { |file,i|
- fromfile = File.join(fromdir,file)
- tofile = File.join(todir,file)
- fromstat = File.stat(fromfile)
- tostat = File.stat(tofile)
- [:ftype,:gid,:mode,:uid].each { |method|
-
- assert_equal(
-
- fromstat.send(method),
-
- tostat.send(method)
- )
-
- next if fromstat.ftype == "directory"
- if checked < 10 and i % 3 == 0
- from = File.open(fromfile) { |f| f.read }
- to = File.open(tofile) { |f| f.read }
-
- assert_equal(from,to)
- checked += 1
- end
- }
- }
- end
-
- def random_files(dir)
- checked = 0
- list = file_list(dir)
- list.reverse.each_with_index { |file,i|
- path = File.join(dir,file)
- stat = File.stat(dir)
- if checked < 10 and (i % 3) == 2
- next unless yield path
- checked += 1
- end
- }
- end
-
- def delete_random_files(dir)
- deleted = []
- random_files(dir) { |file|
- stat = File.stat(file)
- begin
- if stat.ftype == "directory"
- false
- else
- deleted << file
- File.unlink(file)
- true
- end
- rescue => detail
- # we probably won't be able to open our own secured files
- puts detail
- false
- end
- }
-
- deleted
- end
-
- def add_random_files(dir)
- added = []
- random_files(dir) { |file|
- stat = File.stat(file)
- begin
- if stat.ftype == "directory"
- name = File.join(file,"file" + rand(100).to_s)
- File.open(name, "w") { |f|
- f.puts rand(10)
- }
- added << name
- else
- false
- end
- rescue => detail
- # we probably won't be able to open our own secured files
- puts detail
- false
- end
- }
- added
- end
-
- def modify_random_files(dir)
- modded = []
- random_files(dir) { |file|
- stat = File.stat(file)
- begin
- if stat.ftype == "directory"
- false
- else
- File.open(file, "w") { |f|
- f.puts rand(10)
- }
- modded << name
- true
- end
- rescue => detail
- # we probably won't be able to open our own secured files
- puts detail
- false
- end
- }
- modded
- end
-
- def readonly_random_files(dir)
- modded = []
- random_files(dir) { |file|
- stat = File.stat(file)
- begin
- if stat.ftype == "directory"
- File.new(file).chmod(0111)
- else
- File.new(file).chmod(0000)
- end
- modded << file
- rescue => detail
- # we probably won't be able to open our own secured files
- puts detail
- false
- end
- }
- modded
- end
-
- def conffile
- exampledir("root/etc/configfile")
- end
+ end
+ }
+ end
+
+ def file_list(dir)
+ list = nil
+ FileUtils.cd(dir) {
+ list = %x{find . 2>/dev/null}.chomp.split(/\n/)
+ }
+ list
+ end
+
+ def assert_trees_equal(fromdir,todir)
+ assert(FileTest.directory?(fromdir))
+ assert(FileTest.directory?(todir))
+
+ # verify the file list is the same
+ fromlist = nil
+ FileUtils.cd(fromdir) {
+ fromlist = %x{find . 2>/dev/null}.chomp.split(/\n/).reject { |file|
+ ! FileTest.readable?(file)
+ }.sort
+ }
+ tolist = file_list(todir).sort
+
+ fromlist.sort.zip(tolist.sort).each { |a,b|
+ assert_equal(a, b, "Fromfile #{a} with length #{fromlist.length} does not match tofile #{b} with length #{tolist.length}")
+ }
+ #assert_equal(fromlist,tolist)
+
+ # and then do some verification that the files are actually set up
+ # the same
+ checked = 0
+ fromlist.each_with_index { |file,i|
+ fromfile = File.join(fromdir,file)
+ tofile = File.join(todir,file)
+ fromstat = File.stat(fromfile)
+ tostat = File.stat(tofile)
+ [:ftype,:gid,:mode,:uid].each { |method|
+
+ assert_equal(
+
+ fromstat.send(method),
+
+ tostat.send(method)
+ )
+
+ next if fromstat.ftype == "directory"
+ if checked < 10 and i % 3 == 0
+ from = File.open(fromfile) { |f| f.read }
+ to = File.open(tofile) { |f| f.read }
+
+ assert_equal(from,to)
+ checked += 1
+ end
+ }
+ }
+ end
+
+ def random_files(dir)
+ checked = 0
+ list = file_list(dir)
+ list.reverse.each_with_index { |file,i|
+ path = File.join(dir,file)
+ stat = File.stat(dir)
+ if checked < 10 and (i % 3) == 2
+ next unless yield path
+ checked += 1
+ end
+ }
+ end
+
+ def delete_random_files(dir)
+ deleted = []
+ random_files(dir) { |file|
+ stat = File.stat(file)
+ begin
+ if stat.ftype == "directory"
+ false
+ else
+ deleted << file
+ File.unlink(file)
+ true
+ end
+ rescue => detail
+ # we probably won't be able to open our own secured files
+ puts detail
+ false
+ end
+ }
+
+ deleted
+ end
+
+ def add_random_files(dir)
+ added = []
+ random_files(dir) { |file|
+ stat = File.stat(file)
+ begin
+ if stat.ftype == "directory"
+ name = File.join(file,"file" + rand(100).to_s)
+ File.open(name, "w") { |f|
+ f.puts rand(10)
+ }
+ added << name
+ else
+ false
+ end
+ rescue => detail
+ # we probably won't be able to open our own secured files
+ puts detail
+ false
+ end
+ }
+ added
+ end
+
+ def modify_random_files(dir)
+ modded = []
+ random_files(dir) { |file|
+ stat = File.stat(file)
+ begin
+ if stat.ftype == "directory"
+ false
+ else
+ File.open(file, "w") { |f|
+ f.puts rand(10)
+ }
+ modded << name
+ true
+ end
+ rescue => detail
+ # we probably won't be able to open our own secured files
+ puts detail
+ false
+ end
+ }
+ modded
+ end
+
+ def readonly_random_files(dir)
+ modded = []
+ random_files(dir) { |file|
+ stat = File.stat(file)
+ begin
+ if stat.ftype == "directory"
+ File.new(file).chmod(0111)
+ else
+ File.new(file).chmod(0000)
+ end
+ modded << file
+ rescue => detail
+ # we probably won't be able to open our own secured files
+ puts detail
+ false
+ end
+ }
+ modded
+ end
+
+ def conffile
+ exampledir("root/etc/configfile")
+ end
end
diff --git a/test/lib/puppettest/parsertesting.rb b/test/lib/puppettest/parsertesting.rb
index fe85fe95e..bd04c1ec5 100644
--- a/test/lib/puppettest/parsertesting.rb
+++ b/test/lib/puppettest/parsertesting.rb
@@ -2,427 +2,427 @@ require 'puppettest'
require 'puppet/rails'
module PuppetTest::ParserTesting
- include PuppetTest
- AST = Puppet::Parser::AST
+ include PuppetTest
+ AST = Puppet::Parser::AST
- Compiler = Puppet::Parser::Compiler
+ Compiler = Puppet::Parser::Compiler
- # A fake class that we can use for testing evaluation.
- class FakeAST
- attr_writer :evaluate
+ # A fake class that we can use for testing evaluation.
+ class FakeAST
+ attr_writer :evaluate
- def evaluated?
- @evaluated
- end
-
- def evaluate(*args)
- @evaluated = true
- @evaluate
- end
-
- def initialize(val = nil)
- @evaluate = val if val
- end
-
- def reset
- @evaluated = nil
- end
-
- def safeevaluate(*args)
- evaluate
- end
-
- def evaluate_match(othervalue, scope, options={})
- value = evaluate
- othervalue == value
- end
+ def evaluated?
+ @evaluated
end
- def astarray(*args)
- AST::ASTArray.new(
- :children => args
- )
+ def evaluate(*args)
+ @evaluated = true
+ @evaluate
end
- def mkcompiler(parser = nil)
- node = mknode
- Compiler.new(node)
+ def initialize(val = nil)
+ @evaluate = val if val
end
- def mknode(name = nil)
- require 'puppet/node'
- Puppet::Node.new(name || "nodename")
+ def reset
+ @evaluated = nil
end
- def mkparser
- Puppet::Node::Environment.clear
- Puppet::Parser::Parser.new(Puppet::Node::Environment.new)
+ def safeevaluate(*args)
+ evaluate
end
- def mkscope(hash = {})
- parser ||= mkparser
- compiler ||= mkcompiler
- compiler.topscope.source = (parser.find_hostclass("", "") || parser.newclass(""))
-
- raise "Could not find source for scope" unless compiler.topscope.source
- # Make the 'main' stuff
- compiler.send(:evaluate_main)
- compiler.topscope
+ def evaluate_match(othervalue, scope, options={})
+ value = evaluate
+ othervalue == value
end
-
- def classobj(name, hash = {})
- hash[:file] ||= __FILE__
- hash[:line] ||= __LINE__
- hash[:type] ||= name
- AST::HostClass.new(hash)
+ end
+
+ def astarray(*args)
+ AST::ASTArray.new(
+ :children => args
+ )
+ end
+
+ def mkcompiler(parser = nil)
+ node = mknode
+ Compiler.new(node)
+ end
+
+ def mknode(name = nil)
+ require 'puppet/node'
+ Puppet::Node.new(name || "nodename")
+ end
+
+ def mkparser
+ Puppet::Node::Environment.clear
+ Puppet::Parser::Parser.new(Puppet::Node::Environment.new)
+ end
+
+ def mkscope(hash = {})
+ parser ||= mkparser
+ compiler ||= mkcompiler
+ compiler.topscope.source = (parser.find_hostclass("", "") || parser.newclass(""))
+
+ raise "Could not find source for scope" unless compiler.topscope.source
+ # Make the 'main' stuff
+ compiler.send(:evaluate_main)
+ compiler.topscope
+ end
+
+ def classobj(name, hash = {})
+ hash[:file] ||= __FILE__
+ hash[:line] ||= __LINE__
+ hash[:type] ||= name
+ AST::HostClass.new(hash)
+ end
+
+ def tagobj(*names)
+ args = {}
+ newnames = names.collect do |name|
+ if name.is_a? AST
+ name
+ else
+ nameobj(name)
+ end
end
+ args[:type] = astarray(*newnames)
+ assert_nothing_raised("Could not create tag #{names.inspect}") {
+ return AST::Tag.new(args)
+ }
+ end
- def tagobj(*names)
- args = {}
- newnames = names.collect do |name|
- if name.is_a? AST
- name
- else
- nameobj(name)
- end
- end
- args[:type] = astarray(*newnames)
- assert_nothing_raised("Could not create tag #{names.inspect}") {
- return AST::Tag.new(args)
- }
- end
+ def resourcedef(type, title, params)
+ title = stringobj(title) unless title.is_a?(AST)
+ assert_nothing_raised("Could not create #{type} #{title}") {
- def resourcedef(type, title, params)
- title = stringobj(title) unless title.is_a?(AST)
- assert_nothing_raised("Could not create #{type} #{title}") {
+ return AST::Resource.new(
- return AST::Resource.new(
+ :file => __FILE__,
+ :line => __LINE__,
+ :title => title,
+ :type => type,
- :file => __FILE__,
- :line => __LINE__,
- :title => title,
- :type => type,
+ :parameters => resourceinst(params)
+ )
+ }
+ end
- :parameters => resourceinst(params)
- )
- }
- end
+ def virt_resourcedef(*args)
+ res = resourcedef(*args)
+ res.virtual = true
+ res
+ end
- def virt_resourcedef(*args)
- res = resourcedef(*args)
- res.virtual = true
- res
- end
+ def resourceoverride(type, title, params)
+ assert_nothing_raised("Could not create #{type} #{name}") {
- def resourceoverride(type, title, params)
- assert_nothing_raised("Could not create #{type} #{name}") {
+ return AST::ResourceOverride.new(
- return AST::ResourceOverride.new(
+ :file => __FILE__,
+ :line => __LINE__,
+ :object => resourceref(type, title),
- :file => __FILE__,
- :line => __LINE__,
- :object => resourceref(type, title),
+ :type => type,
+ :parameters => resourceinst(params)
+ )
+ }
+ end
- :type => type,
- :parameters => resourceinst(params)
- )
- }
- end
+ def resourceref(type, title)
+ assert_nothing_raised("Could not create #{type} #{title}") {
- def resourceref(type, title)
- assert_nothing_raised("Could not create #{type} #{title}") {
+ return AST::ResourceReference.new(
- return AST::ResourceReference.new(
+ :file => __FILE__,
+ :line => __LINE__,
+ :type => type,
- :file => __FILE__,
- :line => __LINE__,
- :type => type,
+ :title => stringobj(title)
+ )
+ }
+ end
- :title => stringobj(title)
- )
- }
- end
-
- def fileobj(path, hash = {"owner" => "root"})
- assert_nothing_raised("Could not create file #{path}") {
- return resourcedef("file", path, hash)
- }
- end
+ def fileobj(path, hash = {"owner" => "root"})
+ assert_nothing_raised("Could not create file #{path}") {
+ return resourcedef("file", path, hash)
+ }
+ end
- def nameobj(name)
- assert_nothing_raised("Could not create name #{name}") {
+ def nameobj(name)
+ assert_nothing_raised("Could not create name #{name}") {
- return AST::Name.new(
+ return AST::Name.new(
- :file => tempfile,
+ :file => tempfile,
- :line => rand(100),
- :value => name
- )
- }
- end
+ :line => rand(100),
+ :value => name
+ )
+ }
+ end
- def typeobj(name)
- assert_nothing_raised("Could not create type #{name}") {
+ def typeobj(name)
+ assert_nothing_raised("Could not create type #{name}") {
- return AST::Type.new(
+ return AST::Type.new(
- :file => tempfile,
+ :file => tempfile,
- :line => rand(100),
- :value => name
- )
- }
- end
+ :line => rand(100),
+ :value => name
+ )
+ }
+ end
- def nodedef(name)
- assert_nothing_raised("Could not create node #{name}") {
+ def nodedef(name)
+ assert_nothing_raised("Could not create node #{name}") {
- return AST::NodeDef.new(
+ return AST::NodeDef.new(
- :file => tempfile,
+ :file => tempfile,
- :line => rand(100),
- :names => nameobj(name),
+ :line => rand(100),
+ :names => nameobj(name),
- :code => AST::ASTArray.new(
+ :code => AST::ASTArray.new(
- :children => [
- varobj("#{name}var", "#{name}value"),
+ :children => [
+ varobj("#{name}var", "#{name}value"),
- fileobj("/#{name}")
- ]
- )
- )
- }
- end
-
- def resourceinst(hash)
- assert_nothing_raised("Could not create resource instance") {
- params = hash.collect { |param, value|
- resourceparam(param, value)
- }
-
- return AST::ResourceInstance.new(
-
- :file => tempfile,
-
- :line => rand(100),
- :children => params
- )
- }
- end
+ fileobj("/#{name}")
+ ]
+ )
+ )
+ }
+ end
- def resourceparam(param, value)
- # Allow them to pass non-strings in
- value = stringobj(value) if value.is_a?(String)
- assert_nothing_raised("Could not create param #{param}") {
+ def resourceinst(hash)
+ assert_nothing_raised("Could not create resource instance") {
+ params = hash.collect { |param, value|
+ resourceparam(param, value)
+ }
- return AST::ResourceParam.new(
+ return AST::ResourceInstance.new(
- :file => tempfile,
+ :file => tempfile,
- :line => rand(100),
- :param => param,
- :value => value
- )
- }
- end
+ :line => rand(100),
+ :children => params
+ )
+ }
+ end
- def stringobj(value)
+ def resourceparam(param, value)
+ # Allow them to pass non-strings in
+ value = stringobj(value) if value.is_a?(String)
+ assert_nothing_raised("Could not create param #{param}") {
- AST::String.new(
+ return AST::ResourceParam.new(
- :file => tempfile,
+ :file => tempfile,
- :line => rand(100),
- :value => value
- )
- end
+ :line => rand(100),
+ :param => param,
+ :value => value
+ )
+ }
+ end
- def varobj(name, value)
- value = stringobj(value) unless value.is_a? AST
- assert_nothing_raised("Could not create #{name} code") {
+ def stringobj(value)
- return AST::VarDef.new(
+ AST::String.new(
- :file => tempfile,
+ :file => tempfile,
- :line => rand(100),
- :name => nameobj(name),
- :value => value
- )
- }
- end
+ :line => rand(100),
+ :value => value
+ )
+ end
- def varref(name)
- assert_nothing_raised("Could not create #{name} variable") {
+ def varobj(name, value)
+ value = stringobj(value) unless value.is_a? AST
+ assert_nothing_raised("Could not create #{name} code") {
- return AST::Variable.new(
+ return AST::VarDef.new(
- :file => __FILE__,
- :line => __LINE__,
+ :file => tempfile,
- :value => name
- )
- }
- end
+ :line => rand(100),
+ :name => nameobj(name),
+ :value => value
+ )
+ }
+ end
- def argobj(name, value)
- assert_nothing_raised("Could not create #{name} compargument") {
- return AST::CompArgument.new(
- :children => [nameobj(name), stringobj(value)]
- )
- }
- end
+ def varref(name)
+ assert_nothing_raised("Could not create #{name} variable") {
- def defaultobj(type, params)
- pary = []
- params.each { |p,v|
+ return AST::Variable.new(
- pary << AST::ResourceParam.new(
+ :file => __FILE__,
+ :line => __LINE__,
- :file => __FILE__,
- :line => __LINE__,
- :param => p,
+ :value => name
+ )
+ }
+ end
- :value => stringobj(v)
- )
- }
+ def argobj(name, value)
+ assert_nothing_raised("Could not create #{name} compargument") {
+ return AST::CompArgument.new(
+ :children => [nameobj(name), stringobj(value)]
+ )
+ }
+ end
- past = AST::ASTArray.new(
+ def defaultobj(type, params)
+ pary = []
+ params.each { |p,v|
- :file => __FILE__,
- :line => __LINE__,
+ pary << AST::ResourceParam.new(
- :children => pary
- )
+ :file => __FILE__,
+ :line => __LINE__,
+ :param => p,
- assert_nothing_raised("Could not create defaults for #{type}") {
+ :value => stringobj(v)
+ )
+ }
- return AST::ResourceDefaults.new(
+ past = AST::ASTArray.new(
- :file => __FILE__,
- :line => __LINE__,
- :type => type,
+ :file => __FILE__,
+ :line => __LINE__,
- :parameters => past
- )
- }
- end
+ :children => pary
+ )
- def taggedobj(name, ftype = :statement)
- functionobj("tagged", name, ftype)
- end
+ assert_nothing_raised("Could not create defaults for #{type}") {
- def functionobj(function, name, ftype = :statement)
- func = nil
- assert_nothing_raised do
+ return AST::ResourceDefaults.new(
- func = Puppet::Parser::AST::Function.new(
+ :file => __FILE__,
+ :line => __LINE__,
+ :type => type,
- :name => function,
- :ftype => ftype,
+ :parameters => past
+ )
+ }
+ end
- :arguments => AST::ASTArray.new(
- :children => [nameobj(name)]
- )
- )
- end
+ def taggedobj(name, ftype = :statement)
+ functionobj("tagged", name, ftype)
+ end
- func
- end
+ def functionobj(function, name, ftype = :statement)
+ func = nil
+ assert_nothing_raised do
- # This assumes no nodes
- def assert_creates(manifest, *files)
- oldmanifest = Puppet[:manifest]
- Puppet[:manifest] = manifest
+ func = Puppet::Parser::AST::Function.new(
- catalog = Puppet::Parser::Compiler.new(mknode).compile.to_ral
- catalog.apply
+ :name => function,
+ :ftype => ftype,
- files.each do |file|
- assert(FileTest.exists?(file), "Did not create #{file}")
- end
- ensure
- Puppet[:manifest] = oldmanifest
+ :arguments => AST::ASTArray.new(
+ :children => [nameobj(name)]
+ )
+ )
end
- def mk_transobject(file = "/etc/passwd")
- obj = nil
- assert_nothing_raised {
- obj = Puppet::TransObject.new("file", file)
- obj["owner"] = "root"
- obj["mode"] = "644"
- }
+ func
+ end
- obj
- end
-
- def mk_transbucket(*resources)
- bucket = nil
- assert_nothing_raised {
- bucket = Puppet::TransBucket.new
- bucket.name = "yayname"
- bucket.type = "yaytype"
- }
+ # This assumes no nodes
+ def assert_creates(manifest, *files)
+ oldmanifest = Puppet[:manifest]
+ Puppet[:manifest] = manifest
- resources.each { |o| bucket << o }
+ catalog = Puppet::Parser::Compiler.new(mknode).compile.to_ral
+ catalog.apply
- bucket
+ files.each do |file|
+ assert(FileTest.exists?(file), "Did not create #{file}")
end
-
- # Make a tree of resources, yielding if desired
- def mk_transtree(depth = 4, width = 2)
- top = nil
- assert_nothing_raised {
- top = Puppet::TransBucket.new
- top.name = "top"
- top.type = "bucket"
- }
-
- bucket = top
-
- file = tempfile
- depth.times do |i|
- resources = []
- width.times do |j|
- path = tempfile + i.to_s
- obj = Puppet::TransObject.new("file", path)
- obj["owner"] = "root"
- obj["mode"] = "644"
-
- # Yield, if they want
- yield(obj, i, j) if block_given?
-
- resources << obj
- end
-
- newbucket = mk_transbucket(*resources)
-
- bucket.push newbucket
- bucket = newbucket
- end
-
- top
+ ensure
+ Puppet[:manifest] = oldmanifest
+ end
+
+ def mk_transobject(file = "/etc/passwd")
+ obj = nil
+ assert_nothing_raised {
+ obj = Puppet::TransObject.new("file", file)
+ obj["owner"] = "root"
+ obj["mode"] = "644"
+ }
+
+ obj
+ end
+
+ def mk_transbucket(*resources)
+ bucket = nil
+ assert_nothing_raised {
+ bucket = Puppet::TransBucket.new
+ bucket.name = "yayname"
+ bucket.type = "yaytype"
+ }
+
+ resources.each { |o| bucket << o }
+
+ bucket
+ end
+
+ # Make a tree of resources, yielding if desired
+ def mk_transtree(depth = 4, width = 2)
+ top = nil
+ assert_nothing_raised {
+ top = Puppet::TransBucket.new
+ top.name = "top"
+ top.type = "bucket"
+ }
+
+ bucket = top
+
+ file = tempfile
+ depth.times do |i|
+ resources = []
+ width.times do |j|
+ path = tempfile + i.to_s
+ obj = Puppet::TransObject.new("file", path)
+ obj["owner"] = "root"
+ obj["mode"] = "644"
+
+ # Yield, if they want
+ yield(obj, i, j) if block_given?
+
+ resources << obj
+ end
+
+ newbucket = mk_transbucket(*resources)
+
+ bucket.push newbucket
+ bucket = newbucket
end
- # Take a list of AST resources, evaluate them, and return the results
- def assert_evaluate(children)
- top = nil
- assert_nothing_raised("Could not create top object") {
- top = AST::ASTArray.new(
- :children => children
- )
- }
-
- trans = nil
- scope = nil
- assert_nothing_raised {
- scope = Puppet::Parser::Scope.new
- trans = scope.evaluate(:ast => top)
- }
-
- trans
- end
+ top
+ end
+
+ # Take a list of AST resources, evaluate them, and return the results
+ def assert_evaluate(children)
+ top = nil
+ assert_nothing_raised("Could not create top object") {
+ top = AST::ASTArray.new(
+ :children => children
+ )
+ }
+
+ trans = nil
+ scope = nil
+ assert_nothing_raised {
+ scope = Puppet::Parser::Scope.new
+ trans = scope.evaluate(:ast => top)
+ }
+
+ trans
+ end
end
diff --git a/test/lib/puppettest/railstesting.rb b/test/lib/puppettest/railstesting.rb
index 2240c739a..e05511e3b 100644
--- a/test/lib/puppettest/railstesting.rb
+++ b/test/lib/puppettest/railstesting.rb
@@ -1,52 +1,52 @@
module PuppetTest::RailsTesting
- Parser = Puppet::Parser
- AST = Puppet::Parser::AST
- include PuppetTest::ParserTesting
+ Parser = Puppet::Parser
+ AST = Puppet::Parser::AST
+ include PuppetTest::ParserTesting
- def teardown
- super
+ def teardown
+ super
- # If we don't clean up the connection list, then the rails
- # lib will still think it's connected.
- ActiveRecord::Base.clear_active_connections! if Puppet.features.rails?
- end
+ # If we don't clean up the connection list, then the rails
+ # lib will still think it's connected.
+ ActiveRecord::Base.clear_active_connections! if Puppet.features.rails?
+ end
- def railsinit
- Puppet::Rails.init
- end
+ def railsinit
+ Puppet::Rails.init
+ end
- def railsteardown
- Puppet::Rails.teardown if Puppet[:dbadapter] != "sqlite3"
- end
+ def railsteardown
+ Puppet::Rails.teardown if Puppet[:dbadapter] != "sqlite3"
+ end
- def railsresource(type = "file", title = "/tmp/testing", params = {})
- railsteardown
- railsinit
+ def railsresource(type = "file", title = "/tmp/testing", params = {})
+ railsteardown
+ railsinit
- # We need a host for resources
- #host = Puppet::Rails::Host.new(:name => Facter.value("hostname"))
+ # We need a host for resources
+ #host = Puppet::Rails::Host.new(:name => Facter.value("hostname"))
- # Now build a resource
- resources = []
+ # Now build a resource
+ resources = []
- resources << mkresource(
- :type => type, :title => title, :exported => true,
+ resources << mkresource(
+ :type => type, :title => title, :exported => true,
- :parameters => params)
+ :parameters => params)
- # Now collect our facts
- facts = Facter.to_hash
+ # Now collect our facts
+ facts = Facter.to_hash
- # Now try storing our crap
- host = nil
- node = mknode(facts["hostname"])
- node.parameters = facts
- assert_nothing_raised {
- host = Puppet::Rails::Host.store(node, resources)
- }
+ # Now try storing our crap
+ host = nil
+ node = mknode(facts["hostname"])
+ node.parameters = facts
+ assert_nothing_raised {
+ host = Puppet::Rails::Host.store(node, resources)
+ }
- # Now save the whole thing
- host.save
- end
+ # Now save the whole thing
+ host.save
+ end
end
diff --git a/test/lib/puppettest/reporttesting.rb b/test/lib/puppettest/reporttesting.rb
index b0cb0f2ec..448a6a9d8 100644
--- a/test/lib/puppettest/reporttesting.rb
+++ b/test/lib/puppettest/reporttesting.rb
@@ -1,16 +1,16 @@
module PuppetTest::Reporttesting
- def fakereport
- # Create a bunch of log messages in an array.
- report = Puppet::Transaction::Report.new
+ def fakereport
+ # Create a bunch of log messages in an array.
+ report = Puppet::Transaction::Report.new
- 3.times { |i|
- # We have to use warning so that the logs always happen
- log = Puppet.warning("Report test message #{i}")
+ 3.times { |i|
+ # We have to use warning so that the logs always happen
+ log = Puppet.warning("Report test message #{i}")
- report << log
- }
+ report << log
+ }
- report
- end
+ report
+ end
end
diff --git a/test/lib/puppettest/resourcetesting.rb b/test/lib/puppettest/resourcetesting.rb
index 0949dfff4..ea8bec01b 100644
--- a/test/lib/puppettest/resourcetesting.rb
+++ b/test/lib/puppettest/resourcetesting.rb
@@ -1,54 +1,54 @@
module PuppetTest::ResourceTesting
- Parser = Puppet::Parser
- AST = Puppet::Parser::AST
+ Parser = Puppet::Parser
+ AST = Puppet::Parser::AST
- def mkevaltest(parser = nil)
- parser ||= mkparser
+ def mkevaltest(parser = nil)
+ parser ||= mkparser
- @parser.newdefine(
- "evaltest",
+ @parser.newdefine(
+ "evaltest",
- :arguments => [%w{one}, ["two", stringobj("755")]],
+ :arguments => [%w{one}, ["two", stringobj("755")]],
- :code => resourcedef(
- "file", "/tmp",
+ :code => resourcedef(
+ "file", "/tmp",
- "owner" => varref("one"), "mode" => varref("two"))
- )
+ "owner" => varref("one"), "mode" => varref("two"))
+ )
+ end
+
+ def mkresource(args = {})
+ args[:source] ||= "source"
+ args[:scope] ||= mkscope
+
+ type = args[:type] || "resource"
+ title = args[:title] || "testing"
+ args.delete(:type)
+ args.delete(:title)
+ {:source => "source", :scope => "scope"}.each do |param, value|
+ args[param] ||= value
end
- def mkresource(args = {})
- args[:source] ||= "source"
- args[:scope] ||= mkscope
-
- type = args[:type] || "resource"
- title = args[:title] || "testing"
- args.delete(:type)
- args.delete(:title)
- {:source => "source", :scope => "scope"}.each do |param, value|
- args[param] ||= value
- end
-
- params = args[:parameters] || {:one => "yay", :three => "rah"}
- if args[:parameters] == :none
- args.delete(:parameters)
- else
- args[:parameters] = paramify args[:source], params
- end
-
- Parser::Resource.new(type, title, args)
+ params = args[:parameters] || {:one => "yay", :three => "rah"}
+ if args[:parameters] == :none
+ args.delete(:parameters)
+ else
+ args[:parameters] = paramify args[:source], params
end
- def param(name, value, source)
- Parser::Resource::Param.new(:name => name, :value => value, :source => source)
- end
+ Parser::Resource.new(type, title, args)
+ end
+
+ def param(name, value, source)
+ Parser::Resource::Param.new(:name => name, :value => value, :source => source)
+ end
- def paramify(source, hash)
- hash.collect do |name, value|
- Parser::Resource::Param.new(
- :name => name, :value => value, :source => source
- )
- end
+ def paramify(source, hash)
+ hash.collect do |name, value|
+ Parser::Resource::Param.new(
+ :name => name, :value => value, :source => source
+ )
end
+ end
end
diff --git a/test/lib/puppettest/runnable_test.rb b/test/lib/puppettest/runnable_test.rb
index ac2fb7b2e..bb8d89e27 100644
--- a/test/lib/puppettest/runnable_test.rb
+++ b/test/lib/puppettest/runnable_test.rb
@@ -1,43 +1,43 @@
# Manage whether a test is runnable.
module PuppetTest
- module RunnableTest
- # Confine this example group based on specified criteria. This can be
- # a message and its related test either as a hash or as a single
- # message argument and a block to be evaluated at the time the confine
- # is checked.
- #
- # Examples:
- #
- # confine "Rails is not available" => Puppet.features.rails?
- #
- # confine("ActiveRecord 2.1.x") { ::ActiveRecord::VERSION::MAJOR == 2 and ::ActiveRecord::VERSION::MINOR <= 1 }
- #
- def confine(hash_or_message, &block)
- hash = block_given? ? {hash_or_message => block} : hash_or_message
- confines.update hash
- end
+ module RunnableTest
+ # Confine this example group based on specified criteria. This can be
+ # a message and its related test either as a hash or as a single
+ # message argument and a block to be evaluated at the time the confine
+ # is checked.
+ #
+ # Examples:
+ #
+ # confine "Rails is not available" => Puppet.features.rails?
+ #
+ # confine("ActiveRecord 2.1.x") { ::ActiveRecord::VERSION::MAJOR == 2 and ::ActiveRecord::VERSION::MINOR <= 1 }
+ #
+ def confine(hash_or_message, &block)
+ hash = block_given? ? {hash_or_message => block} : hash_or_message
+ confines.update hash
+ end
- # Check all confines for a given example group, starting with any
- # specified in the parent example group. If any confine test is false,
- # the example group is not runnable (and will be skipped). Note: This
- # is used directly by Rspec and is not intended for develper use.
- #
- def runnable?
- return false if superclass.respond_to?(:runnable?) and not superclass.runnable?
+ # Check all confines for a given example group, starting with any
+ # specified in the parent example group. If any confine test is false,
+ # the example group is not runnable (and will be skipped). Note: This
+ # is used directly by Rspec and is not intended for develper use.
+ #
+ def runnable?
+ 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)
- messages << message unless is_runnable
- end
+ confines.each do |message, is_runnable|
+ is_runnable = is_runnable.call if is_runnable.respond_to?(:call)
+ messages << message unless is_runnable
+ end
- messages.empty?
- end
+ messages.empty?
+ end
- def messages; @messages ||= [] end
+ def messages; @messages ||= [] end
- private
+ private
- def confines; @confines ||= {} end
- end
+ def confines; @confines ||= {} end
+ end
end
diff --git a/test/lib/puppettest/servertest.rb b/test/lib/puppettest/servertest.rb
index 4efcedddf..4174c1a3d 100644
--- a/test/lib/puppettest/servertest.rb
+++ b/test/lib/puppettest/servertest.rb
@@ -2,73 +2,73 @@ require 'puppettest'
require 'puppet/network/http_server/webrick'
module PuppetTest::ServerTest
- include PuppetTest
- def setup
- super
+ include PuppetTest
+ def setup
+ super
- if defined?(@@port)
- @@port += 1
- else
- @@port = 20000
- end
+ if defined?(@@port)
+ @@port += 1
+ else
+ @@port = 20000
end
+ end
- # create a simple manifest that just creates a file
- def mktestmanifest
- file = File.join(Puppet[:confdir], "#{(self.class.to_s + "test")}site.pp")
- #@createdfile = File.join(tmpdir, self.class.to_s + "manifesttesting" +
- # "_#{@method_name}")
- @createdfile = tempfile
+ # create a simple manifest that just creates a file
+ def mktestmanifest
+ file = File.join(Puppet[:confdir], "#{(self.class.to_s + "test")}site.pp")
+ #@createdfile = File.join(tmpdir, self.class.to_s + "manifesttesting" +
+ # "_#{@method_name}")
+ @createdfile = tempfile
- File.open(file, "w") { |f|
- f.puts "file { \"%s\": ensure => file, mode => 755 }\n" % @createdfile
- }
+ File.open(file, "w") { |f|
+ f.puts "file { \"%s\": ensure => file, mode => 755 }\n" % @createdfile
+ }
- @@tmpfiles << @createdfile
- @@tmpfiles << file
+ @@tmpfiles << @createdfile
+ @@tmpfiles << file
- file
- end
+ file
+ end
- # create a server, forked into the background
- def mkserver(handlers = nil)
- Puppet[:name] = "puppetmasterd"
- # our default handlers
- unless handlers
- handlers = {
- :CA => {}, # so that certs autogenerate
- :Master => {
- :Manifest => mktestmanifest,
- :UseNodes => false
- },
- }
- end
+ # create a server, forked into the background
+ def mkserver(handlers = nil)
+ Puppet[:name] = "puppetmasterd"
+ # our default handlers
+ unless handlers
+ handlers = {
+ :CA => {}, # so that certs autogenerate
+ :Master => {
+ :Manifest => mktestmanifest,
+ :UseNodes => false
+ },
+ }
+ end
- # then create the actual server
- server = nil
- assert_nothing_raised {
+ # then create the actual server
+ server = nil
+ assert_nothing_raised {
- server = Puppet::Network::HTTPServer::WEBrick.new(
+ server = Puppet::Network::HTTPServer::WEBrick.new(
- :Port => @@port,
+ :Port => @@port,
- :Handlers => handlers
- )
- }
+ :Handlers => handlers
+ )
+ }
- # fork it
- spid = fork {
- trap(:INT) { server.shutdown }
- server.start
- }
+ # fork it
+ spid = fork {
+ trap(:INT) { server.shutdown }
+ server.start
+ }
- # and store its pid for killing
- @@tmppids << spid
+ # and store its pid for killing
+ @@tmppids << spid
- # give the server a chance to do its thing
- sleep 1
- spid
- end
+ # give the server a chance to do its thing
+ sleep 1
+ spid
+ end
end
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
diff --git a/test/lib/puppettest/testcase.rb b/test/lib/puppettest/testcase.rb
index de088a468..b1b22e524 100644
--- a/test/lib/puppettest/testcase.rb
+++ b/test/lib/puppettest/testcase.rb
@@ -8,21 +8,21 @@ require 'puppettest/runnable_test'
require 'test/unit'
class PuppetTest::TestCase < Test::Unit::TestCase
- include PuppetTest
- extend PuppetTest::RunnableTest
+ include PuppetTest
+ extend PuppetTest::RunnableTest
- def self.suite
- # Always skip this parent class. It'd be nice if there were a
- # "supported" way to do this.
- if self == PuppetTest::TestCase
- suite = Test::Unit::TestSuite.new(name)
- return suite
- elsif self.runnable?
- return super
- else
- puts "Skipping #{name}: #{@messages.join(", ")}" if defined? $console
- suite = Test::Unit::TestSuite.new(name)
- return suite
- end
+ def self.suite
+ # Always skip this parent class. It'd be nice if there were a
+ # "supported" way to do this.
+ if self == PuppetTest::TestCase
+ suite = Test::Unit::TestSuite.new(name)
+ return suite
+ elsif self.runnable?
+ return super
+ else
+ puts "Skipping #{name}: #{@messages.join(", ")}" if defined? $console
+ suite = Test::Unit::TestSuite.new(name)
+ return suite
end
+ end
end