summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2005-09-07 02:53:19 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2005-09-07 02:53:19 +0000
commitb77d29568e8adaa0104d8ee5b4c168ef6e3c4bdd (patch)
tree8372dc3bc8ed4cb293ff19e7cf6f920d8e7abb69 /test
parent4f2812a2180894b645583c7a7c3aa8a012b2b0ac (diff)
downloadpuppet-b77d29568e8adaa0104d8ee5b4c168ef6e3c4bdd.tar.gz
puppet-b77d29568e8adaa0104d8ee5b4c168ef6e3c4bdd.tar.xz
puppet-b77d29568e8adaa0104d8ee5b4c168ef6e3c4bdd.zip
adding user and group classes (although user class is not yet functional), and added "is(state)" and "should(state)" methods for retrieving the respective values on a specified state
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@630 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test')
-rwxr-xr-xtest/types/tc_group.rb99
-rwxr-xr-xtest/types/tc_user.rb98
2 files changed, 197 insertions, 0 deletions
diff --git a/test/types/tc_group.rb b/test/types/tc_group.rb
new file mode 100755
index 000000000..7f3c1d01f
--- /dev/null
+++ b/test/types/tc_group.rb
@@ -0,0 +1,99 @@
+if __FILE__ == $0
+ $:.unshift '..'
+ $:.unshift '../../lib'
+ $puppetbase = "../../../../language/trunk"
+end
+
+# $Id$
+
+require 'etc'
+require 'puppet/type'
+require 'puppettest'
+require 'test/unit'
+
+class TestGroup < TestPuppet
+ def setup
+ Puppet[:loglevel] = :debug if __FILE__ == $0
+ super
+ end
+
+ def groupnames
+ %x{groups}.chomp.split(/ /)
+ end
+
+ def groupids
+ Process.groups
+ end
+
+ def test_eachmethod
+ obj = Etc.getgrnam(groupnames()[0])
+
+ assert(obj, "Could not retrieve test group object")
+
+ Puppet::Type::Group.validstates.each { |name, state|
+ assert_nothing_raised {
+ method = state.infomethod
+ assert(method, "State %s has no infomethod" % name)
+ assert(obj.respond_to?(method), "State %s has an invalid method %s" %
+ [name, method])
+ }
+ }
+ end
+
+ def test_owngroups
+ groupnames().each { |group|
+ gobj = nil
+ comp = nil
+ assert_nothing_raised {
+ gobj = Puppet::Type::Group.new(
+ :name => group,
+ :check => [:gid]
+ )
+
+ comp = newcomp("grouptest %s" % group, gobj)
+ }
+
+ trans = nil
+ assert_nothing_raised {
+ trans = comp.evaluate
+ }
+
+ assert(gobj.is(:gid), "Failed to retrieve gid")
+ }
+ end
+
+ if Process.uid == 0
+ def test_mkgroup
+ gobj = nil
+ comp = nil
+ name = "pptestgr"
+ assert_nothing_raised {
+ gobj = Puppet::Type::Group.new(
+ :name => name
+ )
+
+ comp = newcomp("groupmaker %s" % name, gobj)
+ }
+
+ trans = nil
+ assert_nothing_raised {
+ trans = comp.evaluate
+ }
+
+ events = nil
+ assert_nothing_raised {
+ events = trans.evaluate.reject { |e| e.nil? }.collect { |e| e.event }
+ }
+
+ assert_equal([:group_created], events, "Incorrect group events")
+
+ assert_nothing_raised {
+ events = trans.rollback.reject { |e| e.nil? }.collect { |e| e.event }
+ }
+
+ assert_equal([:group_deleted], events, "Incorrect deletion group events")
+ end
+ else
+ $stderr.puts "Not running as root; skipping group creation tests."
+ end
+end
diff --git a/test/types/tc_user.rb b/test/types/tc_user.rb
new file mode 100755
index 000000000..3522539d5
--- /dev/null
+++ b/test/types/tc_user.rb
@@ -0,0 +1,98 @@
+if __FILE__ == $0
+ $:.unshift '..'
+ $:.unshift '../../lib'
+ $puppetbase = "../../../../language/trunk"
+end
+
+# $Id$
+
+require 'puppet/type'
+require 'test/unit'
+
+class TestType < Test::Unit::TestCase
+ def test_typemethods
+ assert_nothing_raised() {
+ Puppet::Type.buildstatehash
+ }
+
+ Puppet::Type.eachtype { |type|
+ name = nil
+ assert_nothing_raised() {
+ name = type.name
+ }
+
+ assert(
+ name
+ )
+
+ assert_equal(
+ type,
+ Puppet::Type.type(name)
+ )
+
+ assert(
+ type.namevar
+ )
+
+ assert_not_nil(
+ type.states
+ )
+
+ assert_not_nil(
+ type.validstates
+ )
+
+ assert(
+ type.validparameter?(type.namevar)
+ )
+ }
+ end
+
+ def test_stringvssymbols
+ file = nil
+ path = "/tmp/testfile"
+ assert_nothing_raised() {
+ system("rm -f %s" % path)
+ file = Puppet::Type::PFile.new(
+ :path => path,
+ :create => true,
+ :recurse => true,
+ :checksum => "md5"
+ )
+ }
+ assert_nothing_raised() {
+ file.retrieve
+ }
+ assert_nothing_raised() {
+ file.sync
+ }
+ Puppet::Type::PFile.clear
+ assert_nothing_raised() {
+ system("rm -f %s" % path)
+ file = Puppet::Type::PFile.new(
+ "path" => path,
+ "create" => true,
+ "recurse" => true,
+ "checksum" => "md5"
+ )
+ }
+ assert_nothing_raised() {
+ file.retrieve
+ }
+ assert_nothing_raised() {
+ file[:path]
+ }
+ assert_nothing_raised() {
+ file["path"]
+ }
+ assert_nothing_raised() {
+ file[:recurse]
+ }
+ assert_nothing_raised() {
+ file["recurse"]
+ }
+ assert_nothing_raised() {
+ file.sync
+ }
+ end
+end