summaryrefslogtreecommitdiffstats
path: root/test/util/instance_loader.rb
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-05-07 18:59:40 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-05-07 18:59:40 +0000
commitf42a755cc2e4bc77880dec9571ccd11f33f2737f (patch)
tree733e1c1681b9c325f269da81ab5faf1f58494a67 /test/util/instance_loader.rb
parent53f16125761400df4fb1b99159c6b3bab8f5f397 (diff)
downloadpuppet-f42a755cc2e4bc77880dec9571ccd11f33f2737f.tar.gz
puppet-f42a755cc2e4bc77880dec9571ccd11f33f2737f.tar.xz
puppet-f42a755cc2e4bc77880dec9571ccd11f33f2737f.zip
Adding a module to abstract using Autoload to load and manage instances
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2476 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test/util/instance_loader.rb')
-rwxr-xr-xtest/util/instance_loader.rb53
1 files changed, 53 insertions, 0 deletions
diff --git a/test/util/instance_loader.rb b/test/util/instance_loader.rb
new file mode 100755
index 000000000..fa08d1bd6
--- /dev/null
+++ b/test/util/instance_loader.rb
@@ -0,0 +1,53 @@
+#!/usr/bin/env ruby
+
+$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/
+
+require 'puppet'
+require 'puppet/util/instance_loader'
+require 'puppettest'
+
+class TestInstanceloader < Test::Unit::TestCase
+ include PuppetTest
+
+ def setup
+ super
+ @loader = Class.new do
+ extend Puppet::Util::InstanceLoader
+
+ def self.newstuff(name, value)
+ instance_hash(:stuff)[name] = value
+ end
+ end
+
+ assert_nothing_raised("Could not create autoloader") do
+ @loader.autoload(:stuff, "puppet/stuff")
+ end
+ end
+
+ # Make sure we correctly create our autoload instance. This covers the basics.
+ def test_autoload
+ # Make sure we can retrieve the loader
+ assert_instance_of(Puppet::Util::Autoload, @loader.instance_loader(:stuff), "Could not get autoloader")
+
+ # Make sure we can get the instance hash
+ assert(@loader.instance_hash(:stuff), "Could not get instance hash")
+
+ # Make sure it defines the instance retrieval method
+ assert(@loader.respond_to?(:stuff), "Did not define instance retrieval method")
+ end
+
+ def test_loaded_instances
+ assert_equal([], @loader.loaded_instances(:stuff), "Incorrect loaded instances")
+
+ @loader.newstuff(:testing, "a value")
+
+ assert_equal([:testing], @loader.loaded_instances(:stuff), "Incorrect loaded instances")
+
+ assert_equal("a value", @loader.loaded_instance(:stuff, :testing), "Got incorrect loaded instance")
+ end
+
+ def test_autoloading
+ end
+end
+
+# $Id$