Skip to content

Commit bbb35f7

Browse files
authored
Merge pull request #8567 from joshcooper/order_dependent_11022
(PUP-11022) Resolve order dependent test failures
2 parents 8482397 + a6f2b56 commit bbb35f7

File tree

6 files changed

+49
-35
lines changed

6 files changed

+49
-35
lines changed

spec/unit/gettext/config_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@
2727
Puppet::GettextConfig.delete_all_text_domains
2828
end
2929

30+
# These tests assume gettext is enabled, but it will be disabled when the
31+
# first time the `Puppet[:disable_i18n]` setting is resolved
32+
around(:each) do |example|
33+
disabled = Puppet::GettextConfig.instance_variable_get(:@gettext_disabled)
34+
Puppet::GettextConfig.instance_variable_set(:@gettext_disabled, false)
35+
begin
36+
example.run
37+
ensure
38+
Puppet::GettextConfig.instance_variable_set(:@gettext_disabled, disabled)
39+
end
40+
end
41+
3042
describe 'setting and getting the locale' do
3143
it 'should return "en" when gettext is unavailable' do
3244
allow(Puppet::GettextConfig).to receive(:gettext_loaded?).and_return(false)

spec/unit/provider/service/init_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
allow(provider_class).to receive(:defpath).and_return('tmp')
8484

8585
@services = ['one', 'two', 'three', 'four', 'umountfs']
86+
allow(Dir).to receive(:entries).and_call_original
8687
allow(Dir).to receive(:entries).with('tmp').and_return(@services)
8788
expect(FileTest).to receive(:directory?).with('tmp').and_return(true)
8889
allow(FileTest).to receive(:executable?).and_return(true)

spec/unit/provider/service/openwrt_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
allow(File).to receive(:directory?).with('/etc/init.d').and_return(true)
3333

3434
allow(Puppet::FileSystem).to receive(:exist?).with('/etc/init.d/myservice').and_return(true)
35+
allow(FileTest).to receive(:file?).and_call_original
3536
allow(FileTest).to receive(:file?).with('/etc/init.d/myservice').and_return(true)
3637
allow(FileTest).to receive(:executable?).with('/etc/init.d/myservice').and_return(true)
3738
end
@@ -47,7 +48,8 @@
4748
let(:services) {['dnsmasq', 'dropbear', 'firewall', 'led', 'puppet', 'uhttpd' ]}
4849

4950
before :each do
50-
allow(Dir).to receive(:entries).and_return(services)
51+
allow(Dir).to receive(:entries).and_call_original
52+
allow(Dir).to receive(:entries).with('/etc/init.d').and_return(services)
5153
allow(FileTest).to receive(:directory?).and_return(true)
5254
allow(FileTest).to receive(:executable?).and_return(true)
5355
end

spec/unit/transaction/additional_resource_generator_spec.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ def generate()
9393
end
9494
end
9595

96-
97-
9896
after(:each) do
9997
Puppet::Type.rmtype(:gen_empty)
10098
Puppet::Type.rmtype(:eval_after)

spec/unit/transaction_spec.rb

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@
55
require 'puppet/transaction'
66
require 'fileutils'
77

8-
Puppet::Type.newtype(:generator) do
9-
newparam(:name) { isnamevar }
10-
11-
def generate
12-
end
13-
end
14-
158
describe Puppet::Transaction do
169
include PuppetSpec::Files
1710
include PuppetSpec::Compiler
@@ -27,6 +20,19 @@ def transaction_with_resource(resource)
2720
transaction
2821
end
2922

23+
before(:all) do
24+
Puppet::Type.newtype(:transaction_generator) do
25+
newparam(:name) { isnamevar }
26+
27+
def generate
28+
end
29+
end
30+
end
31+
32+
after(:all) do
33+
Puppet::Type.rmtype(:transaction_generator)
34+
end
35+
3036
before do
3137
@basepath = make_absolute("/what/ever")
3238
@transaction = Puppet::Transaction.new(Puppet::Resource::Catalog.new, nil, Puppet::Graph::SequentialPrioritizer.new)
@@ -330,9 +336,9 @@ def transaction_with_resource(resource)
330336
describe "when generating resources before traversal" do
331337
let(:catalog) { Puppet::Resource::Catalog.new }
332338
let(:transaction) { Puppet::Transaction.new(catalog, nil, Puppet::Graph::SequentialPrioritizer.new) }
333-
let(:generator) { Puppet::Type.type(:generator).new :title => "generator" }
339+
let(:generator) { Puppet::Type.type(:transaction_generator).new :title => "generator" }
334340
let(:generated) do
335-
%w[a b c].map { |name| Puppet::Type.type(:generator).new(:name => name) }
341+
%w[a b c].map { |name| Puppet::Type.type(:transaction_generator).new(:name => name) }
336342
end
337343

338344
before :each do
@@ -673,7 +679,7 @@ def transaction_with_resource(resource)
673679
end
674680

675681
describe "and new resources are generated" do
676-
let(:generator) { Puppet::Type.type(:generator).new :title => "generator" }
682+
let(:generator) { Puppet::Type.type(:transaction_generator).new :title => "generator" }
677683
let(:generated) do
678684
%w[a b c].map { |name| Puppet::Type.type(:package).new :title => "foo", :name => name, :provider => :apt }
679685
end
@@ -787,16 +793,8 @@ def post_resource_eval
787793
end
788794

789795
it "should call Selinux.matchpathcon_fini in case Selinux is enabled ", :if => Puppet.features.posix? do
790-
unless defined?(Selinux)
791-
module Selinux
792-
def self.is_selinux_enabled
793-
true
794-
end
795-
796-
def self.matchpathcon_fini
797-
end
798-
end
799-
end
796+
selinux = double('selinux', is_selinux_enabled: true, matchpathcon_fini: nil)
797+
stub_const('Selinux', selinux)
800798

801799
resource = Puppet::Type.type(:file).new(:path => make_absolute("/tmp/foo"))
802800
transaction = transaction_with_resource(resource)

spec/unit/util/selinux_spec.rb

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,29 @@
33
require 'pathname'
44
require 'puppet/util/selinux'
55

6-
unless defined?(Selinux)
7-
module Selinux
8-
def self.is_selinux_enabled
9-
false
10-
end
11-
end
12-
end
13-
146
describe Puppet::Util::SELinux do
157
include Puppet::Util::SELinux
168

9+
let(:selinux) { double('selinux', is_selinux_enabled: false) }
10+
11+
before :each do
12+
stub_const('Selinux', selinux)
13+
end
14+
1715
describe "selinux_support?" do
18-
it "should return :true if this system has SELinux enabled" do
16+
it "should return true if this system has SELinux enabled" do
1917
expect(Selinux).to receive(:is_selinux_enabled).and_return(1)
20-
expect(selinux_support?).to be_truthy
18+
expect(selinux_support?).to eq(true)
2119
end
2220

23-
it "should return :false if this system lacks SELinux" do
21+
it "should return false if this system has SELinux disabled" do
2422
expect(Selinux).to receive(:is_selinux_enabled).and_return(0)
25-
expect(selinux_support?).to be_falsey
23+
expect(selinux_support?).to eq(false)
24+
end
25+
26+
it "should return false if this system lacks SELinux" do
27+
hide_const('Selinux')
28+
expect(selinux_support?).to eq(false)
2629
end
2730

2831
it "should return nil if /proc/mounts does not exist" do

0 commit comments

Comments
 (0)