summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-12-12 21:33:54 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-12-12 21:33:54 +0000
commit8829aa7d489fffaba31c0ff8ac4ff0562357551c (patch)
tree99fde22b54d529f04a8fa66520601da9e07a77f4 /test
parent4abbdc13f4a1762eb5d848763dde1780f6408de8 (diff)
downloadpuppet-8829aa7d489fffaba31c0ff8ac4ff0562357551c.tar.gz
puppet-8829aa7d489fffaba31c0ff8ac4ff0562357551c.tar.xz
puppet-8829aa7d489fffaba31c0ff8ac4ff0562357551c.zip
Adding a metatype to manage resources of a specified type. For now, this metatype just supports purging unmanaged resources. Also, fixed a few tests here and there
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1912 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test')
-rwxr-xr-xtest/other/dsl.rb1
-rw-r--r--test/other/pgraph.rb4
-rwxr-xr-xtest/other/transactions.rb3
-rwxr-xr-xtest/types/resources.rb129
-rwxr-xr-xtest/util/graph.rb4
5 files changed, 133 insertions, 8 deletions
diff --git a/test/other/dsl.rb b/test/other/dsl.rb
index 50eac4781..b36cca745 100755
--- a/test/other/dsl.rb
+++ b/test/other/dsl.rb
@@ -200,6 +200,7 @@ class TestDSL < Test::Unit::TestCase
a = aspect :testing
Puppet::Type.eachtype do |type|
+ next if type.name.to_s =~ /test/
assert(a.respond_to?(type.name),
"Aspects do not have a %s method" % type.name)
end
diff --git a/test/other/pgraph.rb b/test/other/pgraph.rb
index 88f753131..1ef853cc4 100644
--- a/test/other/pgraph.rb
+++ b/test/other/pgraph.rb
@@ -88,8 +88,6 @@ class TestPGraph < Test::Unit::TestCase
deps.add_edge!(source, target, :callback => :refresh)
end
- deps.to_jpg("deps-before")
-
deps.splice!(contgraph, Container)
assert(! deps.cyclic?, "Created a cyclic graph")
@@ -125,4 +123,4 @@ class TestPGraph < Test::Unit::TestCase
end
end
-# $Id$ \ No newline at end of file
+# $Id$
diff --git a/test/other/transactions.rb b/test/other/transactions.rb
index 67a2daea9..4190ada3a 100755
--- a/test/other/transactions.rb
+++ b/test/other/transactions.rb
@@ -559,7 +559,6 @@ class TestTransactions < Test::Unit::TestCase
file = f(letter)
assert(reverse.vertex?(file), "%s did not make it into reversal" % letter)
end
- graph.to_jpg("normal_relations")
end
# Test pre-evaluation generation
@@ -769,4 +768,4 @@ class TestTransactions < Test::Unit::TestCase
end
end
-# $Id$ \ No newline at end of file
+# $Id$
diff --git a/test/types/resources.rb b/test/types/resources.rb
new file mode 100755
index 000000000..f8a2f6640
--- /dev/null
+++ b/test/types/resources.rb
@@ -0,0 +1,129 @@
+#!/usr/bin/env ruby
+#
+# Created by Luke Kanies on 2006-12-12.
+# Copyright (c) 2006. All rights reserved.
+
+$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/
+
+require 'puppettest'
+
+class TestResources < Test::Unit::TestCase
+ include PuppetTest
+
+ def add_purge_lister
+ # Now define the list method
+ class << @purgetype
+ def list
+ $purgemembers.values
+ end
+ end
+ end
+
+ def mk_purger(managed = false)
+ @purgenum ||= 0
+ @purgenum += 1
+ obj = @purgetype.create :name => "purger%s" % @purgenum
+ $purgemembers[obj[:name]] = obj
+ if managed
+ obj[:fake] = "testing"
+ end
+ obj
+ end
+
+ def mkpurgertype
+ # Create a purgeable type
+ $purgemembers = {}
+ @purgetype = Puppet::Type.newtype(:purgetest) do
+ newparam(:name, :namevar => true) {}
+ newstate(:ensure) do
+ newvalue(:absent) do
+ $purgemembers[@parent[:name]] = @parent
+ end
+ newvalue(:present) do
+ $purgemembers.delete(@parent[:name])
+ end
+ end
+ newstate(:fake) do
+ def sync
+ :faked
+ end
+ end
+ end
+ cleanup do
+ Puppet::Type.rmtype(:purgetest)
+ end
+ end
+
+ def setup
+ super
+ @type = Puppet::Type.type(:resources)
+ end
+
+ def test_initialize
+ assert(@type, "Could not retrieve resources type")
+ # Make sure we can't create them for types that don't exist
+ assert_raise(ArgumentError) do
+ @type.create :name => "thereisnotypewiththisname"
+ end
+
+ # Now make sure it works for a normal type
+ usertype = nil
+ assert_nothing_raised do
+ usertype = @type.create :name => "user"
+ end
+ assert(usertype, "did not create user resource type")
+ assert_equal(Puppet::Type.type(:user), usertype.resource_type,
+ "resource_type was not set correctly")
+ end
+
+ def test_purge
+ # Create a purgeable type
+ mkpurgertype
+
+ purger = nil
+ assert_nothing_raised do
+ purger = @type.create :name => "purgetest"
+ end
+ assert(purger, "did not get purger manager")
+
+ # Make sure we throw an error, because the purger type does
+ # not support listing.
+
+ # It should work when we set it to false
+ assert_nothing_raised do
+ purger[:purge] = false
+ end
+ # but not true
+ assert_raise(ArgumentError) do
+ purger[:purge] = true
+ end
+ add_purge_lister()
+
+ assert_equal($purgemembers.values.sort, @purgetype.list.sort)
+
+ # and it should now succeed
+ assert_nothing_raised do
+ purger[:purge] = true
+ end
+ assert(purger.purge?, "purge boolean was not enabled")
+
+ # Okay, now let's try doing some purging, yo
+ managed = []
+ unmanned = []
+ 3.times { managed << mk_purger(true) } # 3 managed
+ 3.times { unmanned << mk_purger(false) } # 3 unmanaged
+
+ managed.each do |m|
+ assert(m.managed?, "managed resource was not considered managed")
+ end
+ unmanned.each do |u|
+ assert(! u.managed?, "unmanaged resource was considered managed")
+ end
+
+ # Now make sure the generate method only finds the unmanaged resources
+ assert_equal(unmanned.collect { |r| r.title }.sort, purger.generate.collect { |r| r.title },
+ "Did not return correct purge list")
+ end
+end
+
+# $Id$ \ No newline at end of file
diff --git a/test/util/graph.rb b/test/util/graph.rb
index 1df294c77..7d43ed6f9 100755
--- a/test/util/graph.rb
+++ b/test/util/graph.rb
@@ -51,8 +51,6 @@ class TestUtilGraph < Test::Unit::TestCase
end
end
- graph.to_jpg("graph")
-
# Now make sure we correctly retrieve the leaves from each container
{top => %w{a b c d e f g h},
one => %w{a b},
@@ -106,4 +104,4 @@ class TestUtilGraph < Test::Unit::TestCase
end
end
-# $Id$ \ No newline at end of file
+# $Id$