Sha256: 088dac61a88f356b8e3425723ebbddd508e9290cffb666ec7d82d0c3a11e508d

Contents?: true

Size: 1.87 KB

Versions: 234

Compression:

Stored size: 1.87 KB

Contents

#! /usr/bin/env ruby
require 'spec_helper'

require 'puppet/indirector/exec'

describe Puppet::Indirector::Exec do
  before :all do
    @indirection = stub 'indirection', :name => :testing
    Puppet::Indirector::Indirection.expects(:instance).with(:testing).returns(@indirection)
    module Testing; end
    @exec_class = class Testing::MyTesting < Puppet::Indirector::Exec
      attr_accessor :command
      self
    end
  end

  let(:path) { File.expand_path('/echo') }
  let(:arguments) { {:failonfail => true, :combine => false } }

  before :each do
    @searcher = @exec_class.new
    @searcher.command = [path]

    @request = stub 'request', :key => "foo"
  end

  it "should throw an exception if the command is not an array" do
    @searcher.command = path
    expect { @searcher.find(@request) }.to raise_error(Puppet::DevError)
  end

  it "should throw an exception if the command is not fully qualified" do
    @searcher.command = ["mycommand"]
    expect { @searcher.find(@request) }.to raise_error(ArgumentError)
  end

  it "should execute the command with the object name as the only argument" do
    @searcher.expects(:execute).with([path, 'foo'], arguments)
    @searcher.find(@request)
  end

  it "should return the output of the script" do
    @searcher.expects(:execute).with([path, 'foo'], arguments).returns("whatever")
    expect(@searcher.find(@request)).to eq("whatever")
  end

  it "should return nil when the command produces no output" do
    @searcher.expects(:execute).with([path, 'foo'], arguments).returns(nil)
    expect(@searcher.find(@request)).to be_nil
  end

  it "should raise an exception if there's an execution failure" do
    @searcher.expects(:execute).with([path, 'foo'], arguments).raises(Puppet::ExecutionFailure.new("message"))
    expect {
      @searcher.find(@request)
    }.to raise_exception(Puppet::Error, 'Failed to find foo via exec: message')
  end
end

Version data entries

234 entries across 234 versions & 1 rubygems

Version Path
puppet-5.5.3 spec/unit/indirector/exec_spec.rb
puppet-5.5.3-x86-mingw32 spec/unit/indirector/exec_spec.rb
puppet-5.5.3-x64-mingw32 spec/unit/indirector/exec_spec.rb
puppet-5.5.3-universal-darwin spec/unit/indirector/exec_spec.rb
puppet-5.5.2 spec/unit/indirector/exec_spec.rb
puppet-5.5.2-x86-mingw32 spec/unit/indirector/exec_spec.rb
puppet-5.5.2-x64-mingw32 spec/unit/indirector/exec_spec.rb
puppet-5.5.2-universal-darwin spec/unit/indirector/exec_spec.rb
puppet-5.3.7 spec/unit/indirector/exec_spec.rb
puppet-5.3.7-x86-mingw32 spec/unit/indirector/exec_spec.rb
puppet-5.3.7-x64-mingw32 spec/unit/indirector/exec_spec.rb
puppet-5.3.7-universal-darwin spec/unit/indirector/exec_spec.rb
puppet-4.10.12 spec/unit/indirector/exec_spec.rb
puppet-4.10.12-x86-mingw32 spec/unit/indirector/exec_spec.rb
puppet-4.10.12-x64-mingw32 spec/unit/indirector/exec_spec.rb
puppet-4.10.12-universal-darwin spec/unit/indirector/exec_spec.rb
puppet-5.5.1 spec/unit/indirector/exec_spec.rb
puppet-5.5.1-x86-mingw32 spec/unit/indirector/exec_spec.rb
puppet-5.5.1-x64-mingw32 spec/unit/indirector/exec_spec.rb
puppet-5.5.1-universal-darwin spec/unit/indirector/exec_spec.rb