pairing with luke, nagios_command provider skeleton
[vinpup.git] / test / other / overrides.rb
blobe0e3fdf5fc4703d47c16728f47601ca83a3dcf96
1 #!/usr/bin/env ruby
3 require File.dirname(__FILE__) + '/../lib/puppettest'
5 require 'puppet'
6 require 'puppettest'
8 class TestOverrides < Test::Unit::TestCase
9         include PuppetTest
10     def mksubdirs(basedir, level)
11         @@tmpfiles << basedir
12         dir = basedir.dup
14         (level + 1).times { |index|
15             Dir.mkdir(dir)
16             path = File.join(dir, "file")
17             File.open(path, "w") { |f| f.puts "yayness" }
18             dir = File.join(dir, index.to_s)
19         }
20     end
22     def test_simpleoverride
23         basedir = File.join(tmpdir(), "overridetesting")
24         mksubdirs(basedir, 1)
26         baseobj = nil
27         basefile = File.join(basedir, "file")
28         assert_nothing_raised("Could not create base obj") {
29             baseobj = Puppet.type(:file).create(
30                 :title => "base",
31                 :path => basedir,
32                 :recurse => true,
33                 :mode => "755"
34             )
35         }
37         subobj = nil
38         subdir = File.join(basedir, "0")
39         subfile = File.join(subdir, "file")
40         assert_nothing_raised("Could not create sub obj") {
41             subobj = Puppet.type(:file).create(
42                 :title => "sub",
43                 :path => subdir,
44                 :recurse => true,
45                 :mode => "644"
46             )
47         }
49         assert_apply(baseobj, subobj)
51         assert(File.stat(basefile).mode & 007777 == 0755)
52         assert(File.stat(subfile).mode & 007777 == 0644)
53     end
55     def test_deepoverride
56         basedir = File.join(tmpdir(), "deepoverridetesting")
57         mksubdirs(basedir, 10)
59         baseobj = nil
60         assert_nothing_raised("Could not create base obj") {
61             baseobj = Puppet.type(:file).create(
62                 :path => basedir,
63                 :recurse => true,
64                 :mode => "755"
65             )
66         }
68         children = []
69         files = {}
70         subdir = basedir.dup
71         mode = nil
72         10.times { |index|
73             next unless index % 3
74             subdir = File.join(subdir, index.to_s)
75             path = File.join(subdir, "file")
76             if index % 2
77                 mode = "644"
78                 files[path] = 0644
79             else
80                 mode = "750"
81                 files[path] = 0750
82             end
84             assert_nothing_raised("Could not create sub obj") {
85                 children << Puppet.type(:file).create(
86                     :path => subdir,
87                     :recurse => true,
88                     :mode => mode
89                 )
90             }
91         }
93         config = mk_catalog(baseobj, *children)
95         assert_nothing_raised("Could not eval component") {
96             config.apply
97         }
99         files.each { |path, mode|
100             assert(FileTest.exists?(path), "File %s does not exist" % path)
101             curmode = File.stat(path).mode & 007777
102             assert(curmode == mode,
103                 "File %s was incorrect mode %o instead of %o" % [path, curmode, mode])
104         }
105     end