Sha256: 50f1aae362f7f4e06f88be239aff0759a581b0f2f10b36e92612af2c6749fa31

Contents?: true

Size: 1.78 KB

Versions: 44

Compression:

Stored size: 1.78 KB

Contents

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

require 'puppet_spec/files'

describe Puppet::Type.type(:exec), unless: Puppet::Util::Platform.jruby? 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

44 entries across 44 versions & 1 rubygems

Version Path
puppet-6.4.0 spec/integration/type/exec_spec.rb
puppet-6.4.0-x86-mingw32 spec/integration/type/exec_spec.rb
puppet-6.4.0-x64-mingw32 spec/integration/type/exec_spec.rb
puppet-6.4.0-universal-darwin spec/integration/type/exec_spec.rb
puppet-6.0.7 spec/integration/type/exec_spec.rb
puppet-6.0.7-x86-mingw32 spec/integration/type/exec_spec.rb
puppet-6.0.7-x64-mingw32 spec/integration/type/exec_spec.rb
puppet-6.0.7-universal-darwin spec/integration/type/exec_spec.rb
puppet-6.3.0 spec/integration/type/exec_spec.rb
puppet-6.3.0-x86-mingw32 spec/integration/type/exec_spec.rb
puppet-6.3.0-x64-mingw32 spec/integration/type/exec_spec.rb
puppet-6.3.0-universal-darwin spec/integration/type/exec_spec.rb
puppet-6.2.0 spec/integration/type/exec_spec.rb
puppet-6.2.0-x86-mingw32 spec/integration/type/exec_spec.rb
puppet-6.2.0-x64-mingw32 spec/integration/type/exec_spec.rb
puppet-6.2.0-universal-darwin spec/integration/type/exec_spec.rb
puppet-6.0.5 spec/integration/type/exec_spec.rb
puppet-6.0.5-x86-mingw32 spec/integration/type/exec_spec.rb
puppet-6.0.5-x64-mingw32 spec/integration/type/exec_spec.rb
puppet-6.0.5-universal-darwin spec/integration/type/exec_spec.rb