diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-11-08 05:22:24 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-11-08 05:22:24 +0000 |
| commit | 744ded30a02883dd8ce5fbf2b847f10acb226d6e (patch) | |
| tree | d962b7b21f3a5d20dafd8e7f862c23a2449c2c9b /test | |
| parent | dc4d98091a5566be289830839f1d6eb39367b42c (diff) | |
| download | puppet-744ded30a02883dd8ce5fbf2b847f10acb226d6e.tar.gz puppet-744ded30a02883dd8ce5fbf2b847f10acb226d6e.tar.xz puppet-744ded30a02883dd8ce5fbf2b847f10acb226d6e.zip | |
Merging the code over from the oscar branch. I will now be doing all development in the trunk again, except for larger changes, which will still get their own branch. This is a merge of the changes from revision 1826 to revision 1834.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1835 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test')
| -rw-r--r-- | test/Rakefile | 1 | ||||
| -rwxr-xr-x | test/certmgr/certmgr.rb | 69 | ||||
| -rwxr-xr-x | test/certmgr/inventory.rb | 79 | ||||
| -rwxr-xr-x | test/client/networkclient.rb | 20 | ||||
| -rwxr-xr-x | test/language/parser.rb | 23 | ||||
| -rwxr-xr-x | test/lib/puppettest.rb | 23 | ||||
| -rw-r--r-- | test/lib/puppettest/certificates.rb | 61 | ||||
| -rw-r--r-- | test/lib/puppettest/parsertesting.rb | 2 | ||||
| -rwxr-xr-x | test/other/features.rb | 60 | ||||
| -rwxr-xr-x | test/other/metrics.rb | 9 | ||||
| -rwxr-xr-x | test/other/report.rb | 3 | ||||
| -rwxr-xr-x | test/puppet/defaults.rb | 2 | ||||
| -rwxr-xr-x | test/types/exec.rb | 2 | ||||
| -rwxr-xr-x | test/types/file.rb | 40 | ||||
| -rwxr-xr-x | test/types/group.rb | 8 | ||||
| -rwxr-xr-x | test/types/package.rb | 2 | ||||
| -rwxr-xr-x | test/types/type.rb | 9 | ||||
| -rwxr-xr-x | test/util/posixtest.rb | 173 | ||||
| -rwxr-xr-x | test/util/utiltest.rb | 99 |
19 files changed, 471 insertions, 214 deletions
diff --git a/test/Rakefile b/test/Rakefile index 3918d127e..4c7ca6ef3 100644 --- a/test/Rakefile +++ b/test/Rakefile @@ -1,5 +1,6 @@ require 'rake/testtask' require 'find' + include Find include FileTest diff --git a/test/certmgr/certmgr.rb b/test/certmgr/certmgr.rb index 5e2210913..d9349a9c0 100755 --- a/test/certmgr/certmgr.rb +++ b/test/certmgr/certmgr.rb @@ -5,6 +5,7 @@ $:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/ require 'puppet' require 'puppet/sslcertificates.rb' require 'puppettest' +require 'puppettest/certificates' # so, what kind of things do we want to test? @@ -16,7 +17,7 @@ require 'puppettest' # and test whether we've got things in the right scopes class TestCertMgr < Test::Unit::TestCase - include PuppetTest + include PuppetTest::Certificates def setup super #@dir = File.join(Puppet[:certdir], "testing") @@ -24,28 +25,6 @@ class TestCertMgr < Test::Unit::TestCase system("mkdir -p %s" % @dir) end - def mkPassFile() - keyfile = File.join(@dir, "tmpkeyfile") - @@tmpfiles << keyfile - unless FileTest.exists?(@dir) - system("mkdir -p %s" % @dir) - end - File.open(keyfile, "w", 0600) { |f| - f.print "as;dklj23rlkjzdflij23wr" - } - - return keyfile - end - - def mkCA - ca = nil - assert_nothing_raised { - ca = Puppet::SSLCertificates::CA.new() - } - - return ca - end - def testCreateSelfSignedCertificate cert = nil name = "testing" @@ -191,16 +170,6 @@ class TestCertMgr < Test::Unit::TestCase assert_equal($?,0) assert_equal(File.join(Puppet[:certdir], "signedcertest.pem: OK\n"), output) end - - def mkcert(hostname) - cert = nil - assert_nothing_raised { - cert = Puppet::SSLCertificates::Certificate.new(:name => hostname) - cert.mkcsr - } - - return cert - end def test_interactiveca @@ -259,8 +228,8 @@ class TestCertMgr < Test::Unit::TestCase def test_crl ca = mkCA() - h1 = mkSignedCert(ca, "host1.example.com") - h2 = mkSignedCert(ca, "host2.example.com") + h1 = mksignedcert(ca, "host1.example.com") + h2 = mksignedcert(ca, "host2.example.com") assert(ca.cert.verify(ca.cert.public_key)) assert(h1.verify(ca.cert.public_key)) @@ -295,23 +264,6 @@ class TestCertMgr < Test::Unit::TestCase assert(!store.verify(h2, [ca.cert])) end - def mkSignedCert(ca, host) - cert = mkcert(host) - assert_nothing_raised { - signedcert, cacert = ca.sign(cert.mkcsr) - return signedcert - } - 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 test_ttl cert = mksignedcert assert_equal(5 * 365 * 24 * 60 * 60, cert.not_after - cert.not_before) @@ -343,15 +295,6 @@ class TestCertMgr < Test::Unit::TestCase assert_equal(3 * 24 * 60 * 60, cert.not_after - cert.not_before) end - - def mksignedcert - ca = mkCA() - hostname = "ttltest.example.com" - - cert = nil - assert_nothing_raised { - cert, cacert = ca.sign(mkcert(hostname).mkcsr) - } - return cert - end end + +# $Id$ diff --git a/test/certmgr/inventory.rb b/test/certmgr/inventory.rb new file mode 100755 index 000000000..c94523d85 --- /dev/null +++ b/test/certmgr/inventory.rb @@ -0,0 +1,79 @@ +#!/usr/bin/env ruby + +$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/ + +require 'puppet' +require 'puppettest/certificates' +require 'puppet/sslcertificates/inventory.rb' + +class TestCertInventory < Test::Unit::TestCase + include PuppetTest::Certificates + + Inventory = Puppet::SSLCertificates::Inventory + + def test_format + cert = mksignedcert + + format = nil + assert_nothing_raised do + format = Inventory.format(cert) + end + + assert(format =~ /^0x0001 \S+ \S+ #{cert.subject}/, + "Did not create correct format") + end + + def test_init + # First create a couple of certificates + ca = mkCA + + cert1 = mksignedcert(ca, "host1.madstop.com") + cert2 = mksignedcert(ca, "host2.madstop.com") + + init = nil + assert_nothing_raised do + init = Inventory.init + end + + [cert1, cert2].each do |cert| + assert(init.include?(cert.subject.to_s), + "Did not catch %s" % cert.subject.to_s) + end + end + + def test_add + certs = [] + + user = Puppet::Util.uid(Puppet[:user]) + + ca = mkCA + 3.times do |i| + cert = mksignedcert(ca, "host#{i.to_s}.domain.com") + certs << cert + + # Add the cert + assert_nothing_raised do + Puppet::SSLCertificates::Inventory.add(cert) + end + + # Now make sure the cert is in there + assert(FileTest.exists?(Puppet[:cert_inventory]), + "Inventory file was not created") + + # And make sure all of our certs are in there + certs.each do |c| + assert( + File.read(Puppet[:cert_inventory]).include?(cert.subject.to_s), + "File does not contain %s" % cert.subject.to_s + ) + end + + # And make sure the inventory file is owned by the right user + if Process.uid == 0 + assert_equal(user, File.stat(Puppet[:cert_inventory]).uid) + end + end + end +end + +# $Id$ diff --git a/test/client/networkclient.rb b/test/client/networkclient.rb new file mode 100755 index 000000000..f4ef4c554 --- /dev/null +++ b/test/client/networkclient.rb @@ -0,0 +1,20 @@ +#!/usr/bin/env ruby + +$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/ + +require 'puppet' +require 'puppet/client' +require 'puppet/server' +require 'puppettest' + +class TestClient < Test::Unit::TestCase + def test_set_backtrace + error = Puppet::NetworkClientError.new("An error") + assert_nothing_raised do + error.set_backtrace ["caller"] + end + end +end + +# $Id$ + diff --git a/test/language/parser.rb b/test/language/parser.rb index a90ff2c7a..fa87dc6f5 100755 --- a/test/language/parser.rb +++ b/test/language/parser.rb @@ -581,6 +581,29 @@ file { "/tmp/yayness": #assert_instance_of(AST::CollExpr, query.test2) end end + + # We've had problems with files other than site.pp importing into main. + def test_importing_into_main + top = tempfile() + other = tempfile() + File.open(top, "w") do |f| + f.puts "import '#{other}'" + end + + file = tempfile() + File.open(other, "w") do |f| + f.puts "file { '#{file}': ensure => present }" + end + + interp = mkinterp :Manifest => top, :UseNodes => false + + code = nil + assert_nothing_raised do + code = interp.run("hostname.domain.com", {}).flatten + end + assert(code.length == 1, "Did not get the file") + assert_instance_of(Puppet::TransObject, code[0]) + end end # $Id$ diff --git a/test/lib/puppettest.rb b/test/lib/puppettest.rb index 07e3e084e..05d59a3a7 100755 --- a/test/lib/puppettest.rb +++ b/test/lib/puppettest.rb @@ -109,23 +109,16 @@ module PuppetTest Puppet::Log.close Puppet::Log.newdestination tempfile() Puppet[:httplog] = tempfile() - else + else + if textmate? + Puppet[:color] = false + end Puppet::Log.newdestination :console Puppet::Log.level = :debug #$VERBOSE = 1 Puppet.info @method_name Puppet[:trace] = true end - #if $0 =~ /.+\.rb/ or Puppet[:debug] - # Puppet::Log.newdestination :console - # Puppet::Log.level = :debug - # #$VERBOSE = 1 - # Puppet.info @method_name - #else - # Puppet::Log.close - # Puppet::Log.newdestination tempfile() - # Puppet[:httplog] = tempfile() - #end Puppet[:ignoreschedules] = true end @@ -142,6 +135,14 @@ module PuppetTest @@tmpfiles << f return f end + + def textmate? + if ENV["TM_FILENAME"] + return true + else + return false + end + end def tstdir dir = tempfile() diff --git a/test/lib/puppettest/certificates.rb b/test/lib/puppettest/certificates.rb new file mode 100644 index 000000000..ff19b95b3 --- /dev/null +++ b/test/lib/puppettest/certificates.rb @@ -0,0 +1,61 @@ +# Certificate-related helper methods. + +require 'puppettest' + +module PuppetTest::Certificates + include PuppetTest + + def mkPassFile() + keyfile = File.join(@dir, "tmpkeyfile") + @@tmpfiles << keyfile + unless FileTest.exists?(@dir) + system("mkdir -p %s" % @dir) + end + File.open(keyfile, "w", 0600) { |f| + f.print "as;dklj23rlkjzdflij23wr" + } + + return keyfile + end + + def mkCA + ca = nil + assert_nothing_raised { + ca = Puppet::SSLCertificates::CA.new() + } + + return 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 + } + + return 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) + } + return cert + end +end + +# $Id$ diff --git a/test/lib/puppettest/parsertesting.rb b/test/lib/puppettest/parsertesting.rb index 1a6b5b12a..c7d4ec961 100644 --- a/test/lib/puppettest/parsertesting.rb +++ b/test/lib/puppettest/parsertesting.rb @@ -12,7 +12,7 @@ module PuppetTest::ParserTesting end def mkinterp(args = {}) - args[:Code] ||= "" + args[:Code] ||= "" unless args.include?(:Manifest) args[:Local] ||= true Puppet::Parser::Interpreter.new(args) end diff --git a/test/other/features.rb b/test/other/features.rb new file mode 100755 index 000000000..fb643c926 --- /dev/null +++ b/test/other/features.rb @@ -0,0 +1,60 @@ +#!/usr/bin/env ruby +# +# Created by Luke Kanies on 2006-11-07. +# Copyright (c) 2006. All rights reserved. + +$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/ + +require 'puppettest' +require 'puppet/feature' + +class TestFeatures < Test::Unit::TestCase + include PuppetTest + + def setup + super + libdir = tempfile() + @features = Puppet::Feature.new(libdir) + end + + def test_new + assert_nothing_raised do + @features.add(:failer) do + raise ArgumentError, "nopes" + end + end + + assert(@features.respond_to?(:failer?), "Feature method did not get added") + assert_nothing_raised("failure propagated outside of feature") do + assert(! @features.failer?, "failure was considered true") + end + + # Now make one that succeeds + $succeeds = nil + assert_nothing_raised("Failed to add normal feature") do + @features.add(:succeeds) do + $succeeds = true + end + end + assert($succeeds, "Block was not called on initialization") + + assert(@features.respond_to?(:succeeds?), "Did not add succeeding feature") + assert_nothing_raised("Failed to call succeeds") { assert(@features.succeeds?, "Feature was not true") } + end + + def test_libs + assert_nothing_raised do + @features.add(:puppet, :libs => %w{puppet}) + end + + assert(@features.puppet?) + + assert_nothing_raised do + @features.add(:missing, :libs => %w{puppet no/such/library/okay}) + end + + assert(! @features.missing?, "Missing lib was considered true") + end +end + +# $Id$
\ No newline at end of file diff --git a/test/other/metrics.rb b/test/other/metrics.rb index 049d00093..a2904b2a5 100755 --- a/test/other/metrics.rb +++ b/test/other/metrics.rb @@ -7,14 +7,7 @@ require 'puppet' require 'puppettest' require 'puppet/type' -$haverrd = true -begin - require 'RRD' -rescue LoadError - $haverrd = false -end - -if $haverrd +if Puppet.features.rrd? class TestMetric < Test::Unit::TestCase include PuppetTest diff --git a/test/other/report.rb b/test/other/report.rb index a459e0cb2..433a0d8d8 100755 --- a/test/other/report.rb +++ b/test/other/report.rb @@ -21,6 +21,7 @@ class TestReports < Test::Unit::TestCase # Now make a file for testing logging file = Puppet::Type.newfile(:path => tempfile(), :ensure => "file") + file.finish log = nil assert_nothing_raised { @@ -83,7 +84,7 @@ class TestReports < Test::Unit::TestCase assert_equal(yaml, File.read(file), "File did not get written") end - if Puppet::Metric.haverrd? + if Puppet.features.rrd? def test_rrdgraph_report Puppet.config.use(:metrics) # First do some work diff --git a/test/puppet/defaults.rb b/test/puppet/defaults.rb index 7ac74eb54..033fb71bc 100755 --- a/test/puppet/defaults.rb +++ b/test/puppet/defaults.rb @@ -15,7 +15,7 @@ class TestPuppetDefaults < Test::Unit::TestCase @@booleans = %w{rrdgraph noop} def testVersion - assert( Puppet.version =~ /^[0-9]+(\.[0-9]+)*$/ ) + assert( Puppet.version =~ /^[0-9]+(\.[0-9]+)*/, "got invalid version number %s" % Puppet.version ) end def testStringOrParam diff --git a/test/types/exec.rb b/test/types/exec.rb index 53d343010..305f27d56 100755 --- a/test/types/exec.rb +++ b/test/types/exec.rb @@ -144,7 +144,7 @@ class TestExec < Test::Unit::TestCase file.retrieve sum = file.state(:checksum) - assert_equal(sum.is, sum.should) + assert(sum.insync?, "checksum is not in sync") events = trans.evaluate.collect { |event| event.event } diff --git a/test/types/file.rb b/test/types/file.rb index 027b52b81..c6cccae81 100755 --- a/test/types/file.rb +++ b/test/types/file.rb @@ -388,29 +388,24 @@ class TestFile < Test::Unit::TestCase :checksum => type ) } - comp = Puppet.type(:component).create( - :name => "checksum %s" % type - ) - comp.push file trans = nil file.retrieve if file.title !~ /nonexists/ sum = file.state(:checksum) - assert_equal(sum.is, sum.should) - assert(sum.insync?) + assert(sum.insync?, "file is not in sync") end - events = assert_apply(comp) + events = assert_apply(file) assert(! events.include?(:file_changed), "File incorrectly changed") - assert_events([], comp) + assert_events([], file) # We have to sleep because the time resolution of the time-based # mechanisms is greater than one second - sleep 1 + sleep 1 if type =~ /time/ assert_nothing_raised() { File.open(path,File::CREAT|File::TRUNC|File::WRONLY) { |of| @@ -418,7 +413,6 @@ class TestFile < Test::Unit::TestCase } } Puppet.type(:file).clear - Puppet.type(:component).clear # now recreate the file assert_nothing_raised() { @@ -427,19 +421,19 @@ class TestFile < Test::Unit::TestCase :checksum => type ) } - comp = Puppet.type(:component).create( - :name => "checksum, take 2, %s" % type - ) - comp.push file trans = nil - # If the file was missing, it should not generate an event - # when it gets created. - #if path =~ /nonexists/ - # assert_events([], comp) - #else - assert_events([:file_changed], comp) - #end + assert_events([:file_changed], file) + + # Run it a few times to make sure we aren't getting + # spurious changes. + assert_nothing_raised do + file.state(:checksum).retrieve + end + assert(file.state(:checksum).insync?, + "checksum is not in sync") + + sleep 1.1 if type =~ /time/ assert_nothing_raised() { File.unlink(path) File.open(path,File::CREAT|File::TRUNC|File::WRONLY) { |of| @@ -451,13 +445,11 @@ class TestFile < Test::Unit::TestCase of.flush } } - #assert_apply(comp) - assert_events([:file_changed], comp) + assert_events([:file_changed], file) # verify that we're actually getting notified when a file changes assert_nothing_raised() { Puppet.type(:file).clear - Puppet.type(:component).clear } if path =~ /nonexists/ diff --git a/test/types/group.rb b/test/types/group.rb index c681b5bd0..e12089256 100755 --- a/test/types/group.rb +++ b/test/types/group.rb @@ -136,19 +136,17 @@ class TestGroup < Test::Unit::TestCase def test_mkgroup gobj = nil - comp = nil name = "pptestgr" assert_nothing_raised { gobj = Puppet.type(:group).create( :name => name, - :ensure => :present + :gid => 123 ) - - comp = newcomp("groupmaker %s" % name, gobj) } + gobj.finish - trans = assert_events([:group_created], comp, "group") + trans = assert_events([:group_created], gobj, "group") assert(gobj.provider.exists?, "Did not create group") diff --git a/test/types/package.rb b/test/types/package.rb index 3cf1ea34c..611d73044 100755 --- a/test/types/package.rb +++ b/test/types/package.rb @@ -131,6 +131,8 @@ class TestPackages < Test::Unit::TestCase assert_nothing_raised { obj.retrieve } + + assert(obj.is(:ensure) != :absent, "Package %s is not installed" % obj.title) assert_instance_of(String, obj[:ensure], "Ensure did not return a version number") diff --git a/test/types/type.rb b/test/types/type.rb index 2438503c8..4be929ae9 100755 --- a/test/types/type.rb +++ b/test/types/type.rb @@ -798,6 +798,15 @@ end filetype[path] = one end end + + def test_ref + path = tempfile() + file = Puppet::Type.newfile(:path => path) + assert_equal("file[#{path}]", file.ref) + + exec = Puppet::Type.newexec(:title => "yay", :command => "/bin/echo yay") + assert_equal("exec[yay]", exec.ref) + end end # $Id$ diff --git a/test/util/posixtest.rb b/test/util/posixtest.rb new file mode 100755 index 000000000..354e3ad4c --- /dev/null +++ b/test/util/posixtest.rb @@ -0,0 +1,173 @@ +#!/usr/bin/env ruby +# +# Created by Luke Kanies on 2006-11-07. +# Copyright (c) 2006. All rights reserved. + +$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/ + +require 'puppettest' +require 'puppet/util/posix' + +class TestPosixUtil < Test::Unit::TestCase + include PuppetTest + include Puppet::Util::POSIX + + def mk_posix_resource(type, obj) + field = idfield(type) + res = Puppet::Type.type(type).create( + :name => obj.name, + field => obj.send(field) + ) + res.setdefaults + res + end + + def test_get_posix_field + {:gr => nonrootgroup, :pw => nonrootuser}.each do |space, obj| + if space == :gr + id = :gid + else + id = :uid + end + [obj.name, obj.send(id), obj.send(id).to_s].each do |test| + value = nil + assert_nothing_raised do + value = get_posix_field(space, :name, test) + end + assert_equal(obj.name, value) + end + end + end + + def test_get_provider_value + user = nonrootuser + obj = mk_posix_resource(:user, user) + + assert_nothing_raised do + assert_equal(user.uid, get_provider_value(:user, :uid, user.uid)) + assert_equal(user.name, get_provider_value(:user, :name, user.name)) + end + end + + def test_gid_and_uid + {:user => nonrootuser, :group => nonrootgroup}.each do |type, obj| + method = idfield(type) + # First make sure we get it back with both name and id with no object + [obj.name, obj.send(method)].each do |value| + assert_equal(obj.send(method), send(method, value)) + end + + # Now make a Puppet resource and make sure we get it from that. + resource = mk_posix_resource(type, obj) + + [obj.name, obj.send(method)].each do |value| + assert_equal(obj.send(method), send(method, value)) + end + end + end + + def test_util_methods + assert(Puppet::Util.respond_to?(:uid), "util does not have methods") + end + + # First verify we can convert a known user + def test_gidbyname + %x{groups}.split(" ").each { |group| + gid = nil + assert_nothing_raised { + gid = Puppet::Util.gid(group) + } + + assert(gid, "Could not retrieve gid for %s" % group) + } + end + + # Then verify we can retrieve a known group by gid + def test_gidbyid + %x{groups}.split(" ").each { |group| + obj = Puppet.type(:group).create( + :name => group, + :check => [:gid] + ) + obj.setdefaults + obj.retrieve + id = obj.is(:gid) + gid = nil + assert_nothing_raised { + gid = Puppet::Util.gid(id) + } + + assert(gid, "Could not retrieve gid for %s" % group) + assert_equal(id, gid, "Got mismatched ids") + } + end + + # Finally, verify that we can find groups by id even if we don't + # know them + def test_gidbyunknownid + gid = nil + group = Puppet::SUIDManager.gid + assert_nothing_raised { + gid = Puppet::Util.gid(group) + } + + assert(gid, "Could not retrieve gid for %s" % group) + assert_equal(group, gid, "Got mismatched ids") + end + + def user + require 'etc' + unless defined? @user + obj = Etc.getpwuid(Puppet::SUIDManager.uid) + @user = obj.name + end + return @user + end + + # And do it all over again for users + # First verify we can convert a known user + def test_uidbyname + user = user() + uid = nil + assert_nothing_raised { + uid = Puppet::Util.uid(user) + } + + assert(uid, "Could not retrieve uid for %s" % user) + assert_equal(Puppet::SUIDManager.uid, uid, "UIDs did not match") + end + + # Then verify we can retrieve a known user by uid + def test_uidbyid + user = user() + obj = Puppet.type(:user).create( + :name => user, + :check => [:uid] + ) + obj.setdefaults + obj.retrieve + id = obj.is(:uid) + uid = nil + assert_nothing_raised { + uid = Puppet::Util.uid(id) + } + + assert(uid, "Could not retrieve uid for %s" % user) + assert_equal(id, uid, "Got mismatched ids") + end + + # Finally, verify that we can find users by id even if we don't + # know them + def test_uidbyunknownid + uid = nil + user = Puppet::SUIDManager.uid + assert_nothing_raised { + uid = Puppet::Util.uid(user) + } + + assert(uid, "Could not retrieve uid for %s" % user) + assert_equal(user, uid, "Got mismatched ids") + end +end + +# $Id$
\ No newline at end of file diff --git a/test/util/utiltest.rb b/test/util/utiltest.rb index 1ab2ebb9c..ffb2ef347 100755 --- a/test/util/utiltest.rb +++ b/test/util/utiltest.rb @@ -40,105 +40,6 @@ class TestPuppetUtil < Test::Unit::TestCase threads.each { |th| th.join } end - # First verify we can convert a known user - def test_gidbyname - %x{groups}.split(" ").each { |group| - gid = nil - assert_nothing_raised { - gid = Puppet::Util.gid(group) - } - - assert(gid, "Could not retrieve gid for %s" % group) - - assert(Puppet.type(:group)[group], "Util did not create %s" % group) - } - end - - # Then verify we can retrieve a known group by gid - def test_gidbyid - %x{groups}.split(" ").each { |group| - obj = Puppet.type(:group).create( - :name => group, - :check => [:gid] - ) - obj.retrieve - id = obj.is(:gid) - gid = nil - assert_nothing_raised { - gid = Puppet::Util.gid(id) - } - - assert(gid, "Could not retrieve gid for %s" % group) - assert_equal(id, gid, "Got mismatched ids") - } - end - - # Finally, verify that we can find groups by id even if we don't - # know them - def test_gidbyunknownid - gid = nil - group = Puppet::SUIDManager.gid - assert_nothing_raised { - gid = Puppet::Util.gid(group) - } - - assert(gid, "Could not retrieve gid for %s" % group) - assert_equal(group, gid, "Got mismatched ids") - end - - def user - require 'etc' - unless defined? @user - obj = Etc.getpwuid(Puppet::SUIDManager.uid) - @user = obj.name - end - return @user - end - - # And do it all over again for users - # First verify we can convert a known user - def test_uidbyname - user = user() - uid = nil - assert_nothing_raised { - uid = Puppet::Util.uid(user) - } - - assert(uid, "Could not retrieve uid for %s" % user) - assert_equal(Puppet::SUIDManager.uid, uid, "UIDs did not match") - assert(Puppet.type(:user)[user], "Util did not create %s" % user) - end - - # Then verify we can retrieve a known user by uid - def test_uidbyid - user = user() - obj = Puppet.type(:user).create( - :name => user, - :check => [:uid] - ) - obj.retrieve - id = obj.is(:uid) - uid = nil - assert_nothing_raised { - uid = Puppet::Util.uid(id) - } - - assert(uid, "Could not retrieve uid for %s" % user) - assert_equal(id, uid, "Got mismatched ids") - end - - # Finally, verify that we can find users by id even if we don't - # know them - def test_uidbyunknownid - uid = nil - user = Puppet::SUIDManager.uid - assert_nothing_raised { - uid = Puppet::Util.uid(user) - } - - assert(uid, "Could not retrieve uid for %s" % user) - assert_equal(user, uid, "Got mismatched ids") - end def test_withumask oldmask = File.umask |
