~ubuntu-branches/ubuntu/wily/puppet/wily-proposed

« back to all changes in this revision

Viewing changes to spec/unit/provider/exec/posix_spec.rb

  • Committer: Package Import Robot
  • Author(s): Stig Sandbeck Mathisen
  • Date: 2014-10-24 13:47:15 UTC
  • mfrom: (3.1.64 sid)
  • Revision ID: package-import@ubuntu.com-20141024134715-6ig54u0c4gar36ss
Tags: 3.7.2-1
* Imported upstream release 3.7.2
* Declare compliance with Debian Policy 3.9.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#! /usr/bin/env ruby
2
2
require 'spec_helper'
3
3
 
4
 
describe Puppet::Type.type(:exec).provider(:posix) do
 
4
describe Puppet::Type.type(:exec).provider(:posix), :if => Puppet.features.posix? do
5
5
  include PuppetSpec::Files
6
6
 
7
7
  def make_exe
8
8
    cmdpath = tmpdir('cmdpath')
9
9
    exepath = tmpfile('my_command', cmdpath)
10
 
    exepath = exepath + ".exe" if Puppet.features.microsoft_windows?
11
10
    FileUtils.touch(exepath)
12
11
    File.chmod(0755, exepath)
13
12
    exepath
14
13
  end
15
14
 
16
 
  let(:resource) { Puppet::Type.type(:exec).new(:title => File.expand_path('/foo'), :provider => :posix) }
 
15
  let(:resource) { Puppet::Type.type(:exec).new(:title => '/foo', :provider => :posix) }
17
16
  let(:provider) { described_class.new(resource) }
18
17
 
19
18
  describe "#validatecmd" do
31
30
 
32
31
    it "should pass if command is fully qualifed" do
33
32
      provider.resource[:path] = ['/bogus/bin']
34
 
      provider.validatecmd(File.expand_path("/bin/blah/foo"))
 
33
      provider.validatecmd("/bin/blah/foo")
35
34
    end
36
35
  end
37
36
 
64
63
        provider.resource[:path] = [File.dirname(command)]
65
64
        filename = File.basename(command)
66
65
 
67
 
        Puppet::Util::Execution.expects(:execute).with { |cmdline, arguments| (cmdline == filename) && (arguments.is_a? Hash) }.returns(Puppet::Util::Execution::ProcessOutput.new('', 0))
 
66
        Puppet::Util::Execution.expects(:execute).with(filename, instance_of(Hash)).returns(Puppet::Util::Execution::ProcessOutput.new('', 0))
68
67
 
69
68
        provider.run(filename)
70
69
      end
91
90
      expect { provider.run("cd ..") }.to raise_error(ArgumentError, "Could not find command 'cd'")
92
91
    end
93
92
 
 
93
    it "does not override the user when it is already the requested user" do
 
94
      Etc.stubs(:getpwuid).returns(Struct::Passwd.new('testing'))
 
95
      provider.resource[:user] = 'testing'
 
96
      command = make_exe
 
97
 
 
98
      Puppet::Util::Execution.expects(:execute).with(anything(), has_entry(:uid, nil)).returns(Puppet::Util::Execution::ProcessOutput.new('', 0))
 
99
 
 
100
      provider.run(command)
 
101
    end
 
102
 
94
103
    it "should execute the command if the command given includes arguments or subcommands" do
95
104
      provider.resource[:path] = ['/bogus/bin']
96
105
      command = make_exe
97
106
 
98
 
      Puppet::Util::Execution.expects(:execute).with { |cmdline, arguments| (cmdline == "#{command} bar --sillyarg=true --blah") && (arguments.is_a? Hash) }.returns(Puppet::Util::Execution::ProcessOutput.new('', 0))
 
107
      Puppet::Util::Execution.expects(:execute).with("#{command} bar --sillyarg=true --blah", instance_of(Hash)).returns(Puppet::Util::Execution::ProcessOutput.new('', 0))
 
108
 
99
109
      provider.run("#{command} bar --sillyarg=true --blah")
100
110
    end
101
111
 
102
112
    it "should fail if quoted command doesn't exist" do
103
113
      provider.resource[:path] = ['/bogus/bin']
104
 
      command = "#{File.expand_path('/foo')} bar --sillyarg=true --blah"
 
114
      command = "/foo bar --sillyarg=true --blah"
105
115
 
106
116
      expect { provider.run(%Q["#{command}"]) }.to raise_error(ArgumentError, "Could not find command '#{command}'")
107
117
    end
110
120
      provider.resource[:environment] = ['WHATEVER=/something/else', 'WHATEVER=/foo']
111
121
      command = make_exe
112
122
 
113
 
      Puppet::Util::Execution.expects(:execute).with { |cmdline, arguments| (cmdline == command) && (arguments.is_a? Hash) }.returns(Puppet::Util::Execution::ProcessOutput.new('', 0))
 
123
      Puppet::Util::Execution.expects(:execute).with(command, instance_of(Hash)).returns(Puppet::Util::Execution::ProcessOutput.new('', 0))
 
124
 
114
125
      provider.run(command)
 
126
 
115
127
      @logs.map {|l| "#{l.level}: #{l.message}" }.should == ["warning: Overriding environment setting 'WHATEVER' with '/foo'"]
116
128
    end
117
129
 
121
133
      provider.run(provider.resource[:command])
122
134
    end
123
135
 
124
 
    describe "posix locale settings", :unless => Puppet.features.microsoft_windows? do
 
136
    describe "posix locale settings" do
125
137
      # a sentinel value that we can use to emulate what locale environment variables might be set to on an international
126
138
      # system.
127
139
      lang_sentinel_value = "en_US.UTF-8"
160
172
      end
161
173
    end
162
174
 
163
 
    describe "posix user-related environment vars", :unless => Puppet.features.microsoft_windows? do
 
175
    describe "posix user-related environment vars" do
164
176
      # a temporary hash that contains sentinel values for each of the user-related environment variables that we
165
177
      # are expected to unset during an "exec"
166
178
      user_sentinel_env = {}
202
214
          output.strip.should == sentinel_value
203
215
        end
204
216
      end
205
 
 
206
 
 
207
217
    end
208
 
 
209
 
 
210
218
  end
211
219
end