summaryrefslogtreecommitdiffstats
path: root/test/puppet/modules.rb
blob: e652182a82e08e4323fea8c4290b5114c72e1a4c (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
53
54
55
56
57
58
#!/usr/bin/env ruby

$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/

require 'puppet'
require 'puppettest'

class TestModules < Test::Unit::TestCase
	include PuppetTest

    def setup
        super
        @varmods = File::join(Puppet[:vardir], "modules")
        FileUtils::mkdir_p(@varmods)
    end

    def test_modulepath
        Puppet[:modulepath] = "$vardir/modules:/no/such/path/anywhere:.::"
        assert_equal([ @varmods ], Puppet::Module.modulepath)
    end

    def test_find
        assert_nil(Puppet::Module::find("/tmp"))

        file = "testmod/something"
        assert_nil(Puppet::Module::find(file))

        path = File::join(@varmods, "testmod")
        FileUtils::mkdir_p(path)

        mod = Puppet::Module::find("testmod")
        assert_not_nil(mod)
        assert_equal("testmod", mod.name)
        assert_equal(path, mod.path)

        mod = Puppet::Module::find(file)
        assert_not_nil(mod)
        assert_equal("testmod", mod.name)
        assert_equal(path, mod.path)
    end

    def test_find_template
        templ = "testmod/templ.erb"
        assert_equal(File::join(Puppet[:templatedir], templ),
                     Puppet::Module::find_template(templ))

        templ_path = File::join(@varmods, "testmod",
                                Puppet::Module::TEMPLATES, "templ.erb")
        FileUtils::mkdir_p(File::dirname(templ_path))
        File::open(templ_path, "w") { |f| f.puts "Howdy" }

        assert_equal(templ_path, Puppet::Module::find_template(templ))

        mod = Puppet::Module::find(templ)
        assert_not_nil(mod)
        assert_equal(templ_path, mod.template(templ))
    end
end