Module: BoltSpec::Plans
- Defined in:
- lib/bolt_spec/plans.rb,
lib/bolt_spec/plans/action_stubs.rb,
lib/bolt_spec/plans/publish_stub.rb,
lib/bolt_spec/plans/mock_executor.rb,
lib/bolt_spec/plans/action_stubs/task_stub.rb,
lib/bolt_spec/plans/action_stubs/script_stub.rb,
lib/bolt_spec/plans/action_stubs/upload_stub.rb,
lib/bolt_spec/plans/action_stubs/command_stub.rb
Defined Under Namespace
Classes: ActionDouble, ActionStub, CommandStub, MockExecutor, MockPuppetDBClient, PublishStub, ScriptStub, TaskStub, UnexpectedInvocation, UploadStub
Constant Summary
collapse
- MOCKED_ACTIONS =
%i[command script task upload].freeze
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.init ⇒ Object
145
146
147
148
149
150
151
152
153
|
# File 'lib/bolt_spec/plans.rb', line 145
def self.init
Bolt::PAL.load_puppet
Puppet[:tasks] = true
Logging.init :debug, :info, :notice, :warn, :error, :fatal, :any
end
|
Instance Method Details
#allow_apply ⇒ Object
238
239
240
241
|
# File 'lib/bolt_spec/plans.rb', line 238
def allow_apply
executor.stub_apply
nil
end
|
#allow_apply_prep ⇒ Object
233
234
235
236
|
# File 'lib/bolt_spec/plans.rb', line 233
def allow_apply_prep
allow_task('apply_helpers::custom_facts')
nil
end
|
#allow_get_resources ⇒ Object
243
244
245
246
|
# File 'lib/bolt_spec/plans.rb', line 243
def allow_get_resources
allow_task('apply_helpers::query_resources')
nil
end
|
#allow_out_message ⇒ Object
Also known as:
allow_any_out_message
248
249
250
|
# File 'lib/bolt_spec/plans.rb', line 248
def allow_out_message
executor.stub_out_message.add_stub
end
|
#config ⇒ Object
170
171
172
173
174
175
176
|
# File 'lib/bolt_spec/plans.rb', line 170
def config
@config ||= begin
conf = Bolt::Config.new(Bolt::Boltdir.new('.'), {})
conf.modulepath = [modulepath].flatten
conf
end
end
|
#executor ⇒ Object
intended to be private below here
#expect_out_message ⇒ Object
253
254
255
|
# File 'lib/bolt_spec/plans.rb', line 253
def expect_out_message
allow_out_message.expect_call
end
|
#inventory ⇒ Object
183
184
185
|
# File 'lib/bolt_spec/plans.rb', line 183
def inventory
@inventory ||= Bolt::Inventory.create_version(inventory_data, config, plugins)
end
|
#inventory_data ⇒ Object
179
180
181
|
# File 'lib/bolt_spec/plans.rb', line 179
def inventory_data
{}
end
|
#modulepath ⇒ Object
Override in your tests if needed
156
157
158
159
160
|
# File 'lib/bolt_spec/plans.rb', line 156
def modulepath
[RSpec.configuration.module_path]
rescue NoMethodError
raise "RSpec.configuration.module_path not defined set up rspec puppet or define modulepath for this test"
end
|
#pal ⇒ Object
194
195
196
|
# File 'lib/bolt_spec/plans.rb', line 194
def pal
@pal ||= Bolt::PAL.new(config.modulepath, config.hiera_config, config.boltdir.resource_types)
end
|
#puppetdb_client ⇒ Object
190
191
192
|
# File 'lib/bolt_spec/plans.rb', line 190
def puppetdb_client
@puppetdb_client ||= MockPuppetDBClient.new
end
|
#run_plan(name, params) ⇒ Object
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
# File 'lib/bolt_spec/plans.rb', line 198
def run_plan(name, params)
pal = Bolt::PAL.new(config.modulepath, config.hiera_config, config.boltdir.resource_types)
result = pal.run_plan(name, params, executor, inventory, puppetdb_client)
if executor.error_message
raise executor.error_message
end
begin
executor.assert_call_expectations
rescue StandardError => e
raise "#{e.message}\nPlan result: #{result}"
end
result
end
|