Skip to content

Commit ad7607e

Browse files
authored
Merge pull request #5114 from Iristyle/pr/5041
(PUP-6398) Adjust specs / code organization to support parallel specs on Windows
2 parents 6da96e1 + d1afcc1 commit ad7607e

File tree

21 files changed

+104
-16
lines changed

21 files changed

+104
-16
lines changed

lib/puppet/provider/package/pkgdmg.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# in /var/db/.puppet_pkgdmg_installed_<name>
1010

1111
require 'puppet/provider/package'
12-
require 'puppet/util/plist' if Puppet.features.cfpropertylist?
12+
require 'puppet/util/plist'
1313
require 'puppet/util/http_proxy'
1414

1515
Puppet::Type.type(:package).provide :pkgdmg, :parent => Puppet::Provider::Package do

lib/puppet/provider/service/launchd.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'puppet/util/plist' if Puppet.features.cfpropertylist?
1+
require 'puppet/util/plist'
22
Puppet::Type.type(:service).provide :launchd, :parent => :base do
33
desc <<-'EOT'
44
This provider manages jobs with `launchd`, which is the default service

lib/puppet/util/plist.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'cfpropertylist'
1+
require 'cfpropertylist' if Puppet.features.cfpropertylist?
22
require 'puppet/util/execution'
33

44
module Puppet::Util::Plist

spec/unit/module_tool/applications/installer_spec.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
require 'puppet_spec/module_tool/stub_source'
55
require 'semver'
66

7+
require 'tmpdir'
8+
79
describe Puppet::ModuleTool::Applications::Installer do
810
include PuppetSpec::ModuleTool::SharedFunctions
911
include PuppetSpec::Files
@@ -32,6 +34,13 @@
3234
installer.stubs(:module_repository).returns(remote_source)
3335
end
3436

37+
if Puppet.features.microsoft_windows?
38+
before :each do
39+
Puppet.settings.stubs(:[])
40+
Puppet.settings.stubs(:[]).with(:module_working_dir).returns(Dir.mktmpdir('installertmp'))
41+
end
42+
end
43+
3544
def installer(modname, target_dir, options)
3645
Puppet::ModuleTool.set_option_defaults(options)
3746
Puppet::ModuleTool::Applications::Installer.new(modname, target_dir, options)
@@ -358,6 +367,6 @@ def options
358367
end
359368
end
360369
end
361-
362370
end
371+
363372
end

spec/unit/module_tool/applications/unpacker_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
let(:working_dir) { tmpdir("working_dir") }
1515

1616
before :each do
17-
Puppet.settings[:module_working_dir] = working_dir
17+
Puppet.settings.stubs(:[])
18+
Puppet.settings.stubs(:[]).with(:module_working_dir).returns(working_dir)
1819
end
1920

2021
it "should attempt to untar file to temporary location" do

spec/unit/module_tool/applications/upgrader_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require 'puppet_spec/module_tool/shared_functions'
44
require 'puppet_spec/module_tool/stub_source'
55
require 'semver'
6+
require 'tmpdir'
67

78
describe Puppet::ModuleTool::Applications::Upgrader do
89
include PuppetSpec::ModuleTool::SharedFunctions
@@ -31,6 +32,13 @@
3132
installer.stubs(:module_repository).returns(remote_source)
3233
end
3334

35+
if Puppet.features.microsoft_windows?
36+
before :each do
37+
Puppet.settings.stubs(:[])
38+
Puppet.settings.stubs(:[]).with(:module_working_dir).returns(Dir.mktmpdir('upgradertmp'))
39+
end
40+
end
41+
3442
def upgrader(name, options = {})
3543
Puppet::ModuleTool.set_option_defaults(options)
3644
Puppet::ModuleTool::Applications::Upgrader.new(name, options)

spec/unit/provider/package/pacman_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -438,29 +438,29 @@
438438

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

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

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

459459
it 'should return groups on non-empty pacman output' do
460460
pipe = stub()
461461
pipe.expects(:each_line).multiple_yields(*groups)
462462
executor.expects(:open).with('| /usr/bin/pacman -Sgg 2>&1').yields(pipe).returns ''
463-
$CHILD_STATUS.stubs(:exitstatus).returns 0
463+
Puppet::Util::Execution.expects(:exitstatus).returns 0
464464
expect(described_class.get_installed_groups(installed_packages)).to eq({'foo' => 'package1 1.0, package2 2.0'})
465465
end
466466
end

spec/unit/provider/package/pkg_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
let (:resource) { Puppet::Resource.new(:package, 'dummy', :parameters => {:name => 'dummy', :ensure => :latest}) }
66
let (:provider) { described_class.new(resource) }
77

8+
if Puppet.features.microsoft_windows?
9+
# Get a pid for $CHILD_STATUS to latch on to
10+
command = "cmd.exe /c \"exit 0\""
11+
Puppet::Util::Execution.execute(command, {:failonfail => false})
12+
end
13+
814
before :each do
915
described_class.stubs(:command).with(:pkg).returns('/bin/pkg')
1016
end

spec/unit/provider/package/pkgdmg_spec.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
#! /usr/bin/env ruby
22
require 'spec_helper'
33

4-
module Puppet::Util::Plist
5-
end
6-
74
describe Puppet::Type.type(:package).provider(:pkgdmg) do
85
let(:resource) { Puppet::Type.type(:package).new(:name => 'foo', :provider => :pkgdmg) }
96
let(:provider) { described_class.new(resource) }

spec/unit/provider/service/base_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717

1818
subject { provider }
1919

20+
if Puppet.features.microsoft_windows?
21+
# Get a pid for $CHILD_STATUS to latch on to
22+
command = "cmd.exe /c \"exit 0\""
23+
Puppet::Util::Execution.execute(command, {:failonfail => false})
24+
end
25+
2026
context "basic operations" do
2127
subject do
2228
type.new(

0 commit comments

Comments
 (0)