blob: 29c68503d5a476a51edd352a3e3a5bd951e93cc4 (
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
|
# frozen_string_literal: true
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
require 'minitest/autorun'
require 'fileutils'
require_relative '../../../lib/dsl'
class RCMRequiresTest < Minitest::Test
def test_requires
foo_notify = bar_notify = baz_notify = nil
configure_from_scratch do
foo_notify = notify foo do
requires notify bar and requires notify baz
foo_message
end
bar_notify = notify bar
baz_notify = notify baz do
requires notify bar
baz_message
end
end
assert_equal 2, foo_notify.requires.count
assert foo_notify.requires?("notify('bar')", "notify('baz')")
assert_equal 0, bar_notify.requires.count
refute bar_notify.requires?('foo')
assert_equal 1, baz_notify.requires.count
assert baz_notify.requires?("notify('bar')")
end
def test_requires_invalid_resource
assert_raises(NameError) do
configure_from_scratch do
notify { requires invalid('baz') }
end
end
end
def test_requires_non_existant_dependency
assert_raises(RCM::Resource::NoSuchResourceObject) do
configure_from_scratch do
notify do
requires notify nonexistant
end
end
end
end
def test_dependency_loop
assert_raises(RCM::DependencyEvaluator::DependencyLoop) do
configure_from_scratch do
notify looper do
requires notify looper
end
end
end
end
def test_dependency_loop_indirect
assert_raises(RCM::DependencyEvaluator::DependencyLoop) do
configure_from_scratch do
notify looper do
requires notify pooler
end
notify pooler do
requires notify looper
end
end
end
end
def test_configure_from_scratch_uses_current_resource_registry
first = second = nil
configure_from_scratch do
first = notify same do
first_run
end
end
configure_from_scratch do
second = notify same do
second_run
end
end
found = RCM::Resource.find("notify('same')")
refute_same first, found
assert_same second, found
end
end
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|