Class: BoltSpec::Plans::MockExecutor
- Inherits:
-
Object
- Object
- BoltSpec::Plans::MockExecutor
- Defined in:
- lib/bolt_spec/plans/mock_executor.rb
Overview
Nothing on the executor is ‘public’
Instance Attribute Summary collapse
-
#error_message ⇒ Object
readonly
Returns the value of attribute error_message.
-
#noop ⇒ Object
readonly
Returns the value of attribute noop.
-
#run_as ⇒ Object
Returns the value of attribute run_as.
Instance Method Summary collapse
- #assert_call_expectations ⇒ Object
- #await_results(promises) ⇒ Object
-
#initialize(modulepath) ⇒ MockExecutor
constructor
A new instance of MockExecutor.
- #log_action(*_args) ⇒ Object
- #log_plan(_plan_name) ⇒ Object
- #module_file_id(file) ⇒ Object
- #queue_execute(targets) ⇒ Object
- #report_apply(_statements, _resources) ⇒ Object
- #report_bundled_content(_mode, _name) ⇒ Object
- #report_function_call(_function) ⇒ Object
- #run_command(targets, command, options = {}) ⇒ Object
- #run_script(targets, script_path, arguments, options = {}) ⇒ Object
- #run_task(targets, task, arguments, options = {}) ⇒ Object
- #stub_apply ⇒ Object
-
#transport(_protocol) ⇒ Object
Mocked for apply_prep.
- #upload_file(targets, source_path, destination, options = {}) ⇒ Object
- #wait_until_available(targets, _options) ⇒ Object
-
#with_node_logging(_description, targets) ⇒ Object
Mocked for Apply so it does not compile and execute.
- #without_default_logging ⇒ Object
Constructor Details
#initialize(modulepath) ⇒ MockExecutor
Returns a new instance of MockExecutor.
21 22 23 24 25 26 27 28 |
# File 'lib/bolt_spec/plans/mock_executor.rb', line 21 def initialize(modulepath) @noop = false @run_as = nil = nil @allow_apply = false @modulepath = [modulepath].flatten.map { |path| File.absolute_path(path) } MOCKED_ACTIONS.each { |action| instance_variable_set(:"@#{action}_doubles", {}) } end |
Instance Attribute Details
#error_message ⇒ Object (readonly)
Returns the value of attribute error_message.
18 19 20 |
# File 'lib/bolt_spec/plans/mock_executor.rb', line 18 def end |
#noop ⇒ Object (readonly)
Returns the value of attribute noop.
18 19 20 |
# File 'lib/bolt_spec/plans/mock_executor.rb', line 18 def noop @noop end |
#run_as ⇒ Object
Returns the value of attribute run_as.
19 20 21 |
# File 'lib/bolt_spec/plans/mock_executor.rb', line 19 def run_as @run_as end |
Instance Method Details
#assert_call_expectations ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/bolt_spec/plans/mock_executor.rb', line 96 def assert_call_expectations MOCKED_ACTIONS.each do |action| instance_variable_get(:"@#{action}_doubles").map do |object, doub| doub.assert_called(object) end end end |
#await_results(promises) ⇒ Object
146 147 148 149 |
# File 'lib/bolt_spec/plans/mock_executor.rb', line 146 def await_results(promises) raise "Unexpected call to apply(#{targets})" unless @allow_apply Bolt::ResultSet.new(promises.map { |target| Bolt::ApplyResult.new(target) }) end |
#log_action(*_args) ⇒ Object
118 119 120 |
# File 'lib/bolt_spec/plans/mock_executor.rb', line 118 def log_action(*_args) yield end |
#log_plan(_plan_name) ⇒ Object
122 123 124 |
# File 'lib/bolt_spec/plans/mock_executor.rb', line 122 def log_plan(_plan_name) yield end |
#module_file_id(file) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/bolt_spec/plans/mock_executor.rb', line 30 def module_file_id(file) modpath = @modulepath.select { |path| file =~ /^#{path}/ } raise "Could not identify module path containing #{file}: #{modpath}" unless modpath.size == 1 path = Pathname.new(file) relative = path.relative_path_from(Pathname.new(modpath.first)) segments = relative.to_path.split('/') ([segments[0]] + segments[2..-1]).join('/') end |
#queue_execute(targets) ⇒ Object
141 142 143 144 |
# File 'lib/bolt_spec/plans/mock_executor.rb', line 141 def queue_execute(targets) raise "Unexpected call to apply(#{targets})" unless @allow_apply targets end |
#report_apply(_statements, _resources) ⇒ Object
134 |
# File 'lib/bolt_spec/plans/mock_executor.rb', line 134 def report_apply(_statements, _resources); end |
#report_bundled_content(_mode, _name) ⇒ Object
132 |
# File 'lib/bolt_spec/plans/mock_executor.rb', line 132 def report_bundled_content(_mode, _name); end |
#report_function_call(_function) ⇒ Object
130 |
# File 'lib/bolt_spec/plans/mock_executor.rb', line 130 def report_function_call(_function); end |
#run_command(targets, command, options = {}) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/bolt_spec/plans/mock_executor.rb', line 40 def run_command(targets, command, = {}) result = nil if (doub = @command_doubles[command] || @command_doubles[:default]) result = doub.process(targets, command, ) end unless result targets = targets.map(&:name) = "Unexpected call to 'run_command(#{command}, #{targets}, #{options})'" raise UnexpectedInvocation, end result end |
#run_script(targets, script_path, arguments, options = {}) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/bolt_spec/plans/mock_executor.rb', line 53 def run_script(targets, script_path, arguments, = {}) script = module_file_id(script_path) result = nil if (doub = @script_doubles[script] || @script_doubles[:default]) result = doub.process(targets, script, arguments, ) end unless result targets = targets.map(&:name) params = .merge('arguments' => arguments) = "Unexpected call to 'run_script(#{script}, #{targets}, #{params})'" raise UnexpectedInvocation, end result end |
#run_task(targets, task, arguments, options = {}) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/bolt_spec/plans/mock_executor.rb', line 68 def run_task(targets, task, arguments, = {}) result = nil if (doub = @task_doubles[task.name] || @task_doubles[:default]) result = doub.process(targets, task.name, arguments, ) end unless result targets = targets.map(&:name) params = arguments.merge() = "Unexpected call to 'run_task(#{task.name}, #{targets}, #{params})'" raise UnexpectedInvocation, end result end |
#stub_apply ⇒ Object
110 111 112 |
# File 'lib/bolt_spec/plans/mock_executor.rb', line 110 def stub_apply @allow_apply = true end |
#transport(_protocol) ⇒ Object
Mocked for apply_prep
153 154 155 156 157 158 159 160 |
# File 'lib/bolt_spec/plans/mock_executor.rb', line 153 def transport(_protocol) # Always return a transport that includes the puppet-agent feature so version/install are skipped. Class.new do def provided_features ['puppet-agent'] end end.new end |
#upload_file(targets, source_path, destination, options = {}) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/bolt_spec/plans/mock_executor.rb', line 82 def upload_file(targets, source_path, destination, = {}) source = module_file_id(source_path) result = nil if (doub = @upload_doubles[source] || @upload_doubles[:default]) result = doub.process(targets, source, destination, ) end unless result targets = targets.map(&:name) = "Unexpected call to 'upload_file(#{source}, #{destination}, #{targets}, #{options})'" raise UnexpectedInvocation, end result end |
#wait_until_available(targets, _options) ⇒ Object
114 115 116 |
# File 'lib/bolt_spec/plans/mock_executor.rb', line 114 def wait_until_available(targets, ) Bolt::ResultSet.new(targets.map { |target| Bolt::Result.new(target) }) end |
#with_node_logging(_description, targets) ⇒ Object
Mocked for Apply so it does not compile and execute.
137 138 139 |
# File 'lib/bolt_spec/plans/mock_executor.rb', line 137 def with_node_logging(_description, targets) raise "Unexpected call to apply(#{targets})" unless @allow_apply end |
#without_default_logging ⇒ Object
126 127 128 |
# File 'lib/bolt_spec/plans/mock_executor.rb', line 126 def without_default_logging yield end |