Sha256: 05035a368bfcd72cc5f0face8168ddc005930ecb9ea8343feb8c002616f0f8e2

Contents?: true

Size: 1.52 KB

Versions: 15

Compression:

Stored size: 1.52 KB

Contents

# frozen_string_literal: true

module BoltSpec
  module Plans
    class ScriptStub < ActionStub
      def matches(targets, _script, arguments, options)
        if @invocation[:targets] && Set.new(@invocation[:targets]) != Set.new(targets.map(&:name))
          return false
        end

        if @invocation[:arguments] && arguments != @invocation[:arguments]
          return false
        end

        if @invocation[:options] && options != @invocation[:options]
          return false
        end

        true
      end

      def call(targets, script, arguments, options)
        @calls += 1
        if @return_block
          # Merge arguments and options into params to match puppet function signature.
          params = options.merge('arguments' => arguments)
          check_resultset(@return_block.call(targets: targets, script: script, params: params), script)
        else
          Bolt::ResultSet.new(targets.map { |target| @data[target.name] || default_for(target) })
        end
      end

      def parameters
        @invocation[:params]
      end

      def result_for(target, stdout: '', stderr: '')
        Bolt::Result.for_command(target, stdout, stderr, 0, 'script', '', [])
      end

      # Public methods

      def with_params(params)
        @invocation[:params] = params
        @invocation[:arguments] = params['arguments']
        @invocation[:options] = params.select { |k, _v| k.start_with?('_') }
                                      .transform_keys { |k| k.sub(/^_/, '').to_sym }
        self
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
bolt-3.3.0 lib/bolt_spec/plans/action_stubs/script_stub.rb
bolt-3.1.0 lib/bolt_spec/plans/action_stubs/script_stub.rb
bolt-3.0.1 lib/bolt_spec/plans/action_stubs/script_stub.rb
bolt-3.0.0 lib/bolt_spec/plans/action_stubs/script_stub.rb
bolt-2.44.0 lib/bolt_spec/plans/action_stubs/script_stub.rb
bolt-2.42.0 lib/bolt_spec/plans/action_stubs/script_stub.rb
bolt-2.40.2 lib/bolt_spec/plans/action_stubs/script_stub.rb
bolt-2.40.1 lib/bolt_spec/plans/action_stubs/script_stub.rb
bolt-2.38.0 lib/bolt_spec/plans/action_stubs/script_stub.rb
bolt-2.37.0 lib/bolt_spec/plans/action_stubs/script_stub.rb
bolt-2.36.0 lib/bolt_spec/plans/action_stubs/script_stub.rb
bolt-2.35.0 lib/bolt_spec/plans/action_stubs/script_stub.rb
bolt-2.34.0 lib/bolt_spec/plans/action_stubs/script_stub.rb
bolt-2.33.2 lib/bolt_spec/plans/action_stubs/script_stub.rb
bolt-2.33.1 lib/bolt_spec/plans/action_stubs/script_stub.rb