inprovise 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,209 @@
1
+ # ScriptRunner tests for Inprovise
2
+ #
3
+ # Author:: Martin Corino
4
+ # License:: Distributes under the same license as Ruby
5
+
6
+ require_relative 'test_helper'
7
+
8
+ describe Inprovise::ScriptRunner do
9
+ before :each do
10
+ @node = Inprovise::Infrastructure::Node.new('myNode', {channel: 'test', helper: 'test'})
11
+ Inprovise::DSL.module_eval do
12
+
13
+ script 'first' do
14
+ apply do
15
+ end
16
+
17
+ revert do
18
+ end
19
+ end
20
+
21
+ script 'second' do
22
+ depends_on 'first'
23
+ end
24
+
25
+ script 'third' do
26
+ depends_on 'second'
27
+ end
28
+
29
+ script 'four' do
30
+ triggers 'third'
31
+ end
32
+
33
+ script 'validate' do
34
+ apply do
35
+ end
36
+
37
+ revert do
38
+ end
39
+
40
+ validate do
41
+ end
42
+ end
43
+
44
+ script 'invalid' do
45
+ validate do
46
+ false
47
+ end
48
+ end
49
+
50
+ end
51
+ end
52
+
53
+ after :each do
54
+ reset_script_index!
55
+ reset_infrastructure!
56
+ end
57
+
58
+ describe 'dependencies' do
59
+ it 'resolves a script without dependencies' do
60
+ @runner = Inprovise::ScriptRunner.new(@node, 'first')
61
+ @runner.scripts.collect {|s| s.name }.must_equal %w(first)
62
+ end
63
+
64
+ it 'resolves a script with dependencies' do
65
+ @runner = Inprovise::ScriptRunner.new(@node, 'second')
66
+ @runner.scripts.collect {|s| s.name }.must_equal %w(first second)
67
+ end
68
+
69
+ it 'resolves a triggering script' do
70
+ @runner = Inprovise::ScriptRunner.new(@node, 'four')
71
+ @runner.scripts.collect {|s| s.name }.must_equal %w(four first second third)
72
+ end
73
+ end
74
+
75
+ describe 'execute' do
76
+
77
+ describe 'apply' do
78
+ it 'applies a script without dependencies' do
79
+ @runner = Inprovise::ScriptRunner.new(@node, 'first')
80
+ @runner.expects(:execute_apply).once
81
+ .with() { |script, context| script.name.must_equal('first') && Inprovise::ExecutionContext === context }
82
+ @runner.execute(:apply)
83
+ end
84
+
85
+ it 'applies a script with dependencies' do
86
+ @runner = Inprovise::ScriptRunner.new(@node, 'second')
87
+ expected_script_order = %w(first second)
88
+ @runner.expects(:execute_apply).twice
89
+ .with() { |script, context| script.name.must_equal(expected_script_order.shift) && Inprovise::ExecutionContext === context }
90
+ @runner.execute(:apply)
91
+ end
92
+
93
+ it 'applies a triggering script' do
94
+ @runner = Inprovise::ScriptRunner.new(@node, 'four')
95
+ expected_script_order = %w(four first second third)
96
+ @runner.expects(:execute_apply).times(4)
97
+ .with() { |script, context| script.name.must_equal(expected_script_order.shift) && Inprovise::ExecutionContext === context }
98
+ @runner.execute(:apply)
99
+ end
100
+
101
+ it 'validates before and after applying a script' do
102
+ @runner = Inprovise::ScriptRunner.new(@node, 'validate')
103
+ @runner.expects(:exec).once
104
+ .with() { |script, cmd, context| script.name.must_equal('validate') && Inprovise::ExecutionContext === context && cmd == :apply }
105
+ @runner.expects(:is_valid?).twice
106
+ .with() { |script, context| script.name.must_equal('validate') && Inprovise::ExecutionContext === context }
107
+ .returns(false, true)
108
+ @runner.execute(:apply)
109
+ end
110
+ end
111
+
112
+ describe 'revert' do
113
+ it 'reverts a script without dependencies' do
114
+ @runner = Inprovise::ScriptRunner.new(@node, 'first')
115
+ @runner.expects(:execute_revert).once
116
+ .with() { |script, context| script.name.must_equal('first') && Inprovise::ExecutionContext === context }
117
+ @runner.execute(:revert)
118
+ end
119
+
120
+ it 'reverts a script with dependencies' do
121
+ @runner = Inprovise::ScriptRunner.new(@node, 'second')
122
+ expected_script_order = %w(first second).reverse
123
+ @runner.expects(:execute_revert).twice
124
+ .with() { |script, context| script.name.must_equal(expected_script_order.shift) && Inprovise::ExecutionContext === context }
125
+ @runner.execute(:revert)
126
+ end
127
+
128
+ it 'reverts a triggering script' do
129
+ @runner = Inprovise::ScriptRunner.new(@node, 'four')
130
+ expected_script_order = %w(four first second third).reverse
131
+ @runner.expects(:execute_revert).times(4)
132
+ .with() { |script, context| script.name.must_equal(expected_script_order.shift) && Inprovise::ExecutionContext === context }
133
+ @runner.execute(:revert)
134
+ end
135
+
136
+ it 'validates before reverting a script' do
137
+ @runner = Inprovise::ScriptRunner.new(@node, 'validate')
138
+ @runner.expects(:exec).once
139
+ .with() { |script, cmd, context| script.name.must_equal('validate') && Inprovise::ExecutionContext === context && cmd == :revert }
140
+ @runner.expects(:is_valid?).once
141
+ .with() { |script, context| script.name.must_equal('validate') && Inprovise::ExecutionContext === context }
142
+ .returns(true)
143
+ @runner.execute(:revert)
144
+ end
145
+ end
146
+
147
+ describe 'validate' do
148
+ it 'validates a script without dependencies' do
149
+ @runner = Inprovise::ScriptRunner.new(@node, 'first')
150
+ @runner.expects(:execute_validate).once
151
+ .with() { |script, context| script.name.must_equal('first') && Inprovise::ExecutionContext === context }
152
+ @runner.execute(:validate)
153
+ end
154
+
155
+ it 'validates a script with dependencies' do
156
+ @runner = Inprovise::ScriptRunner.new(@node, 'second')
157
+ expected_script_order = %w(first second)
158
+ @runner.expects(:execute_validate).twice
159
+ .with() { |script, context| script.name.must_equal(expected_script_order.shift) && Inprovise::ExecutionContext === context }
160
+ @runner.execute(:validate)
161
+ end
162
+
163
+ it 'validates a triggering script' do
164
+ @runner = Inprovise::ScriptRunner.new(@node, 'four')
165
+ expected_script_order = %w(four first second third)
166
+ @runner.expects(:execute_validate).times(4)
167
+ .with() { |script, context| script.name.must_equal(expected_script_order.shift) && Inprovise::ExecutionContext === context }
168
+ @runner.execute(:validate)
169
+ end
170
+
171
+ it 'throws on validating an invalid script' do
172
+ @runner = Inprovise::ScriptRunner.new(@node, 'validate')
173
+ @runner.expects(:is_valid?).once
174
+ .with() { |script, context| script.name.must_equal('validate') && Inprovise::ExecutionContext === context }
175
+ .returns(false)
176
+ assert_raises Inprovise::ScriptRunner::ValidationFailureError do
177
+ @runner.execute(:validate)
178
+ end
179
+ end
180
+ end
181
+ end
182
+
183
+ describe 'demonstrate' do
184
+ describe 'apply' do
185
+ it 'demonstrates applying a script without dependencies' do
186
+ @runner = Inprovise::ScriptRunner.new(@node, 'first')
187
+ @runner.expects(:execute_apply).once
188
+ .with() { |script, context| script.name.must_equal('first') && Inprovise::MockExecutionContext === context }
189
+ @runner.demonstrate(:apply)
190
+ end
191
+
192
+ it 'demonstrates applying a script with dependencies' do
193
+ @runner = Inprovise::ScriptRunner.new(@node, 'second')
194
+ expected_script_order = %w(first second)
195
+ @runner.expects(:execute_apply).twice
196
+ .with() { |script, context| script.name.must_equal(expected_script_order.shift) && Inprovise::MockExecutionContext === context }
197
+ @runner.demonstrate(:apply)
198
+ end
199
+
200
+ it 'demonstrates applying a triggering script' do
201
+ @runner = Inprovise::ScriptRunner.new(@node, 'four')
202
+ expected_script_order = %w(four first second third)
203
+ @runner.expects(:execute_apply).times(4)
204
+ .with() { |script, context| script.name.must_equal(expected_script_order.shift) && Inprovise::MockExecutionContext === context }
205
+ @runner.demonstrate(:apply)
206
+ end
207
+ end
208
+ end
209
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inprovise
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Corino
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-01 00:00:00.000000000 Z
11
+ date: 2016-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colored
@@ -88,6 +88,7 @@ executables:
88
88
  extensions: []
89
89
  extra_rdoc_files: []
90
90
  files:
91
+ - .codeclimate.yml
91
92
  - .gitignore
92
93
  - .travis.yml
93
94
  - Gemfile
@@ -135,11 +136,13 @@ files:
135
136
  - test/fixtures/include.rb
136
137
  - test/fixtures/inprovise.rb
137
138
  - test/fixtures/myscheme.rb
139
+ - test/helper_test.rb
138
140
  - test/infra_test.rb
139
141
  - test/local_file_test.rb
140
142
  - test/remote_file_test.rb
141
143
  - test/resolver_test.rb
142
144
  - test/script_index_test.rb
145
+ - test/script_runner_test.rb
143
146
  - test/script_test.rb
144
147
  - test/test_helper.rb
145
148
  homepage: https://github.com/mcorino/Inprovise
@@ -174,10 +177,12 @@ test_files:
174
177
  - test/fixtures/include.rb
175
178
  - test/fixtures/inprovise.rb
176
179
  - test/fixtures/myscheme.rb
180
+ - test/helper_test.rb
177
181
  - test/infra_test.rb
178
182
  - test/local_file_test.rb
179
183
  - test/remote_file_test.rb
180
184
  - test/resolver_test.rb
181
185
  - test/script_index_test.rb
186
+ - test/script_runner_test.rb
182
187
  - test/script_test.rb
183
188
  - test/test_helper.rb