diff options
author | Stig Sandbeck Mathisen <ssm@debian.org> | 2014-09-07 10:14:36 +0200 |
---|---|---|
committer | Stig Sandbeck Mathisen <ssm@debian.org> | 2014-09-07 10:14:36 +0200 |
commit | d4b83be375ac1dead058e091191ee7c7b7c24c8a (patch) | |
tree | dc825687392ae3068de5b764be60c53122d9e02a /spec/unit/provider/exec | |
parent | 229cbb976fe0f70f5f30548b83517b415840f9bb (diff) | |
parent | 1681684857c6e39d60d87b0b3520d8783977ceff (diff) | |
download | puppet-upstream/3.7.0.tar.gz |
Imported Upstream version 3.7.0upstream/3.7.0
Diffstat (limited to 'spec/unit/provider/exec')
-rwxr-xr-x | spec/unit/provider/exec/posix_spec.rb | 36 | ||||
-rwxr-xr-x | spec/unit/provider/exec/shell_spec.rb | 4 |
2 files changed, 24 insertions, 16 deletions
diff --git a/spec/unit/provider/exec/posix_spec.rb b/spec/unit/provider/exec/posix_spec.rb index 7c4982fcc..02c338b69 100755 --- a/spec/unit/provider/exec/posix_spec.rb +++ b/spec/unit/provider/exec/posix_spec.rb @@ -1,19 +1,18 @@ #! /usr/bin/env ruby require 'spec_helper' -describe Puppet::Type.type(:exec).provider(:posix) do +describe Puppet::Type.type(:exec).provider(:posix), :if => Puppet.features.posix? do include PuppetSpec::Files def make_exe cmdpath = tmpdir('cmdpath') exepath = tmpfile('my_command', cmdpath) - exepath = exepath + ".exe" if Puppet.features.microsoft_windows? FileUtils.touch(exepath) File.chmod(0755, exepath) exepath end - let(:resource) { Puppet::Type.type(:exec).new(:title => File.expand_path('/foo'), :provider => :posix) } + let(:resource) { Puppet::Type.type(:exec).new(:title => '/foo', :provider => :posix) } let(:provider) { described_class.new(resource) } describe "#validatecmd" do @@ -31,7 +30,7 @@ describe Puppet::Type.type(:exec).provider(:posix) do it "should pass if command is fully qualifed" do provider.resource[:path] = ['/bogus/bin'] - provider.validatecmd(File.expand_path("/bin/blah/foo")) + provider.validatecmd("/bin/blah/foo") end end @@ -64,7 +63,7 @@ describe Puppet::Type.type(:exec).provider(:posix) do provider.resource[:path] = [File.dirname(command)] filename = File.basename(command) - Puppet::Util::Execution.expects(:execute).with { |cmdline, arguments| (cmdline == filename) && (arguments.is_a? Hash) }.returns(Puppet::Util::Execution::ProcessOutput.new('', 0)) + Puppet::Util::Execution.expects(:execute).with(filename, instance_of(Hash)).returns(Puppet::Util::Execution::ProcessOutput.new('', 0)) provider.run(filename) end @@ -91,17 +90,28 @@ describe Puppet::Type.type(:exec).provider(:posix) do expect { provider.run("cd ..") }.to raise_error(ArgumentError, "Could not find command 'cd'") end + it "does not override the user when it is already the requested user" do + Etc.stubs(:getpwuid).returns(Struct::Passwd.new('testing')) + provider.resource[:user] = 'testing' + command = make_exe + + Puppet::Util::Execution.expects(:execute).with(anything(), has_entry(:uid, nil)).returns(Puppet::Util::Execution::ProcessOutput.new('', 0)) + + provider.run(command) + end + it "should execute the command if the command given includes arguments or subcommands" do provider.resource[:path] = ['/bogus/bin'] command = make_exe - 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)) + Puppet::Util::Execution.expects(:execute).with("#{command} bar --sillyarg=true --blah", instance_of(Hash)).returns(Puppet::Util::Execution::ProcessOutput.new('', 0)) + provider.run("#{command} bar --sillyarg=true --blah") end it "should fail if quoted command doesn't exist" do provider.resource[:path] = ['/bogus/bin'] - command = "#{File.expand_path('/foo')} bar --sillyarg=true --blah" + command = "/foo bar --sillyarg=true --blah" expect { provider.run(%Q["#{command}"]) }.to raise_error(ArgumentError, "Could not find command '#{command}'") end @@ -110,8 +120,10 @@ describe Puppet::Type.type(:exec).provider(:posix) do provider.resource[:environment] = ['WHATEVER=/something/else', 'WHATEVER=/foo'] command = make_exe - Puppet::Util::Execution.expects(:execute).with { |cmdline, arguments| (cmdline == command) && (arguments.is_a? Hash) }.returns(Puppet::Util::Execution::ProcessOutput.new('', 0)) + Puppet::Util::Execution.expects(:execute).with(command, instance_of(Hash)).returns(Puppet::Util::Execution::ProcessOutput.new('', 0)) + provider.run(command) + @logs.map {|l| "#{l.level}: #{l.message}" }.should == ["warning: Overriding environment setting 'WHATEVER' with '/foo'"] end @@ -121,7 +133,7 @@ describe Puppet::Type.type(:exec).provider(:posix) do provider.run(provider.resource[:command]) end - describe "posix locale settings", :unless => Puppet.features.microsoft_windows? do + describe "posix locale settings" do # a sentinel value that we can use to emulate what locale environment variables might be set to on an international # system. lang_sentinel_value = "en_US.UTF-8" @@ -160,7 +172,7 @@ describe Puppet::Type.type(:exec).provider(:posix) do end end - describe "posix user-related environment vars", :unless => Puppet.features.microsoft_windows? do + describe "posix user-related environment vars" do # a temporary hash that contains sentinel values for each of the user-related environment variables that we # are expected to unset during an "exec" user_sentinel_env = {} @@ -202,10 +214,6 @@ describe Puppet::Type.type(:exec).provider(:posix) do output.strip.should == sentinel_value end end - - end - - end end diff --git a/spec/unit/provider/exec/shell_spec.rb b/spec/unit/provider/exec/shell_spec.rb index 0f0faa594..932f46b6a 100755 --- a/spec/unit/provider/exec/shell_spec.rb +++ b/spec/unit/provider/exec/shell_spec.rb @@ -2,8 +2,8 @@ require 'spec_helper' describe Puppet::Type.type(:exec).provider(:shell), :unless => Puppet.features.microsoft_windows? do - let :resource do Puppet::Resource.new(:exec, 'foo') end - let :provider do described_class.new(resource) end + let(:resource) { Puppet::Type.type(:exec).new(:title => 'foo', :provider => 'shell') } + let(:provider) { described_class.new(resource) } describe "#run" do it "should be able to run builtin shell commands" do |