pairing with luke, nagios_command provider skeleton
[vinpup.git] / test / other / puppet.rb
blob6527bed5615892696fa0148b64cd553aa98d43de
1 #!/usr/bin/env ruby
3 require File.dirname(__FILE__) + '/../lib/puppettest'
5 require 'puppet'
6 require 'puppettest'
8 # Test the different features of the main puppet module
9 class TestPuppetModule < Test::Unit::TestCase
10         include PuppetTest
11     include SignalObserver
12     
13     def mkfakeclient
14         Class.new(Puppet::Network::Client) do
15             def initialize
16             end
18             def runnow
19                 Puppet.info "fake client has run"
20             end
21         end
22     end
24     def mktestclass
25         Class.new do
26             def initialize(file)
27                 @file = file
28             end
30             def started?
31                 FileTest.exists?(@file)
32             end
34             def start
35                 File.open(@file, "w") do |f| f.puts "" end
36             end
38             def shutdown
39                 File.unlink(@file)
40             end
41         end
42     end
44     # Make sure that services get correctly started and stopped
45     def test_servicehandling
46         file = tempfile()
47         testclass = mktestclass()
49         obj = testclass.new(file)
51         assert_nothing_raised {
52             Puppet.newservice(obj)
53         }
55         assert_nothing_raised {
56             Puppet.start(false)
57         }
59         # Give it a sec or so
60         sleep 0.3
62         assert(obj.started?, "Object was not started")
64         assert_nothing_raised {
65             Puppet.shutdown(false)
66         }
67         # Give it a sec or so
68         sleep 0.3
70         assert(!obj.started?, "Object is still running")
72     end
74     def test_path
75         oldpath = ENV["PATH"]
76         cleanup do
77             ENV["PATH"] = oldpath
78         end
79         newpath = oldpath + ":" + "/something/else"
80         assert_nothing_raised do
81             Puppet[:path] = newpath
82         end
84         assert_equal(newpath, ENV["PATH"])
85     end
87     def test_libdir
88         oldlibs = $:.dup
89         cleanup do
90             $:.each do |dir|
91                 unless oldlibs.include?(dir)
92                     $:.delete(dir)
93                 end
94             end
95         end
96         one = tempfile()
97         two = tempfile()
98         Dir.mkdir(one)
99         Dir.mkdir(two)
101         # Make sure setting the libdir gets the dir added to $:
102         assert_nothing_raised do
103             Puppet[:libdir] = one
104         end
106         assert($:.include?(one), "libdir was not added")
108         # Now change it, make sure it gets added and the old one gets
109         # removed
110         assert_nothing_raised do
111             Puppet[:libdir] = two
112         end
114         assert($:.include?(two), "libdir was not added")
115         assert(! $:.include?(one), "old libdir was not removed")
116     end
118     def test_name
119         # Make sure it defaults to $0 without the rb
120         should = $0.gsub(/.+#{File::SEPARATOR}/,'').sub(/\.rb$/, '')
122         assert_equal(should, Puppet[:name], "default name was not right")
124         assert_nothing_raised("Could not reset name") do
125             Puppet[:name] = "puppetca"
126         end
128         assert_equal("puppetca", Puppet[:name], "name reset did not take")
129     end