Sha256: 83e2ad3e311050fa2c1473fc27d6643f96bcfd6bc13ad5b57c2269c5b2b28972

Contents?: true

Size: 1.72 KB

Versions: 57

Compression:

Stored size: 1.72 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

    File.read(path).should == '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

    Puppet::FileSystem.exist?(path).should be_false
  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

    File.read(path).should == '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

    File.read(path).should == '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

    Puppet::FileSystem.exist?(path).should be_false
  end
end

Version data entries

57 entries across 57 versions & 1 rubygems

Version Path
puppet-3.8.7 spec/integration/type/exec_spec.rb
puppet-3.8.7-x86-mingw32 spec/integration/type/exec_spec.rb
puppet-3.8.7-x64-mingw32 spec/integration/type/exec_spec.rb
puppet-3.8.6 spec/integration/type/exec_spec.rb
puppet-3.8.6-x86-mingw32 spec/integration/type/exec_spec.rb
puppet-3.8.6-x64-mingw32 spec/integration/type/exec_spec.rb
puppet-3.8.5 spec/integration/type/exec_spec.rb
puppet-3.8.5-x86-mingw32 spec/integration/type/exec_spec.rb
puppet-3.8.5-x64-mingw32 spec/integration/type/exec_spec.rb
puppet-3.8.4 spec/integration/type/exec_spec.rb
puppet-3.8.4-x86-mingw32 spec/integration/type/exec_spec.rb
puppet-3.8.4-x64-mingw32 spec/integration/type/exec_spec.rb
puppet-3.8.3 spec/integration/type/exec_spec.rb
puppet-3.8.3-x86-mingw32 spec/integration/type/exec_spec.rb
puppet-3.8.3-x64-mingw32 spec/integration/type/exec_spec.rb
puppet-3.8.2 spec/integration/type/exec_spec.rb
puppet-3.8.2-x86-mingw32 spec/integration/type/exec_spec.rb
puppet-3.8.2-x64-mingw32 spec/integration/type/exec_spec.rb
puppet-3.8.1 spec/integration/type/exec_spec.rb
puppet-3.8.1-x86-mingw32 spec/integration/type/exec_spec.rb