Sha256: d2a29edef0e3ba0637dfae64cda5b1b8f7c0ca6422655c9e490b5479189d0114

Contents?: true

Size: 1.35 KB

Versions: 38

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

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

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

        true
      end

      def call(targets, command, options)
        @calls += 1
        if @return_block
          check_resultset(@return_block.call(targets: targets, command: command, params: options), command)
        else
          Bolt::ResultSet.new(targets.map { |target| @data[target.name] || default_for(target) })
        end
      end

      def parameters
        @invocation[:options]
      end

      def result_for(target, stdout: '', stderr: '')
        value = {
          'stdout'        => stdout,
          'stderr'        => stderr,
          'merged_output' => "#{stdout}\n#{stderr}".strip,
          'exit_code'     => 0
        }

        Bolt::Result.for_command(target, value, 'command', '', [])
      end

      # Public methods

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

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
bolt-4.0.0 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-3.29.0 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-3.28.0 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-3.27.4 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-3.27.2 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-3.27.1 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-3.26.2 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-3.26.1 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-3.25.0 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-3.24.0 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-3.23.1 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-3.23.0 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-3.22.1 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-3.22.0 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-3.21.0 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-3.20.0 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-3.19.0 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-3.18.0 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-3.17.0 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-3.16.1 lib/bolt_spec/plans/action_stubs/command_stub.rb