Sha256: e7873c79ebdd01b53d756e7d1baf05452f0324623989d1e45fd0c0a4bd49feef

Contents?: true

Size: 1.45 KB

Versions: 10

Compression:

Stored size: 1.45 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[:arguments] + @invocation[:options] if @invocation.include[:arguments]
      end

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

      # Public methods

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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
bolt-1.14.0 lib/bolt_spec/plans/action_stubs/script_stub.rb
bolt-1.13.1 lib/bolt_spec/plans/action_stubs/script_stub.rb
bolt-1.13.0 lib/bolt_spec/plans/action_stubs/script_stub.rb
bolt-1.12.0 lib/bolt_spec/plans/action_stubs/script_stub.rb
bolt-1.11.0 lib/bolt_spec/plans/action_stubs/script_stub.rb
bolt-1.10.0 lib/bolt_spec/plans/action_stubs/script_stub.rb
bolt-1.9.0 lib/bolt_spec/plans/action_stubs/script_stub.rb
bolt-1.8.1 lib/bolt_spec/plans/action_stubs/script_stub.rb
bolt-1.8.0 lib/bolt_spec/plans/action_stubs/script_stub.rb
bolt-1.7.0 lib/bolt_spec/plans/action_stubs/script_stub.rb