File: query.rb

package info (click to toggle)
puppet 0.20.1-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,072 kB
  • ctags: 3,365
  • sloc: ruby: 47,009; sh: 496; lisp: 143; xml: 122; makefile: 67
file content (99 lines) | stat: -rwxr-xr-x 2,401 bytes parent folder | download
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
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env ruby

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

require 'puppet'
require 'puppettest'

# $Id: query.rb 1793 2006-10-16 22:01:40Z luke $

class TestQuery < Test::Unit::TestCase
    include PuppetTest
    # hmmm
    # this is complicated, because we store references to the created
    # objects in a central store
    def file
        assert_nothing_raised() {
            cfile = exampledir("root/etc/configfile")
            unless Puppet.type(:file).has_key?(cfile)
                Puppet.type(:file).create(
                    :path => cfile,
                    :check => [:mode, :owner, :checksum]
                )
            end
            @configfile = Puppet.type(:file)[cfile]
        }
        return @configfile
    end

    def service
        assert_nothing_raised() {
            unless Puppet.type(:service).has_key?("sleeper")
                Puppet.type(:service).create(
                    :name => "sleeper",
                    :provider => "init",
                    :path => exampledir("root/etc/init.d"),
                    :hasstatus => true,
                    :check => [:ensure]
                )
            end
            @sleeper = Puppet.type(:service)["sleeper"]
        }

        return @sleeper
    end

    def component(name,*args)
        assert_nothing_raised() {
            @component = Puppet.type(:component).create(:name => name)
        }

        args.each { |arg|
            assert_nothing_raised() {
                @component.push arg
            }
        }

        return @component
    end

    def test_file
        yayfile = file()
        #p yayfile
        yayfile.eachstate { |state|
            assert_nil(state.is)
        }

        assert_nothing_raised() {
            yayfile.retrieve
        }

        assert_nothing_raised() {
            yayfile[:check] = :group
        }

        assert_nothing_raised() {
            yayfile.retrieve
        }
    end

    def test_service
        service = service()
        assert(service, "Did not get service object")
        service.eachstate { |state|
            assert_nil(state.is)
        }

        assert_nothing_raised() {
            service.retrieve
        }
    end

    def test_component
        component = component("a",file(),service())

        assert_nothing_raised() {
            component.retrieve
        }
    end
end