Sha256: bd59e208d424640f42883bd07e80b75cbe1a2a387a5ac9989b4abbe62980ba49

Contents?: true

Size: 1.95 KB

Versions: 340

Compression:

Stored size: 1.95 KB

Contents

require 'spec_helper'

require 'puppet/provider/command'

describe Puppet::Provider::Command do
  let(:name) { "the name" }
  let(:the_options) { { :option => 1 } }
  let(:no_options) { {} }
  let(:executable) { "foo" }
  let(:executable_absolute_path) { "/foo/bar" }

  let(:executor) { double('executor') }
  let(:resolver) { double('resolver') }

  let(:path_resolves_to_itself) do
    resolves = Object.new
    class << resolves
      def which(path)
        path
      end
    end
    resolves
  end

  it "executes a simple command" do
    expect(executor).to receive(:execute).with([executable], no_options)

    command = Puppet::Provider::Command.new(name, executable, path_resolves_to_itself, executor)
    command.execute()
  end

  it "executes a command with extra options" do
    expect(executor).to receive(:execute).with([executable], the_options)

    command = Puppet::Provider::Command.new(name, executable, path_resolves_to_itself, executor, the_options)
    command.execute()
  end

  it "executes a command with arguments" do
    expect(executor).to receive(:execute).with([executable, "arg1", "arg2"], no_options)

    command = Puppet::Provider::Command.new(name, executable, path_resolves_to_itself, executor)
    command.execute("arg1", "arg2")
  end

  it "resolves to an absolute path for better execution" do
    expect(resolver).to receive(:which).with(executable).and_return(executable_absolute_path)
    expect(executor).to receive(:execute).with([executable_absolute_path], no_options)

    command = Puppet::Provider::Command.new(name, executable, resolver, executor)
    command.execute()
  end

  it "errors when the executable resolves to nothing" do
    expect(resolver).to receive(:which).with(executable).and_return(nil)
    expect(executor).not_to receive(:execute)

    command = Puppet::Provider::Command.new(name, executable, resolver, executor)

    expect { command.execute() }.to raise_error(Puppet::Error, "Command #{name} is missing")
  end
end

Version data entries

340 entries across 340 versions & 1 rubygems

Version Path
puppet-7.24.0 spec/unit/provider/command_spec.rb
puppet-7.24.0-x86-mingw32 spec/unit/provider/command_spec.rb
puppet-7.24.0-x64-mingw32 spec/unit/provider/command_spec.rb
puppet-7.24.0-universal-darwin spec/unit/provider/command_spec.rb
puppet-7.23.0 spec/unit/provider/command_spec.rb
puppet-7.23.0-x86-mingw32 spec/unit/provider/command_spec.rb
puppet-7.23.0-x64-mingw32 spec/unit/provider/command_spec.rb
puppet-7.23.0-universal-darwin spec/unit/provider/command_spec.rb
puppet-7.22.0 spec/unit/provider/command_spec.rb
puppet-7.22.0-x86-mingw32 spec/unit/provider/command_spec.rb
puppet-7.22.0-x64-mingw32 spec/unit/provider/command_spec.rb
puppet-7.22.0-universal-darwin spec/unit/provider/command_spec.rb
puppet-6.29.0 spec/unit/provider/command_spec.rb
puppet-6.29.0-x86-mingw32 spec/unit/provider/command_spec.rb
puppet-6.29.0-x64-mingw32 spec/unit/provider/command_spec.rb
puppet-6.29.0-universal-darwin spec/unit/provider/command_spec.rb
puppet-7.21.0 spec/unit/provider/command_spec.rb
puppet-7.21.0-x86-mingw32 spec/unit/provider/command_spec.rb
puppet-7.21.0-x64-mingw32 spec/unit/provider/command_spec.rb
puppet-7.21.0-universal-darwin spec/unit/provider/command_spec.rb