summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@chef.io>2020-07-22 11:09:28 -0700
committerGitHub <noreply@github.com>2020-07-22 11:09:28 -0700
commitd7deaae8fcf84c19c825e43c487819cde24ed549 (patch)
treea32308bcdb81ca1979e9494aa6853424f3a4ad7f
parent4ba1cc0aa1b8fcb826fe09751115bdbe9568c5bf (diff)
parenteea6d8b2f711225ec266206cbedeff4c147aedb0 (diff)
downloadchef-d7deaae8fcf84c19c825e43c487819cde24ed549.tar.gz
Merge pull request #10137 from chef/lcg/extract-mixlib-shellout
-rw-r--r--chef-utils/lib/chef-utils/dsl/path_sanity.rb24
-rw-r--r--chef-utils/lib/chef-utils/dsl/service.rb5
-rw-r--r--chef-utils/lib/chef-utils/internal.rb42
-rw-r--r--lib/chef/dsl/platform_introspection.rb2
-rw-r--r--lib/chef/mixin/chef_utils_wiring.rb40
-rw-r--r--lib/chef/mixin/shell_out.rb192
-rw-r--r--lib/chef/mixin/which.rb5
-rw-r--r--lib/chef/platform/service_helpers.rb59
-rw-r--r--lib/chef/provider/service.rb4
-rw-r--r--lib/chef/resource/service.rb4
-rw-r--r--spec/unit/mixin/shell_out_spec.rb49
11 files changed, 163 insertions, 263 deletions
diff --git a/chef-utils/lib/chef-utils/dsl/path_sanity.rb b/chef-utils/lib/chef-utils/dsl/path_sanity.rb
index a3b71c14d9..921c666124 100644
--- a/chef-utils/lib/chef-utils/dsl/path_sanity.rb
+++ b/chef-utils/lib/chef-utils/dsl/path_sanity.rb
@@ -30,27 +30,27 @@ module ChefUtils
path_separator = ChefUtils.windows? ? ";" : ":"
# ensure the Ruby and Gem bindirs are included for omnibus chef installs
new_paths = env_path.split(path_separator)
- [ ChefUtils::DSL::PathSanity.ruby_bindir, ChefUtils::DSL::PathSanity.gem_bindir ].compact.each do |path|
+ [ __ruby_bindir, __gem_bindir ].compact.each do |path|
new_paths = [ path ] + new_paths unless new_paths.include?(path)
end
- ChefUtils::DSL::PathSanity.sane_paths.each do |path|
+ __sane_paths.each do |path|
new_paths << path unless new_paths.include?(path)
end
new_paths.join(path_separator).encode("utf-8", invalid: :replace, undef: :replace)
end
- class << self
- def sane_paths
- ChefUtils.windows? ? %w{} : %w{/usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin}
- end
+ private
- def ruby_bindir
- RbConfig::CONFIG["bindir"]
- end
+ def __sane_paths
+ ChefUtils.windows? ? %w{} : %w{/usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin}
+ end
- def gem_bindir
- Gem.bindir
- end
+ def __ruby_bindir
+ RbConfig::CONFIG["bindir"]
+ end
+
+ def __gem_bindir
+ Gem.bindir
end
extend self
diff --git a/chef-utils/lib/chef-utils/dsl/service.rb b/chef-utils/lib/chef-utils/dsl/service.rb
index faa5e96467..ed7805806c 100644
--- a/chef-utils/lib/chef-utils/dsl/service.rb
+++ b/chef-utils/lib/chef-utils/dsl/service.rb
@@ -25,6 +25,7 @@ module ChefUtils
module Service
include Internal
include TrainHelpers
+ include Introspection
# Returns if debian's old rc.d manager is installed (not necessarily the primary init system).
#
@@ -97,8 +98,8 @@ module ChefUtils
file_exist?("/etc/rc.d/#{script}")
when :systemd
file_exist?("/etc/init.d/#{script}") ||
- ChefUtils::DSL::Introspection.has_systemd_service_unit?(script) ||
- ChefUtils::DSL::Introspection.has_systemd_unit?(script)
+ has_systemd_service_unit?(script) ||
+ has_systemd_unit?(script)
else
raise ArgumentError, "type of service must be one of :initd, :upstart, :xinetd, :etc_rcd, or :systemd"
end
diff --git a/chef-utils/lib/chef-utils/internal.rb b/chef-utils/lib/chef-utils/internal.rb
index 731a0d1712..aa52005912 100644
--- a/chef-utils/lib/chef-utils/internal.rb
+++ b/chef-utils/lib/chef-utils/internal.rb
@@ -40,11 +40,18 @@ module ChefUtils
private
- # FIXME: include a `__config` method so we can wire up Chef::Config automatically or allow other consumers to
- # inject a config hash without having to take a direct dep on the chef-config gem
-
+ # This should be set to a Chef::Node instance or to some Hash/Mash-like configuration object with the same keys. It needs to
+ # expose keys like `:os`, `:platform`, `:platform_version` and `:platform_family` at least to be useful. It will automatically
+ # pick up a `node` method when mixed into an object that has that as a method (which is the encouraged "public" API to use
+ # for dependency injection rather than overriding the method in this case.
+ #
+ # @return [Hash] hash-like config object
+ #
# @api private
def __getnode(skip_global = false)
+ # Software developers should feel free to rely on the default wiring here to the node method by implementing the node method in their
+ # own class. For anything more complicated they should completely override the method (overriding the whole method is never wrong and
+ # is safer).
return node if respond_to?(:node) && node
return run_context&.node if respond_to?(:run_context) && run_context&.node
@@ -56,7 +63,10 @@ module ChefUtils
nil
end
+ # Just a helper to pull the ENV["PATH"] in a train-independent way
+ #
# @api private
+ #
def __env_path
if __transport_connection
__transport_connection.run_command("echo $PATH").stdout || ""
@@ -65,13 +75,39 @@ module ChefUtils
end
end
+ # This should be set to a Train::Plugins::Transport instance. You should wire this up to nil for not using a train transport connection.
+ #
+ # @return [Train::Plugins::Transport]
+ #
# @api private
+ #
def __transport_connection
+ # Software consumers MUST override this method with their own implementation. The default behavior here is subject to change.
return Chef.run_context.transport_connection if defined?(Chef) && Chef.respond_to?(:run_context) && Chef&.run_context&.transport_connection
nil
end
+ # This should be set to Chef::Config or to some Hash/Mash-like configuration object with the same keys. It must not be nil.
+ #
+ # @return [Hash] hash-like config object
+ #
+ # @api private
+ #
+ def __config
+ raise NotImplementedError
+ end
+
+ # This should be set to Chef::Log or something that duck-types like it. It must not be nil.
+ #
+ # @return [Chef::Log] logger-like logging object
+ #
+ # @api private
+ #
+ def __log
+ raise NotImplementedError
+ end
+
extend self
end
end
diff --git a/lib/chef/dsl/platform_introspection.rb b/lib/chef/dsl/platform_introspection.rb
index 794f807f23..8755644689 100644
--- a/lib/chef/dsl/platform_introspection.rb
+++ b/lib/chef/dsl/platform_introspection.rb
@@ -17,6 +17,7 @@
#
require "chef-utils" unless defined?(ChefUtils::CANARY)
+require "chef/mixin/chef_utils_wiring" unless defined?(Chef::Mixin::ChefUtilsWiring)
class Chef
module DSL
@@ -25,6 +26,7 @@ class Chef
# #value_for_platform.
module PlatformIntrospection
include ChefUtils
+ include Chef::Mixin::ChefUtilsWiring
# Implementation class for determining platform dependent values
class PlatformDependentValue
diff --git a/lib/chef/mixin/chef_utils_wiring.rb b/lib/chef/mixin/chef_utils_wiring.rb
new file mode 100644
index 0000000000..938520059c
--- /dev/null
+++ b/lib/chef/mixin/chef_utils_wiring.rb
@@ -0,0 +1,40 @@
+#--
+# Copyright:: Copyright (c) Chef Software Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require_relative "../log"
+require_relative "../config"
+require_relative "../chef_class"
+
+class Chef
+ module Mixin
+ # Common Dependency Injection wiring for ChefUtils-related modules
+ module ChefUtilsWiring
+ private
+
+ def __config
+ Chef::Config
+ end
+
+ def __log
+ Chef::Log
+ end
+
+ def __transport_connection
+ Chef.run_context&.transport_connection
+ end
+ end
+ end
+end
diff --git a/lib/chef/mixin/shell_out.rb b/lib/chef/mixin/shell_out.rb
index 62916b06de..c3eacc57f0 100644
--- a/lib/chef/mixin/shell_out.rb
+++ b/lib/chef/mixin/shell_out.rb
@@ -15,198 +15,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-require "mixlib/shellout" unless defined?(Mixlib::ShellOut::DEFAULT_READ_TIMEOUT)
-require "chef-utils/dsl/path_sanity" unless defined?(ChefUtils::DSL::PathSanity)
+require "mixlib/shellout/helper" unless defined?(Mixlib::ShellOut::Helper)
+require "chef/mixin/chef_utils_wiring" unless defined?(Chef::Mixin::ChefUtilsWiring)
class Chef
module Mixin
module ShellOut
-
- # PREFERRED APIS:
- #
- # all consumers should now call shell_out!/shell_out.
- #
- # the shell_out_compacted/shell_out_compacted! APIs are private but are intended for use
- # in rspec tests, and should ideally always be used to make code refactoring that do not
- # change behavior easier:
- #
- # allow(provider).to receive(:shell_out_compacted!).with("foo", "bar", "baz")
- # provider.shell_out!("foo", [ "bar", nil, "baz"])
- # provider.shell_out!(["foo", nil, "bar" ], ["baz"])
- #
- # note that shell_out_compacted also includes adding the magical timeout option to force
- # people to setup expectations on that value explicitly. it does not include the default_env
- # mangling in order to avoid users having to setup an expectation on anything other than
- # setting `default_env: false` and allow us to make tweak to the default_env without breaking
- # a thousand unit tests.
- #
-
- def shell_out(*args, **options)
- options = options.dup
- options = Chef::Mixin::ShellOut.maybe_add_timeout(self, options)
- if options.empty?
- shell_out_compacted(*Chef::Mixin::ShellOut.clean_array(*args))
- else
- shell_out_compacted(*Chef::Mixin::ShellOut.clean_array(*args), **options)
- end
- end
-
- def shell_out!(*args, **options)
- options = options.dup
- options = Chef::Mixin::ShellOut.maybe_add_timeout(self, options)
- if options.empty?
- shell_out_compacted!(*Chef::Mixin::ShellOut.clean_array(*args))
- else
- shell_out_compacted!(*Chef::Mixin::ShellOut.clean_array(*args), **options)
- end
- end
-
- # helper sugar for resources that support passing timeouts to shell_out
- #
- # module method to not pollute namespaces, but that means we need self injected as an arg
- # @api private
- def self.maybe_add_timeout(obj, options)
- options = options.dup
- # historically resources have not properly declared defaults on their timeouts, so a default default of 900s was enforced here
- default_val = 900
- return options if options.key?(:timeout)
-
- # FIXME: need to nuke descendent tracker out of Chef::Provider so we can just define that class here without requiring the
- # world, and then just use symbol lookup
- if obj.class.ancestors.map(&:name).include?("Chef::Provider") && obj.respond_to?(:new_resource) && obj.new_resource.respond_to?(:timeout) && !options.key?(:timeout)
- options[:timeout] = obj.new_resource.timeout ? obj.new_resource.timeout.to_f : default_val
- end
- options
- end
-
- # helper function to mangle options when `default_env` is true
- #
- # @api private
- def self.apply_default_env(options)
- options = options.dup
- default_env = options.delete(:default_env)
- default_env = true if default_env.nil?
- if default_env
- env_key = options.key?(:env) ? :env : :environment
- options[env_key] = {
- "LC_ALL" => Chef::Config[:internal_locale],
- "LANGUAGE" => Chef::Config[:internal_locale],
- "LANG" => Chef::Config[:internal_locale],
- env_path => ChefUtils::DSL::PathSanity.sanitized_path,
- }.update(options[env_key] || {})
- end
- options
- end
-
- private
-
- # this SHOULD be used for setting up expectations in rspec, see banner comment at top.
- #
- # the private constraint is meant to avoid code calling this directly, rspec expectations are fine.
- #
- def shell_out_compacted(*args, **options)
- options = Chef::Mixin::ShellOut.apply_default_env(options)
- if options.empty?
- Chef::Mixin::ShellOut.shell_out_command(*args)
- else
- Chef::Mixin::ShellOut.shell_out_command(*args, **options)
- end
- end
-
- # this SHOULD be used for setting up expectations in rspec, see banner comment at top.
- #
- # the private constraint is meant to avoid code calling this directly, rspec expectations are fine.
- #
- def shell_out_compacted!(*args, **options)
- options = Chef::Mixin::ShellOut.apply_default_env(options)
- cmd = if options.empty?
- Chef::Mixin::ShellOut.shell_out_command(*args)
- else
- Chef::Mixin::ShellOut.shell_out_command(*args, **options)
- end
- cmd.error!
- cmd
- end
-
- # Helper for subclasses to reject nil out of an array. It allows
- # using the array form of shell_out (which avoids the need to surround arguments with
- # quote marks to deal with shells).
- #
- # Usage:
- # shell_out!(*clean_array("useradd", universal_options, useradd_options, new_resource.username))
- #
- # universal_options and useradd_options can be nil, empty array, empty string, strings or arrays
- # and the result makes sense.
- #
- # keeping this separate from shell_out!() makes it a bit easier to write expectations against the
- # shell_out args and be able to omit nils and such in the tests (and to test that the nils are
- # being rejected correctly).
- #
- # @param args [String] variable number of string arguments
- # @return [Array] array of strings with nil and null string rejection
-
- def self.clean_array(*args)
- args.flatten.compact.map(&:to_s)
- end
-
- def self.transport_connection
- Chef.run_context.transport_connection
- end
-
- def self.shell_out_command(*args, **options)
- if Chef::Config.target_mode?
- FakeShellOut.new(args, options, transport_connection.run_command(args.join(" "))) # FIXME: train should accept run_command(*args)
- else
- cmd = if options.empty?
- Mixlib::ShellOut.new(*args)
- else
- Mixlib::ShellOut.new(*args, **options)
- end
- cmd.live_stream ||= io_for_live_stream
- cmd.run_command
- cmd
- end
- end
-
- def self.io_for_live_stream
- if STDOUT.tty? && !Chef::Config[:daemon] && Chef::Log.debug?
- STDOUT
- else
- nil
- end
- end
-
- def self.env_path
- if ChefUtils.windows?
- "Path"
- else
- "PATH"
- end
- end
-
- class FakeShellOut
- attr_reader :stdout, :stderr, :exitstatus, :status
-
- def initialize(args, options, result)
- @args = args
- @options = options
- @stdout = result.stdout
- @stderr = result.stderr
- @exitstatus = result.exit_status
- @status = OpenStruct.new(success?: ( exitstatus == 0 ))
- end
-
- def error?
- exitstatus != 0
- end
-
- def error!
- raise Mixlib::ShellOut::ShellCommandFailed, "Unexpected exit status of #{exitstatus} running #{@args}" if error?
- end
- end
+ include Mixlib::ShellOut::Helper
+ include Chef::Mixin::ChefUtilsWiring
end
end
end
-
-# Break circular dep
-require_relative "../config"
diff --git a/lib/chef/mixin/which.rb b/lib/chef/mixin/which.rb
index 1c40ffd70b..01357d76a5 100644
--- a/lib/chef/mixin/which.rb
+++ b/lib/chef/mixin/which.rb
@@ -17,11 +17,14 @@
require "chef-utils/dsl/which" unless defined?(ChefUtils::DSL::Which)
require "chef-utils/dsl/path_sanity" unless defined?(ChefUtils::DSL::PathSanity)
+require "chef/mixin/chef_utils_wiring" unless defined?(Chef::Mixin::ChefUtilsWiring)
class Chef
module Mixin
module Which
include ChefUtils::DSL::Which
+ include ChefUtils::DSL::PathSanity
+ include ChefUtilsWiring
private
@@ -29,7 +32,7 @@ class Chef
#
# @api private
def __extra_path
- ChefUtils::DSL::PathSanity.sane_paths
+ __sane_paths
end
end
end
diff --git a/lib/chef/platform/service_helpers.rb b/lib/chef/platform/service_helpers.rb
index ae1d2bd44b..627fd8d694 100644
--- a/lib/chef/platform/service_helpers.rb
+++ b/lib/chef/platform/service_helpers.rb
@@ -17,38 +17,41 @@
#
require_relative "../chef_class"
-require "chef-utils" if defined?(ChefUtils::CANARY)
+require "chef-utils" unless defined?(ChefUtils::CANARY)
+require "chef/mixin/chef_utils_wiring" unless defined?(Chef::Mixin::ChefUtilsWiring)
class Chef
class Platform
- # @deprecated, use ChefUtils::DSL::Service instead (via the ChefUtils Universal DSL)
- class ServiceHelpers
- class << self
- def service_resource_providers
- providers = []
-
- providers << :debian if ChefUtils::DSL::Service.debianrcd?
- providers << :invokercd if ChefUtils::DSL::Service.invokercd?
- providers << :upstart if ChefUtils::DSL::Service.upstart?
- providers << :insserv if ChefUtils::DSL::Service.insserv?
- providers << :systemd if ChefUtils.systemd?
- providers << :redhat if ChefUtils::DSL::Service.redhatrcd?
-
- providers
- end
-
- def config_for_service(service_name)
- configs = []
-
- configs << :initd if ChefUtils::DSL::Service.service_script_exist?(:initd, service_name)
- configs << :upstart if ChefUtils::DSL::Service.service_script_exist?(:upstart, service_name)
- configs << :xinetd if ChefUtils::DSL::Service.service_script_exist?(:xinetd, service_name)
- configs << :systemd if ChefUtils::DSL::Service.service_script_exist?(:systemd, service_name)
- configs << :etc_rcd if ChefUtils::DSL::Service.service_script_exist?(:etc_rcd, service_name)
-
- configs
- end
+ module ServiceHelpers
+ include ChefUtils::DSL::Service
+ include Chef::Mixin::ChefUtilsWiring
+
+ def service_resource_providers
+ providers = []
+
+ providers << :debian if debianrcd?
+ providers << :invokercd if invokercd?
+ providers << :upstart if upstart?
+ providers << :insserv if insserv?
+ providers << :systemd if systemd?
+ providers << :redhat if redhatrcd?
+
+ providers
+ end
+
+ def config_for_service(service_name)
+ configs = []
+
+ configs << :initd if service_script_exist?(:initd, service_name)
+ configs << :upstart if service_script_exist?(:upstart, service_name)
+ configs << :xinetd if service_script_exist?(:xinetd, service_name)
+ configs << :systemd if service_script_exist?(:systemd, service_name)
+ configs << :etc_rcd if service_script_exist?(:etc_rcd, service_name)
+
+ configs
end
+
+ extend self
end
end
end
diff --git a/lib/chef/provider/service.rb b/lib/chef/provider/service.rb
index 03e878b97d..7a2d2fc86c 100644
--- a/lib/chef/provider/service.rb
+++ b/lib/chef/provider/service.rb
@@ -23,8 +23,8 @@ require "chef-utils" unless defined?(ChefUtils::CANARY)
class Chef
class Provider
class Service < Chef::Provider
- include ChefUtils::DSL::Service
- extend ChefUtils::DSL::Service
+ include Chef::Platform::ServiceHelpers
+ extend Chef::Platform::ServiceHelpers
def supports
@supports ||= new_resource.supports.dup
diff --git a/lib/chef/resource/service.rb b/lib/chef/resource/service.rb
index 08bf6cd5bc..9a6ad20ee8 100644
--- a/lib/chef/resource/service.rb
+++ b/lib/chef/resource/service.rb
@@ -25,8 +25,8 @@ require_relative "../dist"
class Chef
class Resource
class Service < Chef::Resource
- include ChefUtils::DSL::Service
- extend ChefUtils::DSL::Service
+ include Chef::Platform::ServiceHelpers
+ extend Chef::Platform::ServiceHelpers
unified_mode true
provides :service, target_mode: true
diff --git a/spec/unit/mixin/shell_out_spec.rb b/spec/unit/mixin/shell_out_spec.rb
index 8c0790a2c4..5880aa2b6a 100644
--- a/spec/unit/mixin/shell_out_spec.rb
+++ b/spec/unit/mixin/shell_out_spec.rb
@@ -24,7 +24,6 @@ require "spec_helper"
require "chef/mixin/path_sanity"
describe Chef::Mixin::ShellOut do
- include ChefUtils::DSL::PathSanity
let(:shell_out_class) { Class.new { include Chef::Mixin::ShellOut } }
subject(:shell_out_obj) { shell_out_class.new }
@@ -57,38 +56,38 @@ describe Chef::Mixin::ShellOut do
describe "and environment is an option" do
it "should not change environment language settings when they are set to nil" do
options = { environment: { "LC_ALL" => nil, "LANGUAGE" => nil, "LANG" => nil, env_path => nil } }
- expect(Chef::Mixin::ShellOut).to receive(:shell_out_command).with(cmd, **options).and_return(retobj)
+ expect(shell_out_obj).to receive(:__shell_out_command).with(cmd, **options).and_return(retobj)
shell_out_obj.send(method, cmd, **options)
end
it "should not change environment language settings when they are set to non-nil" do
options = { environment: { "LC_ALL" => "en_US.UTF-8", "LANGUAGE" => "en_US.UTF-8", "LANG" => "en_US.UTF-8", env_path => "foo:bar:baz" } }
- expect(Chef::Mixin::ShellOut).to receive(:shell_out_command).with(cmd, **options).and_return(retobj)
+ expect(shell_out_obj).to receive(:__shell_out_command).with(cmd, **options).and_return(retobj)
shell_out_obj.send(method, cmd, **options)
end
it "should set environment language settings to the configured internal locale when they are not present" do
options = { environment: { "HOME" => "/Users/morty" } }
- expect(Chef::Mixin::ShellOut).to receive(:shell_out_command).with(cmd,
+ expect(shell_out_obj).to receive(:__shell_out_command).with(cmd,
environment: {
"HOME" => "/Users/morty",
"LC_ALL" => Chef::Config[:internal_locale],
"LANG" => Chef::Config[:internal_locale],
"LANGUAGE" => Chef::Config[:internal_locale],
- env_path => sanitized_path,
+ env_path => shell_out_obj.sanitized_path,
}).and_return(retobj)
shell_out_obj.send(method, cmd, **options)
end
it "should not mutate the options hash when it adds language settings" do
options = { environment: { "HOME" => "/Users/morty" } }
- expect(Chef::Mixin::ShellOut).to receive(:shell_out_command).with(cmd,
+ expect(shell_out_obj).to receive(:__shell_out_command).with(cmd,
environment: {
"HOME" => "/Users/morty",
"LC_ALL" => Chef::Config[:internal_locale],
"LANG" => Chef::Config[:internal_locale],
"LANGUAGE" => Chef::Config[:internal_locale],
- env_path => sanitized_path,
+ env_path => shell_out_obj.sanitized_path,
}).and_return(retobj)
shell_out_obj.send(method, cmd, **options)
expect(options[:environment].key?("LC_ALL")).to be false
@@ -98,38 +97,38 @@ describe Chef::Mixin::ShellOut do
describe "and env is an option" do
it "should not change env when langauge options are set to nil" do
options = { env: { "LC_ALL" => nil, "LANG" => nil, "LANGUAGE" => nil, env_path => nil } }
- expect(Chef::Mixin::ShellOut).to receive(:shell_out_command).with(cmd, **options).and_return(retobj)
+ expect(shell_out_obj).to receive(:__shell_out_command).with(cmd, **options).and_return(retobj)
shell_out_obj.send(method, cmd, **options)
end
it "should not change env when language options are set to non-nil" do
options = { env: { "LC_ALL" => "de_DE.UTF-8", "LANG" => "de_DE.UTF-8", "LANGUAGE" => "de_DE.UTF-8", env_path => "foo:bar:baz" } }
- expect(Chef::Mixin::ShellOut).to receive(:shell_out_command).with(cmd, **options).and_return(retobj)
+ expect(shell_out_obj).to receive(:__shell_out_command).with(cmd, **options).and_return(retobj)
shell_out_obj.send(method, cmd, **options)
end
it "should set environment language settings to the configured internal locale when they are not present" do
options = { env: { "HOME" => "/Users/morty" } }
- expect(Chef::Mixin::ShellOut).to receive(:shell_out_command).with(cmd,
+ expect(shell_out_obj).to receive(:__shell_out_command).with(cmd,
env: {
"HOME" => "/Users/morty",
"LC_ALL" => Chef::Config[:internal_locale],
"LANG" => Chef::Config[:internal_locale],
"LANGUAGE" => Chef::Config[:internal_locale],
- env_path => sanitized_path,
+ env_path => shell_out_obj.sanitized_path,
}).and_return(retobj)
shell_out_obj.send(method, cmd, **options)
end
it "should not mutate the options hash when it adds language settings" do
options = { env: { "HOME" => "/Users/morty" } }
- expect(Chef::Mixin::ShellOut).to receive(:shell_out_command).with(cmd,
+ expect(shell_out_obj).to receive(:__shell_out_command).with(cmd,
env: {
"HOME" => "/Users/morty",
"LC_ALL" => Chef::Config[:internal_locale],
"LANG" => Chef::Config[:internal_locale],
"LANGUAGE" => Chef::Config[:internal_locale],
- env_path => sanitized_path,
+ env_path => shell_out_obj.sanitized_path,
}).and_return(retobj)
shell_out_obj.send(method, cmd, **options)
expect(options[:env].key?("LC_ALL")).to be false
@@ -139,13 +138,13 @@ describe Chef::Mixin::ShellOut do
describe "and no env/environment option is present" do
it "should set environment language settings to the configured internal locale" do
options = { user: "morty" }
- expect(Chef::Mixin::ShellOut).to receive(:shell_out_command).with(cmd,
+ expect(shell_out_obj).to receive(:__shell_out_command).with(cmd,
user: "morty",
environment: {
"LC_ALL" => Chef::Config[:internal_locale],
"LANG" => Chef::Config[:internal_locale],
"LANGUAGE" => Chef::Config[:internal_locale],
- env_path => sanitized_path,
+ env_path => shell_out_obj.sanitized_path,
}).and_return(retobj)
shell_out_obj.send(method, cmd, **options)
end
@@ -154,12 +153,12 @@ describe Chef::Mixin::ShellOut do
describe "when the last argument is not a Hash" do
it "should set environment language settings to the configured internal locale" do
- expect(Chef::Mixin::ShellOut).to receive(:shell_out_command).with(cmd,
+ expect(shell_out_obj).to receive(:__shell_out_command).with(cmd,
environment: {
"LC_ALL" => Chef::Config[:internal_locale],
"LANG" => Chef::Config[:internal_locale],
"LANGUAGE" => Chef::Config[:internal_locale],
- env_path => sanitized_path,
+ env_path => shell_out_obj.sanitized_path,
}).and_return(retobj)
shell_out_obj.send(method, cmd)
end
@@ -173,19 +172,19 @@ describe Chef::Mixin::ShellOut do
describe "and environment is an option" do
it "should not change environment['LC_ALL'] when set to nil" do
options = { environment: { "LC_ALL" => nil } }
- expect(Chef::Mixin::ShellOut).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ expect(shell_out_obj).to receive(:__shell_out_command).with(cmd, options).and_return(true)
shell_out_obj.shell_out(cmd, **options, default_env: false)
end
it "should not change environment['LC_ALL'] when set to non-nil" do
options = { environment: { "LC_ALL" => "en_US.UTF-8" } }
- expect(Chef::Mixin::ShellOut).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ expect(shell_out_obj).to receive(:__shell_out_command).with(cmd, options).and_return(true)
shell_out_obj.shell_out(cmd, **options, default_env: false)
end
it "should no longer set environment['LC_ALL'] to nil when 'LC_ALL' not present" do
options = { environment: { "HOME" => "/Users/morty" } }
- expect(Chef::Mixin::ShellOut).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ expect(shell_out_obj).to receive(:__shell_out_command).with(cmd, options).and_return(true)
shell_out_obj.shell_out(cmd, **options, default_env: false)
end
end
@@ -193,19 +192,19 @@ describe Chef::Mixin::ShellOut do
describe "and env is an option" do
it "should not change env when set to nil" do
options = { env: { "LC_ALL" => nil } }
- expect(Chef::Mixin::ShellOut).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ expect(shell_out_obj).to receive(:__shell_out_command).with(cmd, options).and_return(true)
shell_out_obj.shell_out(cmd, **options, default_env: false)
end
it "should not change env when set to non-nil" do
options = { env: { "LC_ALL" => "en_US.UTF-8" } }
- expect(Chef::Mixin::ShellOut).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ expect(shell_out_obj).to receive(:__shell_out_command).with(cmd, options).and_return(true)
shell_out_obj.shell_out(cmd, **options, default_env: false)
end
it "should no longer set env['LC_ALL'] to nil when 'LC_ALL' not present" do
options = { env: { "HOME" => "/Users/morty" } }
- expect(Chef::Mixin::ShellOut).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ expect(shell_out_obj).to receive(:__shell_out_command).with(cmd, options).and_return(true)
shell_out_obj.shell_out(cmd, **options, default_env: false)
end
end
@@ -213,7 +212,7 @@ describe Chef::Mixin::ShellOut do
describe "and no env/environment option is present" do
it "should no longer add environment option and set environment['LC_ALL'] to nil" do
options = { user: "morty" }
- expect(Chef::Mixin::ShellOut).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ expect(shell_out_obj).to receive(:__shell_out_command).with(cmd, options).and_return(true)
shell_out_obj.shell_out(cmd, **options, default_env: false)
end
end
@@ -221,7 +220,7 @@ describe Chef::Mixin::ShellOut do
describe "when the last argument is not a Hash" do
it "should no longer add environment options and set environment['LC_ALL'] to nil" do
- expect(Chef::Mixin::ShellOut).to receive(:shell_out_command).with(cmd).and_return(true)
+ expect(shell_out_obj).to receive(:__shell_out_command).with(cmd).and_return(true)
shell_out_obj.shell_out(cmd, default_env: false)
end
end