Skip to content

Commit d41dfe0

Browse files
committed
Make unit testing mode controlled by env var
This feels more user-defined and unlikely to be affected by future Bolt product changes, compared to relying on whether or not a tty is present.
1 parent ec2e9d2 commit d41dfe0

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

Diff for: spec/spec_helper_local.rb

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
require 'puppet'
44

5+
# This environment variable can be read by Ruby Bolt tasks to prevent unwanted
6+
# auto-execution, enabling easy unit testing.
7+
ENV["RSPEC_UNIT_TEST_MODE"] ||= "TRUE"
8+
59
if Gem::Version.new(Puppet.version) >= Gem::Version.new('6.0.0')
610
begin
711
require 'bolt_spec/plans'

Diff for: tasks/puppet_infra_upgrade.rb

+4-3
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,10 @@ def wait_until_connected(nodes:, token_file:, timeout: 120)
9191
end
9292
end
9393

94-
# Run the task if we got piped input. In order to enable unit testing, do not
95-
# run the task if input is a tty.
96-
unless STDIN.tty?
94+
# Run the task unless an environment flag has been set, signaling not to. The
95+
# environment flag is used to disable auto-execution and enable Ruby unit
96+
# testing of this task.
97+
unless ENV['RSPEC_UNIT_TEST_MODE']
9798
upgrade = PEAdm::Task::PuppetInfraUpgrade.new(JSON.parse(STDIN.read))
9899
upgrade.execute!
99100
end

0 commit comments

Comments
 (0)