summaryrefslogtreecommitdiffstats
path: root/test/objects/tc_basic.rb
blob: 75cec7b7b9986a90ca0b4395dfd92df902bf9aaf (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
if __FILE__ == $0
    $:.unshift '..'
    $:.unshift '../../lib'
    $blinkbase = "../.."
end

require 'blink'
require 'test/unit'

# $Id$

class TestBasic < Test::Unit::TestCase
    # hmmm
    # this is complicated, because we store references to the created
    # objects in a central store
    def setup
        @component = nil
        @configfile = nil
        @sleeper = nil

        Blink[:debug] = 1

        assert_nothing_raised() {
            unless Blink::Component.has_key?("sleeper")
                Blink::Component.new(
                    :name => "sleeper"
                )
            end
            @component = Blink::Component["sleeper"]
        }

        assert_nothing_raised() {
            cfile = File.join($blinkbase,"examples/root/etc/configfile")
            unless Blink::Objects::File.has_key?(cfile)
                Blink::Objects::File.new(
                    :path => cfile
                )
            end
            @configfile = Blink::Objects::File[cfile]
        }
        assert_nothing_raised() {
            unless Blink::Objects::Service.has_key?("sleeper")
                Blink::Objects::Service.new(
                    :name => "sleeper",
                    :running => 1
                )
                Blink::Objects::Service.addpath(
                    File.join($blinkbase,"examples/root/etc/init.d")
                )
            end
            @sleeper = Blink::Objects::Service["sleeper"]
        }
        assert_nothing_raised() {
            @component.push(
                @configfile,
                @sleeper
            )
        }
        
        #puts "Component is %s, id %s" % [@component, @component.object_id]
        #puts "ConfigFile is %s, id %s" % [@configfile, @configfile.object_id]
    end

    def test_name_calls
        [@component,@sleeper,@configfile].each { |obj|
            assert_nothing_raised(){
                obj.name
            }
        }
    end

    def test_name_equality
        #puts "Component is %s, id %s" % [@component, @component.object_id]
        assert_equal(
            "sleeper",
            @component.name
        )

        assert_equal(
            File.join($blinkbase,"examples/root/etc/configfile"),
            @configfile.name
        )

        assert_equal(
            "sleeper",
            @sleeper.name
        )
    end

    def test_object_retrieval
        [@component,@sleeper,@configfile].each { |obj|
            assert_equal(
                obj.class[obj.name].object_id,
                obj.object_id
            )
        }
    end
end