Sha256: 596e1552bbf2224a5a1e20e413ddfb4d21fbbfe3a873a06b53b9f28b75114edd

Contents?: true

Size: 1.68 KB

Versions: 29

Compression:

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

    File.should_not be_exist(path)
  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

    File.should_not be_exist(path)
  end
end

Version data entries

29 entries across 29 versions & 2 rubygems

Version Path
puppet-3.3.2 spec/integration/type/exec_spec.rb
puppet-3.3.1 spec/integration/type/exec_spec.rb
puppet-3.3.1.rc3 spec/integration/type/exec_spec.rb
puppet-3.3.1.rc2 spec/integration/type/exec_spec.rb
puppet-3.3.1.rc1 spec/integration/type/exec_spec.rb
puppet-3.3.0 spec/integration/type/exec_spec.rb
puppet-3.3.0.rc3 spec/integration/type/exec_spec.rb
puppet-3.3.0.rc2 spec/integration/type/exec_spec.rb
puppet-3.2.4 spec/integration/type/exec_spec.rb
puppet-3.2.3 spec/integration/type/exec_spec.rb
puppet-3.2.3.rc1 spec/integration/type/exec_spec.rb
puppet-3.2.2 spec/integration/type/exec_spec.rb
puppet-3.2.1 spec/integration/type/exec_spec.rb
puppet-3.2.1.rc1 spec/integration/type/exec_spec.rb
puppet-3.2.0.rc2 spec/integration/type/exec_spec.rb
librarian-puppet-0.9.9 vendor/gems/ruby/1.9.1/gems/puppet-3.1.0/spec/integration/type/exec_spec.rb
puppet-3.2.0.rc1 spec/integration/type/exec_spec.rb
puppet-3.1.1 spec/integration/type/exec_spec.rb
librarian-puppet-0.9.8 vendor/gems/ruby/1.9.1/gems/puppet-3.1.0/spec/integration/type/exec_spec.rb
puppet-3.1.0 spec/integration/type/exec_spec.rb