summaryrefslogtreecommitdiffstats
path: root/test/util/posixtest.rb
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-10-01 00:07:24 -0500
committerJames Turnbull <james@lovedthanlost.net>2008-10-02 07:32:03 +1000
commit862077513570c996e9124743369c9af92485151f (patch)
tree055d2e11ab95d2c9a6f85c31e046382f41126c99 /test/util/posixtest.rb
parent63ad84587892e9cab851cf516f7a381c5ea51f90 (diff)
downloadpuppet-862077513570c996e9124743369c9af92485151f.tar.gz
puppet-862077513570c996e9124743369c9af92485151f.tar.xz
puppet-862077513570c996e9124743369c9af92485151f.zip
Fixed #791 - You should now be able to create and find a user/group in one transaction.
The real problem was that the 'gid' and 'uid' methods didn't handle the case where 'get_posix_field' didn't return a value, and the subsequent 'get_posix_field' calls couldn't handle that. This commit moves the tests for Posix to spec, and fixes the specific bug. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'test/util/posixtest.rb')
-rwxr-xr-xtest/util/posixtest.rb182
1 files changed, 0 insertions, 182 deletions
diff --git a/test/util/posixtest.rb b/test/util/posixtest.rb
deleted file mode 100755
index f64a95d18..000000000
--- a/test/util/posixtest.rb
+++ /dev/null
@@ -1,182 +0,0 @@
-#!/usr/bin/env ruby
-#
-# Created by Luke Kanies on 2006-11-07.
-# Copyright (c) 2006. All rights reserved.
-
-require File.dirname(__FILE__) + '/../lib/puppettest'
-
-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
- {:group => nonrootgroup, :passwd => nonrootuser}.each do |space, obj|
- id = Puppet::Util.idfield(space)
- [obj.name, obj.send(id)].each do |test|
- value = nil
- assert_nothing_raised do
- value = get_posix_field(space, :name, test)
- end
- assert_equal(obj.name, value, "did not get correct value from get_posix_field (known to be broken on some platforms)")
- end
- end
- end
-
- def test_search_posix_field
- {:group => nonrootgroup, :passwd => nonrootuser}.each do |space, obj|
- id = Puppet::Util.idfield(space)
- [obj.name, obj.send(id)].each do |test|
- value = nil
- assert_nothing_raised do
- value = search_posix_field(space, :name, test)
- end
- assert_equal(obj.name, value, "did not get correct value from search_posix_field")
- 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
- current = obj.retrieve
- id = nil
- current.find { |prop, value| id = value if prop.name == :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::Util::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::Util::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::Util::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.provider.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::Util::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
-