Sha256: 948c4f9749f705007c8b278282fd926d33a1b9ec5cb7e183e05d933ffa3f02ee

Contents?: true

Size: 1.74 KB

Versions: 234

Compression:

Stored size: 1.74 KB

Contents

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

require 'puppet_spec/files'

describe Puppet::Type.type(:exec) do
  include PuppetSpec::Files

  let(:catalog) { Puppet::Resource::Catalog.new }
  let(:path) { tmpfile('exec_provider') }
  let(:command) { "ruby -e 'File.open(\"#{path}\", \"w\") { |f| f.print \"foo\" }'" }

  before :each do
    catalog.host_config = false
  end

  it "should execute the command" do
    exec = described_class.new :command => command, :path => ENV['PATH']

    catalog.add_resource exec
    catalog.apply

    expect(File.read(path)).to eq('foo')
  end

  it "should not execute the command if onlyif returns non-zero" do
    exec = described_class.new(
      :command => command,
      :onlyif => "ruby -e 'exit 44'",
      :path => ENV['PATH']
    )

    catalog.add_resource exec
    catalog.apply

    expect(Puppet::FileSystem.exist?(path)).to be_falsey
  end

  it "should execute the command if onlyif returns zero" do
    exec = described_class.new(
      :command => command,
      :onlyif => "ruby -e 'exit 0'",
      :path => ENV['PATH']
    )

    catalog.add_resource exec
    catalog.apply

    expect(File.read(path)).to eq('foo')
  end

  it "should execute the command if unless returns non-zero" do
    exec = described_class.new(
      :command => command,
      :unless => "ruby -e 'exit 45'",
      :path => ENV['PATH']
    )

    catalog.add_resource exec
    catalog.apply

    expect(File.read(path)).to eq('foo')
  end

  it "should not execute the command if unless returns zero" do
    exec = described_class.new(
      :command => command,
      :unless => "ruby -e 'exit 0'",
      :path => ENV['PATH']
    )

    catalog.add_resource exec
    catalog.apply

    expect(Puppet::FileSystem.exist?(path)).to be_falsey
  end
end

Version data entries

234 entries across 234 versions & 1 rubygems

Version Path
puppet-5.5.12 spec/integration/type/exec_spec.rb
puppet-5.5.12-x86-mingw32 spec/integration/type/exec_spec.rb
puppet-5.5.12-x64-mingw32 spec/integration/type/exec_spec.rb
puppet-5.5.12-universal-darwin spec/integration/type/exec_spec.rb
puppet-5.5.10 spec/integration/type/exec_spec.rb
puppet-5.5.10-x86-mingw32 spec/integration/type/exec_spec.rb
puppet-5.5.10-x64-mingw32 spec/integration/type/exec_spec.rb
puppet-5.5.10-universal-darwin spec/integration/type/exec_spec.rb
puppet-5.5.8 spec/integration/type/exec_spec.rb
puppet-5.5.8-x86-mingw32 spec/integration/type/exec_spec.rb
puppet-5.5.8-x64-mingw32 spec/integration/type/exec_spec.rb
puppet-5.5.8-universal-darwin spec/integration/type/exec_spec.rb
puppet-5.5.7 spec/integration/type/exec_spec.rb
puppet-5.5.7-x86-mingw32 spec/integration/type/exec_spec.rb
puppet-5.5.7-x64-mingw32 spec/integration/type/exec_spec.rb
puppet-5.5.7-universal-darwin spec/integration/type/exec_spec.rb
puppet-5.5.6 spec/integration/type/exec_spec.rb
puppet-5.5.6-x86-mingw32 spec/integration/type/exec_spec.rb
puppet-5.5.6-x64-mingw32 spec/integration/type/exec_spec.rb
puppet-5.5.6-universal-darwin spec/integration/type/exec_spec.rb