Module: BoltSpec::Plans
- Includes:
- BoltContext
- 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/plan_stub.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,
lib/bolt_spec/plans/action_stubs/download_stub.rb
Defined Under Namespace
Classes: ActionDouble, ActionStub, CommandStub, DownloadStub, MockExecutor, MockPuppetDBClient, MockPuppetDBInstance, PlanStub, PublishStub, ScriptStub, TaskStub, UnexpectedInvocation, UploadStub
Constant Summary
collapse
- MOCKED_ACTIONS =
%i[command download plan script task upload].freeze
Class Method Summary
collapse
Instance Method Summary
collapse
#allow_out_message, #allow_out_verbose, #config, #config_data, #executor, #expect_out_message, #expect_out_verbose, #in_bolt_context, #inventory, #inventory_data, #modulepath, #pal, #plugins, #setup
Class Method Details
.init ⇒ Object
94
95
96
97
98
99
100
101
102
|
# File 'lib/bolt_spec/plans.rb', line 94
def self.init
Bolt::PAL.load_puppet
Puppet[:tasks] = true
Logging.init :trace, :debug, :info, :notice, :warn, :error, :fatal
end
|
Instance Method Details
#allow_apply ⇒ Object
160
161
162
163
|
# File 'lib/bolt_spec/plans.rb', line 160
def allow_apply
executor.stub_apply
nil
end
|
#allow_apply_prep ⇒ Object
155
156
157
158
|
# File 'lib/bolt_spec/plans.rb', line 155
def allow_apply_prep
allow_task('apply_helpers::custom_facts')
nil
end
|
#allow_get_resources ⇒ Object
165
166
167
168
|
# File 'lib/bolt_spec/plans.rb', line 165
def allow_get_resources
allow_task('apply_helpers::query_resources')
nil
end
|
#execute_any_plan ⇒ Object
Flag for the default behavior of executing sub-plans during testing By default we allow any sub-plan to be executed, no mocking required. Users can still mock out plans in this mode and the mocks will check for parameters and return values like normal. However, if a plan isn’t explicitly mocked out, it will be executed.
175
176
177
|
# File 'lib/bolt_spec/plans.rb', line 175
def execute_any_plan
executor.execute_any_plan = true
end
|
#execute_no_plan ⇒ Object
If you want to explicitly mock out all of the sub-plan calls, then call this prior to calling ‘run_plan()` along with setting up any mocks that you require. In this mode, any plan that is not explicitly mocked out will not be executed and an error will be thrown.
184
185
186
|
# File 'lib/bolt_spec/plans.rb', line 184
def execute_no_plan
executor.execute_any_plan = false
end
|
#puppetdb_client ⇒ Object
123
124
125
|
# File 'lib/bolt_spec/plans.rb', line 123
def puppetdb_client
@puppetdb_client ||= MockPuppetDBClient.new({})
end
|
#run_plan(name, params) ⇒ Object
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
# File 'lib/bolt_spec/plans.rb', line 127
def run_plan(name, params)
pal = Bolt::PAL.new(
Bolt::Config::Modulepath.new(config.modulepath),
config.hiera_config,
config.project.resource_types,
config.compile_concurrency,
config.trusted_external,
config.apply_settings,
config.project
)
result = executor.with_plan_allowed_exec(name, params) do
pal.run_plan(name, params, executor, inventory, puppetdb_client)
end
if executor.error_message
raise executor.error_message
end
begin
executor.assert_call_expectations
rescue StandardError => e
raise "#{e.message}\nPlan result: #{result}\n#{e.backtrace.join("\n")}"
end
result
end
|