summaryrefslogtreecommitdiffstats
path: root/test/other/relationship.rb
blob: d890a031d3b3f5c0b01da402dfd77d58c541ff20 (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
#!/usr/bin/env ruby
#
#  Created by Luke A. Kanies on 2006-11-24.
#  Copyright (c) 2006. All rights reserved.

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

require 'puppettest'
require 'puppet/relationship'

class TestRelationship < Test::Unit::TestCase
    include PuppetTest
    
    def test_initialize
        rel = Puppet::Relationship
        
        [["source", "target", "label"],
         ["source", "target", {:event => :nothing}]
        ].each do |ary|
            # Make sure the label is required
            assert_raise(Puppet::DevError) do
                rel.new(*ary)
            end
        end
    end
    
    def test_attributes
        rel = Puppet::Relationship
        
        i = nil
        assert_nothing_raised do
            i = rel.new "source", "target", :event => :yay, :callback => :boo
        end
        
        assert_equal(:yay, i.event, "event was not retrieved")
        assert_equal(:boo, i.callback, "callback was not retrieved")
        
        # Now try it with nil values
        assert_nothing_raised("failed to create with no event or callback") {
            i = rel.new "source", "target"
        }
        
        assert_nil(i.event, "event was not nil")
        assert_nil(i.callback, "callback was not nil")
    end

    def test_match
        edge = Puppet::Relationship.new(:a, :b)

        assert(! edge.match?(:NONE), "nil event matched :NONE")
        assert(! edge.match?(:ALL_EVENT), "nil event matched :ALL_EVENTS")
        assert(! edge.match?(:random), "nil event matched random")

        # Now set the edge to none
        edge.label = {:event => :NONE}
        assert(! edge.match?(:NONE), ":NONE event matched :NONE")
        assert(! edge.match?(:ALL_EVENT), ":NONE event matched :ALL_EVENTS")
        assert(! edge.match?(:random), ":NONE event matched random")

        # Now set it to :ALL
        edge.label = {:event => :ALL_EVENTS}
        assert(! edge.match?(:NONE), ":ALL_EVENTS event matched :NONE")
        assert(edge.match?(:ALL_EVENTS), ":ALL_EVENTS did not match :ALL_EVENTS")
        assert(edge.match?(:random), ":ALL_EVENTS did not match random")

        # And finally, :random
        edge.label = {:event => :random}
        assert(! edge.match?(:NONE), ":random event matched :NONE")
        assert(! edge.match?(:ALL_EVENTS), ":random matched :ALL_EVENTS")
        assert(edge.match?(:random), ":random did not match random")
    end
end