blob: 1e39bdb9fa72a3b7088569f033f8b18fa8bbb3bf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
#! /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
|