summaryrefslogtreecommitdiff
path: root/test/types/query.rb
blob: 121670012e674caaf9fc6a3b924ba5cc9ce62788 (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
if __FILE__ == $0
    $:.unshift '..'
    $:.unshift '../../lib'
    $puppetbase = File.join(Dir.getwd(), "../..")
end

require 'puppet'
require 'puppettest'
require 'test/unit'

# $Id$

class TestQuery < Test::Unit::TestCase
    include TestPuppet
    # hmmm
    # this is complicated, because we store references to the created
    # objects in a central store
    def file
        assert_nothing_raised() {
            cfile = File.join($puppetbase,"examples/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 => File.join($puppetbase,"examples/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