Sha256: 54b8c90989e11cc1d9d2937213d5c2f3bf8d5a260d615bdc9bd1048163a77097

Contents?: true

Size: 1.69 KB

Versions: 4

Compression:

Stored size: 1.69 KB

Contents

#! /usr/bin/env ruby -S rspec
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

4 entries across 4 versions & 1 rubygems

Version Path
puppet-3.0.0.rc8 spec/integration/type/exec_spec.rb
puppet-3.0.0.rc7 spec/integration/type/exec_spec.rb
puppet-3.0.0.rc5 spec/integration/type/exec_spec.rb
puppet-3.0.0.rc4 spec/integration/type/exec_spec.rb