summaryrefslogtreecommitdiffstats
path: root/test/util/instance_loader.rb
blob: a7ea41532c81d232691106f012667dfe71e7426a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env ruby

require File.dirname(__FILE__) + '/../lib/puppettest'

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 instance loader") do
            @loader.instance_load(: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 instance loader")

        # 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_instance_loading
    end
end