mixlib-shellout 3.1.1 → 3.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3e6f0d990000b229cfa3d812040828440973f528374790b2eb261c28db29bc13
4
- data.tar.gz: 23ff6a2702bcb423b56daa92a23938299f541f1724dfb5599059dd65aa4e957c
3
+ metadata.gz: f11a7758041e86b3243966f06c35f8c5e104286cd9658465442a1f15fb1483ec
4
+ data.tar.gz: 6ccd66f875c30ecab220f933bb35019a43f30b463ca9febf05a9d176133ebe46
5
5
  SHA512:
6
- metadata.gz: 6c76cc403ee32e7dae114f34e7684b3aa530eacfde72eb160ab0c007de6dbf3d8497f651d2894c873b6f3e734918de922ad57632965ada3fb1ef67418efb6d31
7
- data.tar.gz: cad33035223cdd99827846282a9e9a201e63a6f99611f25430caaa6ddf72fd3da21f18e97840d77c70d1af9abd2da65bfeb732a20aa41b1f039ae494c8968b44
6
+ metadata.gz: 528a473db4dba8fe3d67add2d7c618d23b0926b02640a09d64b98c520180e0ea9259b790d65523ddc43d57b6d19f577838f59c89c99d3caf1cb380a5a23921ec
7
+ data.tar.gz: 73b5d26d33f68670128e4c4debb265d2f9bb3c7f73a5b04c88fda71ea7de1d6d5e6fdedea3b1be836921a5ec2ff0d9122cc29b70f5021c742a24fb3485c7d7b3
@@ -17,32 +17,22 @@
17
17
 
18
18
  require_relative "../shellout"
19
19
  require "chef-utils"
20
- require "chef-utils/dsl/path_sanity"
20
+ require "chef-utils/dsl/default_paths"
21
21
  require "chef-utils/internal"
22
22
 
23
23
  module Mixlib
24
24
  class ShellOut
25
25
  module Helper
26
26
  include ChefUtils::Internal
27
- include ChefUtils::DSL::PathSanity
27
+ include ChefUtils::DSL::DefaultPaths
28
28
 
29
- # PREFERRED APIS:
30
29
  #
31
- # all consumers should now call shell_out!/shell_out.
30
+ # These APIs are considered public for use in ohai and chef (by cookbooks and plugins, etc)
31
+ # but are considered private/experimental for now for the direct users of mixlib-shellout.
32
32
  #
33
- # the shell_out_compacted/shell_out_compacted! APIs are private but are intended for use
34
- # in rspec tests, and should ideally always be used to make code refactoring that do not
35
- # change behavior easier:
36
- #
37
- # allow(provider).to receive(:shell_out_compacted!).with("foo", "bar", "baz")
38
- # provider.shell_out!("foo", [ "bar", nil, "baz"])
39
- # provider.shell_out!(["foo", nil, "bar" ], ["baz"])
40
- #
41
- # note that shell_out_compacted also includes adding the magical timeout option to force
42
- # people to setup expectations on that value explicitly. it does not include the default_env
43
- # mangling in order to avoid users having to setup an expectation on anything other than
44
- # setting `default_env: false` and allow us to make tweak to the default_env without breaking
45
- # a thousand unit tests.
33
+ # You can see an example of how to handle the "dependenecy injection" in the rspec unit test.
34
+ # That backend API is left deliberately undocumented for now and may not follow SemVer and may
35
+ # break at any time (at least for the rest of 2020).
46
36
  #
47
37
 
48
38
  def shell_out(*args, **options)
@@ -98,15 +88,28 @@ module Mixlib
98
88
  "LC_ALL" => __config[:internal_locale],
99
89
  "LANGUAGE" => __config[:internal_locale],
100
90
  "LANG" => __config[:internal_locale],
101
- __env_path_name => sanitized_path,
91
+ __env_path_name => default_paths,
102
92
  }.update(options[env_key] || {})
103
93
  end
104
94
  options
105
95
  end
106
96
 
107
- # this SHOULD be used for setting up expectations in rspec, see banner comment at top.
97
+ # The shell_out_compacted/shell_out_compacted! APIs are private but are intended for use
98
+ # in rspec tests. They should always be used in rspec tests instead of shell_out to allow
99
+ # for less brittle rspec tests.
108
100
  #
109
- # the private constraint is meant to avoid code calling this directly, rspec expectations are fine.
101
+ # This expectation:
102
+ #
103
+ # allow(provider).to receive(:shell_out_compacted!).with("foo", "bar", "baz")
104
+ #
105
+ # Is met by many different possible calling conventions that mean the same thing:
106
+ #
107
+ # provider.shell_out!("foo", [ "bar", nil, "baz"])
108
+ # provider.shell_out!(["foo", nil, "bar" ], ["baz"])
109
+ #
110
+ # Note that when setting `default_env: false` that you should just setup an expectation on
111
+ # :shell_out_compacted for `default_env: false`, rather than the expanded env settings so
112
+ # that the default_env implementation can change without breaking unit tests.
110
113
  #
111
114
  def shell_out_compacted(*args, **options)
112
115
  options = __apply_default_env(options)
@@ -117,10 +120,6 @@ module Mixlib
117
120
  end
118
121
  end
119
122
 
120
- # this SHOULD be used for setting up expectations in rspec, see banner comment at top.
121
- #
122
- # the private constraint is meant to avoid code calling this directly, rspec expectations are fine.
123
- #
124
123
  def shell_out_compacted!(*args, **options)
125
124
  options = __apply_default_env(options)
126
125
  cmd = if options.empty?
@@ -132,23 +131,12 @@ module Mixlib
132
131
  cmd
133
132
  end
134
133
 
135
- # Helper for subclasses to reject nil out of an array. It allows
136
- # using the array form of shell_out (which avoids the need to surround arguments with
137
- # quote marks to deal with shells).
138
- #
139
- # Usage:
140
- # shell_out!(*clean_array("useradd", universal_options, useradd_options, new_resource.username))
141
- #
142
- # universal_options and useradd_options can be nil, empty array, empty string, strings or arrays
143
- # and the result makes sense.
144
- #
145
- # keeping this separate from shell_out!() makes it a bit easier to write expectations against the
146
- # shell_out args and be able to omit nils and such in the tests (and to test that the nils are
147
- # being rejected correctly).
134
+ # Helper for subclasses to reject nil out of an array. It allows using the array form of
135
+ # shell_out (which avoids the need to surround arguments with quote marks to deal with shells).
148
136
  #
149
137
  # @param args [String] variable number of string arguments
150
138
  # @return [Array] array of strings with nil and null string rejection
151
-
139
+ #
152
140
  def __clean_array(*args)
153
141
  args.flatten.compact.map(&:to_s)
154
142
  end
@@ -1,5 +1,5 @@
1
1
  module Mixlib
2
2
  class ShellOut
3
- VERSION = "3.1.1".freeze
3
+ VERSION = "3.1.2".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mixlib-shellout
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.1
4
+ version: 3.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chef Software Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-17 00:00:00.000000000 Z
11
+ date: 2020-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef-utils