summaryrefslogtreecommitdiffstats
path: root/test/other/puppet.rb
blob: 0dea54da42186c0f709cfa4d8ce448d6e91a3853 (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env ruby

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

require 'puppet'
require 'puppettest'

# Test the different features of the main puppet module
class TestPuppetModule < Test::Unit::TestCase
    include PuppetTest
    include SignalObserver

    def mkfakeclient
        Class.new(Puppet::Network::Client) do
            def initialize
            end

            def runnow
                Puppet.info "fake client has run"
            end
        end
    end

    def mktestclass
        Class.new do
            def initialize(file)
                @file = file
            end

            def started?
                FileTest.exists?(@file)
            end

            def start
                File.open(@file, "w") do |f| f.puts "" end
            end

            def shutdown
                File.unlink(@file)
            end
        end
    end

    def test_path
        oldpath = ENV["PATH"]
        cleanup do
            ENV["PATH"] = oldpath
        end
        newpath = oldpath + ":" + "/something/else"
        assert_nothing_raised do
            Puppet[:path] = newpath
        end

        assert_equal(newpath, ENV["PATH"])
    end

    def test_libdir
        oldlibs = $:.dup
        cleanup do
            $:.each do |dir|
                unless oldlibs.include?(dir)
                    $:.delete(dir)
                end
            end
        end
        one = tempfile()
        two = tempfile()
        Dir.mkdir(one)
        Dir.mkdir(two)

        # Make sure setting the libdir gets the dir added to $:
        assert_nothing_raised do
            Puppet[:libdir] = one
        end

        assert($:.include?(one), "libdir was not added")

        # Now change it, make sure it gets added and the old one gets
        # removed
        assert_nothing_raised do
            Puppet[:libdir] = two
        end

        assert($:.include?(two), "libdir was not added")
        assert(! $:.include?(one), "old libdir was not removed")
    end
end