Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/puppet/provider/package/pkgdmg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# in /var/db/.puppet_pkgdmg_installed_<name>

require 'puppet/provider/package'
require 'puppet/util/plist' if Puppet.features.cfpropertylist?
require 'puppet/util/plist'
require 'puppet/util/http_proxy'

Puppet::Type.type(:package).provide :pkgdmg, :parent => Puppet::Provider::Package do
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/service/launchd.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'puppet/util/plist' if Puppet.features.cfpropertylist?
require 'puppet/util/plist'
Puppet::Type.type(:service).provide :launchd, :parent => :base do
desc <<-'EOT'
This provider manages jobs with `launchd`, which is the default service
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/util/plist.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'cfpropertylist'
require 'cfpropertylist' if Puppet.features.cfpropertylist?
require 'puppet/util/execution'

module Puppet::Util::Plist
Expand Down
11 changes: 10 additions & 1 deletion spec/unit/module_tool/applications/installer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
require 'puppet_spec/module_tool/stub_source'
require 'semver'

require 'tmpdir'

describe Puppet::ModuleTool::Applications::Installer do
include PuppetSpec::ModuleTool::SharedFunctions
include PuppetSpec::Files
Expand Down Expand Up @@ -32,6 +34,13 @@
installer.stubs(:module_repository).returns(remote_source)
end

if Puppet.features.microsoft_windows?
before :each do
Puppet.settings.stubs(:[])
Puppet.settings.stubs(:[]).with(:module_working_dir).returns(Dir.mktmpdir('installertmp'))
end
end

def installer(modname, target_dir, options)
Puppet::ModuleTool.set_option_defaults(options)
Puppet::ModuleTool::Applications::Installer.new(modname, target_dir, options)
Expand Down Expand Up @@ -358,6 +367,6 @@ def options
end
end
end

end

end
3 changes: 2 additions & 1 deletion spec/unit/module_tool/applications/unpacker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
let(:working_dir) { tmpdir("working_dir") }

before :each do
Puppet.settings[:module_working_dir] = working_dir
Puppet.settings.stubs(:[])
Puppet.settings.stubs(:[]).with(:module_working_dir).returns(working_dir)
end

it "should attempt to untar file to temporary location" do
Expand Down
8 changes: 8 additions & 0 deletions spec/unit/module_tool/applications/upgrader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'puppet_spec/module_tool/shared_functions'
require 'puppet_spec/module_tool/stub_source'
require 'semver'
require 'tmpdir'

describe Puppet::ModuleTool::Applications::Upgrader do
include PuppetSpec::ModuleTool::SharedFunctions
Expand Down Expand Up @@ -31,6 +32,13 @@
installer.stubs(:module_repository).returns(remote_source)
end

if Puppet.features.microsoft_windows?
before :each do
Puppet.settings.stubs(:[])
Puppet.settings.stubs(:[]).with(:module_working_dir).returns(Dir.mktmpdir('upgradertmp'))
end
end

def upgrader(name, options = {})
Puppet::ModuleTool.set_option_defaults(options)
Puppet::ModuleTool::Applications::Upgrader.new(name, options)
Expand Down
8 changes: 4 additions & 4 deletions spec/unit/provider/package/pacman_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -438,29 +438,29 @@

it 'should raise an error on non-zero pacman exit without a filter' do
executor.expects(:open).with('| /usr/bin/pacman -Sgg 2>&1').returns 'error!'
$CHILD_STATUS.stubs(:exitstatus).returns 1
Puppet::Util::Execution.expects(:exitstatus).returns 1
expect { described_class.get_installed_groups(installed_packages) }.to raise_error(Puppet::ExecutionFailure, 'error!')
end

it 'should return empty groups on non-zero pacman exit with a filter' do
executor.expects(:open).with('| /usr/bin/pacman -Sgg git 2>&1').returns ''
$CHILD_STATUS.stubs(:exitstatus).returns 1
Puppet::Util::Execution.expects(:exitstatus).returns 1
expect(described_class.get_installed_groups(installed_packages, 'git')).to eq({})
end

it 'should return empty groups on empty pacman output' do
pipe = stub()
pipe.expects(:each_line)
executor.expects(:open).with('| /usr/bin/pacman -Sgg 2>&1').yields(pipe).returns ''
$CHILD_STATUS.stubs(:exitstatus).returns 0
Puppet::Util::Execution.expects(:exitstatus).returns 0
expect(described_class.get_installed_groups(installed_packages)).to eq({})
end

it 'should return groups on non-empty pacman output' do
pipe = stub()
pipe.expects(:each_line).multiple_yields(*groups)
executor.expects(:open).with('| /usr/bin/pacman -Sgg 2>&1').yields(pipe).returns ''
$CHILD_STATUS.stubs(:exitstatus).returns 0
Puppet::Util::Execution.expects(:exitstatus).returns 0
expect(described_class.get_installed_groups(installed_packages)).to eq({'foo' => 'package1 1.0, package2 2.0'})
end
end
Expand Down
6 changes: 6 additions & 0 deletions spec/unit/provider/package/pkg_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
let (:resource) { Puppet::Resource.new(:package, 'dummy', :parameters => {:name => 'dummy', :ensure => :latest}) }
let (:provider) { described_class.new(resource) }

if Puppet.features.microsoft_windows?
# Get a pid for $CHILD_STATUS to latch on to
command = "cmd.exe /c \"exit 0\""
Puppet::Util::Execution.execute(command, {:failonfail => false})
end

before :each do
described_class.stubs(:command).with(:pkg).returns('/bin/pkg')
end
Expand Down
3 changes: 0 additions & 3 deletions spec/unit/provider/package/pkgdmg_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#! /usr/bin/env ruby
require 'spec_helper'

module Puppet::Util::Plist
end

describe Puppet::Type.type(:package).provider(:pkgdmg) do
let(:resource) { Puppet::Type.type(:package).new(:name => 'foo', :provider => :pkgdmg) }
let(:provider) { described_class.new(resource) }
Expand Down
6 changes: 6 additions & 0 deletions spec/unit/provider/service/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@

subject { provider }

if Puppet.features.microsoft_windows?
# Get a pid for $CHILD_STATUS to latch on to
command = "cmd.exe /c \"exit 0\""
Puppet::Util::Execution.execute(command, {:failonfail => false})
end

context "basic operations" do
subject do
type.new(
Expand Down
6 changes: 6 additions & 0 deletions spec/unit/provider/service/debian_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@

describe provider_class do

if Puppet.features.microsoft_windows?
# Get a pid for $CHILD_STATUS to latch on to
command = "cmd.exe /c \"exit 0\""
Puppet::Util::Execution.execute(command, {:failonfail => false})
end

before(:each) do
# Create a mock resource
@resource = stub 'resource'
Expand Down
6 changes: 6 additions & 0 deletions spec/unit/provider/service/gentoo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

describe Puppet::Type.type(:service).provider(:gentoo) do

if Puppet.features.microsoft_windows?
# Get a pid for $CHILD_STATUS to latch on to
command = "cmd.exe /c \"exit 0\""
Puppet::Util::Execution.execute(command, {:failonfail => false})
end

before :each do
Puppet::Type.type(:service).stubs(:defaultprovider).returns described_class
FileTest.stubs(:file?).with('/sbin/rc-update').returns true
Expand Down
7 changes: 7 additions & 0 deletions spec/unit/provider/service/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
require 'spec_helper'

describe Puppet::Type.type(:service).provider(:init) do

if Puppet.features.microsoft_windows?
# Get a pid for $CHILD_STATUS to latch on to
command = "cmd.exe /c \"exit 0\""
Puppet::Util::Execution.execute(command, {:failonfail => false})
end

before do
Puppet::Type.type(:service).defaultprovider = described_class
end
Expand Down
6 changes: 6 additions & 0 deletions spec/unit/provider/service/launchd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
let (:launchd_overrides_10_) { '/var/db/com.apple.xpc.launchd/disabled.plist' }
subject { resource.provider }

if Puppet.features.microsoft_windows?
# Get a pid for $CHILD_STATUS to latch on to
command = "cmd.exe /c \"exit 0\""
Puppet::Util::Execution.execute(command, {:failonfail => false})
end

describe "the type interface" do
%w{ start stop enabled? enable disable status}.each do |method|
it { is_expected.to respond_to method.to_sym }
Expand Down
6 changes: 6 additions & 0 deletions spec/unit/provider/service/openrc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

describe Puppet::Type.type(:service).provider(:openrc) do

if Puppet.features.microsoft_windows?
# Get a pid for $CHILD_STATUS to latch on to
command = "cmd.exe /c \"exit 0\""
Puppet::Util::Execution.execute(command, {:failonfail => false})
end

before :each do
Puppet::Type.type(:service).stubs(:defaultprovider).returns described_class
['/sbin/rc-service', '/bin/rc-status', '/sbin/rc-update'].each do |command|
Expand Down
6 changes: 6 additions & 0 deletions spec/unit/provider/service/src_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@

describe provider_class do

if Puppet.features.microsoft_windows?
# Get a pid for $CHILD_STATUS to latch on to
command = "cmd.exe /c \"exit 0\""
Puppet::Util::Execution.execute(command, {:failonfail => false})
end

before :each do
@resource = stub 'resource'
@resource.stubs(:[]).returns(nil)
Expand Down
7 changes: 7 additions & 0 deletions spec/unit/provider/service/systemd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
require 'spec_helper'

describe Puppet::Type.type(:service).provider(:systemd) do

if Puppet.features.microsoft_windows?
# Get a pid for $CHILD_STATUS to latch on to
command = "cmd.exe /c \"exit 0\""
Puppet::Util::Execution.execute(command, {:failonfail => false})
end

before :each do
Puppet::Type.type(:service).stubs(:defaultprovider).returns described_class
described_class.stubs(:which).with('systemctl').returns '/bin/systemctl'
Expand Down
6 changes: 6 additions & 0 deletions spec/unit/provider/service/upstart_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
let(:start_on_default_runlevels) { "\nstart on runlevel [2,3,4,5]" }
let(:provider_class) { Puppet::Type.type(:service).provider(:upstart) }

if Puppet.features.microsoft_windows?
# Get a pid for $CHILD_STATUS to latch on to
command = "cmd.exe /c \"exit 0\""
Puppet::Util::Execution.execute(command, {:failonfail => false})
end

def given_contents_of(file, content)
File.open(file, 'w') do |file|
file.write(content)
Expand Down
13 changes: 13 additions & 0 deletions spec/unit/settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1375,8 +1375,21 @@ def assert_accessing_setting_is_deprecated(settings, setting)
end

describe "when adding users and groups to the catalog" do
before :all do
# when this spec is run in isolation to build a settings catalog
# it will not be able to autorequire and load types for the first time
# on Windows with microsoft_windows? stubbed to false, because
# Puppet::Util.path_to_uri is called to generate a URI to load code
# and it manipulates the path based on OS
# so instead we forcefully "prime" the cached types
Puppet::Type.type(:user).new(:name => 'foo')
Puppet::Type.type(:group).new(:name => 'bar')
Puppet::Type.type(:file).new(:name => Dir.pwd) # appropriate for OS
end

before do
Puppet.features.stubs(:root?).returns true
# stubbed to false, as Windows catalogs don't add users / groups
Puppet.features.stubs(:microsoft_windows?).returns false

@settings.define_settings :foo,
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/util/execution_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def stub_process_wait(exitstatus)

Puppet::Util::Execution.stubs(:execute_windows).returns(proc_info_stub)
stub_process_wait(real_exit_status)
$CHILD_STATUS.stubs(:exitstatus).returns(real_exit_status % 256) # The exitstatus is changed to be mod 256 so that ruby can fit it into 8 bits.
Puppet::Util::Execution.stubs(:exitstatus).returns(real_exit_status % 256) # The exitstatus is changed to be mod 256 so that ruby can fit it into 8 bits.

expect(Puppet::Util::Execution.execute('test command', :failonfail => false).exitstatus).to eq(real_exit_status)
end
Expand Down
4 changes: 1 addition & 3 deletions spec/unit/util/plist_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
require 'spec_helper'
require 'puppet/util/plist' if Puppet.features.cfpropertylist?
require 'puppet/util/plist'
require 'puppet_spec/files'

module Puppet::Util::Plist; end

describe Puppet::Util::Plist, :if => Puppet.features.cfpropertylist? do
include PuppetSpec::Files

Expand Down