summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorStuart Preston <stuart@chef.io>2018-06-23 22:51:27 +0100
committerStuart Preston <stuart@chef.io>2018-06-23 22:51:27 +0100
commit0d8a14f8972d4908264c3376228489beea191678 (patch)
treec1a51531d1864659c6b3fb1a12ef400d277076ae /spec
parentacb4c6adc451ff72eab8512bafe63fb16ea22856 (diff)
parentbec29232c2b42609a4746f4df9141758af87287f (diff)
downloadchef-0d8a14f8972d4908264c3376228489beea191678.tar.gz
Merge branch 'master' into sp/ffi-powershell
Signed-off-by: <>
Diffstat (limited to 'spec')
-rw-r--r--spec/functional/mixin/shell_out_spec.rb4
-rw-r--r--spec/unit/mixin/shell_out_spec.rb176
-rw-r--r--spec/unit/provider/package_spec.rb2
3 files changed, 169 insertions, 13 deletions
diff --git a/spec/functional/mixin/shell_out_spec.rb b/spec/functional/mixin/shell_out_spec.rb
index f0d1eb7cbc..48a34762c6 100644
--- a/spec/functional/mixin/shell_out_spec.rb
+++ b/spec/functional/mixin/shell_out_spec.rb
@@ -21,6 +21,10 @@ describe Chef::Mixin::ShellOut do
include Chef::Mixin::ShellOut
describe "shell_out_with_systems_locale" do
+ before do
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
+ end
+
describe "when environment['LC_ALL'] is not set" do
it "should use the default shell_out setting" do
cmd = if windows?
diff --git a/spec/unit/mixin/shell_out_spec.rb b/spec/unit/mixin/shell_out_spec.rb
index df35960cc9..2fef051b29 100644
--- a/spec/unit/mixin/shell_out_spec.rb
+++ b/spec/unit/mixin/shell_out_spec.rb
@@ -53,6 +53,9 @@ describe Chef::Mixin::ShellOut do
[ :shell_out, :shell_out_compact, :shell_out_compact_timeout, :shell_out!, :shell_out_compact!, :shell_out_compact_timeout! ].each do |method|
describe "##{method}" do
+ before do
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
+ end
describe "when the last argument is a Hash" do
describe "and environment is an option" do
@@ -157,24 +160,27 @@ describe Chef::Mixin::ShellOut do
end
end
end
- end
- 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, {
- :environment => {
- "LC_ALL" => Chef::Config[:internal_locale],
- "LANG" => Chef::Config[:internal_locale],
- "LANGUAGE" => Chef::Config[:internal_locale],
- env_path => sanitized_path,
- },
- }).and_return(retobj)
- shell_out_obj.send(method, cmd)
+ 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, {
+ :environment => {
+ "LC_ALL" => Chef::Config[:internal_locale],
+ "LANG" => Chef::Config[:internal_locale],
+ "LANGUAGE" => Chef::Config[:internal_locale],
+ env_path => sanitized_path,
+ },
+ }).and_return(retobj)
+ shell_out_obj.send(method, cmd)
+ end
end
end
end
describe "#shell_out_with_systems_locale" do
+ before do
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
+ end
describe "when the last argument is a Hash" do
describe "and environment is an option" do
@@ -294,5 +300,151 @@ describe Chef::Mixin::ShellOut do
end
end
+ describe "deprecations" do
+ [ :shell_out_with_systems_locale, :shell_out_compact, :shell_out_compact_timeout, :shell_out_with_systems_locale!, :shell_out_compact!, :shell_out_compact_timeout! ].each do |method|
+ it "should not respond to #{method} in Chef-15", chef: ">= 15" do
+ expect(shell_out_obj.respond_to?(method)).to be false
+ end
+ end
+
+ it "removed shell_out_with_timeout from Chef::Provider::Package", chef: ">= 15" do
+ expect(Chef::Provider::Package.instance_methods + Chef::Provider::Package.private_instance_methods).not_to include(:shell_out_with_timeout)
+ end
+
+ it "removed shell_out_with_timeout! from Chef::Provider::Package", chef: ">= 15" do
+ expect(Chef::Provider::Package.instance_methods + Chef::Provider::Package.private_instance_methods).not_to include(:shell_out_with_timeout!)
+ end
+ end
+
+ describe "Custom Resource timeouts" do
+ class CustomResource < Chef::Resource
+ provides :whatever
+
+ property :timeout, Numeric
+
+ action :install do
+ end
+ end
+
+ let(:new_resource) { CustomResource.new("foo") }
+ let(:provider) { new_resource.provider_for_action(:install) }
+
+ describe "on Chef-14", chef: "< 15" do
+ it "doesn't add timeout for shell_out" do
+ expect(provider).to receive(:shell_out_compacted).with("foo")
+ provider.shell_out("foo")
+ end
+ it "doesn't add timeout for shell_out!" do
+ expect(provider).to receive(:shell_out_compacted!).with("foo")
+ provider.shell_out!("foo")
+ end
+ end
+
+ describe "on Chef-15", chef: ">= 15" do
+ [ :shell_out, :shell_out! ].each do |method|
+ stubbed_method = (method == :shell_out) ? :shell_out_compacted : :shell_out_compacted!
+ it "#{method} defaults to 900 seconds" do
+ expect(provider).to receive(stubbed_method).with("foo", timeout: 900)
+ provider.send(method, "foo")
+ end
+ it "#{method} overrides the default timeout with its options" do
+ expect(provider).to receive(stubbed_method).with("foo", timeout: 1)
+ provider.send(method, "foo", timeout: 1)
+ end
+ it "#{method} overrides the new_resource.timeout with the timeout option" do
+ new_resource.timeout(99)
+ expect(provider).to receive(stubbed_method).with("foo", timeout: 1)
+ provider.send(method, "foo", timeout: 1)
+ end
+ it "#{method} defaults to 900 seconds and preserves options" do
+ expect(provider).to receive(stubbed_method).with("foo", env: nil, timeout: 900)
+ provider.send(method, "foo", env: nil)
+ end
+ it "#{method} overrides the default timeout with its options and preserves options" do
+ expect(provider).to receive(stubbed_method).with("foo", timeout: 1, env: nil)
+ provider.send(method, "foo", timeout: 1, env: nil)
+ end
+ it "#{method} overrides the new_resource.timeout with the timeout option and preseves options" do
+ new_resource.timeout(99)
+ expect(provider).to receive(stubbed_method).with("foo", timeout: 1, env: nil)
+ provider.send(method, "foo", timeout: 1, env: nil)
+ end
+ end
+ end
+ end
+
+ describe "timeouts" do
+ let(:new_resource) { Chef::Resource::Package.new("foo") }
+ let(:provider) { new_resource.provider_for_action(:install) }
+
+ [ :shell_out, :shell_out! ].each do |method|
+ stubbed_method = (method == :shell_out) ? :shell_out_compacted : :shell_out_compacted!
+ it "#{method} defaults to 900 seconds" do
+ expect(provider).to receive(stubbed_method).with("foo", timeout: 900)
+ provider.send(method, "foo")
+ end
+ it "#{method} overrides the default timeout with its options" do
+ expect(provider).to receive(stubbed_method).with("foo", timeout: 1)
+ provider.send(method, "foo", timeout: 1)
+ end
+ it "#{method} overrides the new_resource.timeout with the timeout option" do
+ new_resource.timeout(99)
+ expect(provider).to receive(stubbed_method).with("foo", timeout: 1)
+ provider.send(method, "foo", timeout: 1)
+ end
+ it "#{method} defaults to 900 seconds and preserves options" do
+ expect(provider).to receive(stubbed_method).with("foo", env: nil, timeout: 900)
+ provider.send(method, "foo", env: nil)
+ end
+ it "#{method} overrides the default timeout with its options and preserves options" do
+ expect(provider).to receive(stubbed_method).with("foo", timeout: 1, env: nil)
+ provider.send(method, "foo", timeout: 1, env: nil)
+ end
+ it "#{method} overrides the new_resource.timeout with the timeout option and preseves options" do
+ new_resource.timeout(99)
+ expect(provider).to receive(stubbed_method).with("foo", timeout: 1, env: nil)
+ provider.send(method, "foo", timeout: 1, env: nil)
+ end
+ end
+ end
+
+ describe "deprecated timeouts" do # Chef 15: delete me
+ let(:new_resource) { Chef::Resource::Package.new("foo") }
+ let(:provider) { new_resource.provider_for_action(:install) }
+
+ before(:each) do
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
+ end
+
+ [ :shell_out_compact_timeout, :shell_out_compact_timeout! ].each do |method|
+ stubbed_method = (method == :shell_out_compact_timeout) ? :shell_out_compacted : :shell_out_compacted!
+ it "#{method} defaults to 900 seconds" do
+ expect(provider).to receive(stubbed_method).with("foo", timeout: 900)
+ provider.send(method, "foo")
+ end
+ it "#{method} overrides the default timeout with its options" do
+ expect(provider).to receive(stubbed_method).with("foo", timeout: 1)
+ provider.send(method, "foo", timeout: 1)
+ end
+ it "#{method} overrides the new_resource.timeout with the timeout option" do
+ new_resource.timeout(99)
+ expect(provider).to receive(stubbed_method).with("foo", timeout: 99)
+ provider.send(method, "foo", timeout: 1)
+ end
+ it "#{method} defaults to 900 seconds and preserves options" do
+ expect(provider).to receive(stubbed_method).with("foo", env: nil, timeout: 900)
+ provider.send(method, "foo", env: nil)
+ end
+ it "#{method} overrides the default timeout with its options and preserves options" do
+ expect(provider).to receive(stubbed_method).with("foo", timeout: 1, env: nil)
+ provider.send(method, "foo", timeout: 1, env: nil)
+ end
+ it "#{method} overrides the new_resource.timeout with the timeout option and preseves options" do
+ new_resource.timeout(99)
+ expect(provider).to receive(stubbed_method).with("foo", timeout: 99, env: nil)
+ provider.send(method, "foo", timeout: 1, env: nil)
+ end
+ end
+ end
end
end
diff --git a/spec/unit/provider/package_spec.rb b/spec/unit/provider/package_spec.rb
index 2eb7cf63e1..904e339e47 100644
--- a/spec/unit/provider/package_spec.rb
+++ b/spec/unit/provider/package_spec.rb
@@ -942,7 +942,7 @@ describe "Chef::Provider::Package - Multi" do
end
[ :shell_out_with_timeout, :shell_out_with_timeout! ].each do |method|
- stubbed_method = method == :shell_out_with_timeout! ? :shell_out! : :shell_out
+ stubbed_method = method == :shell_out_with_timeout! ? :shell_out_compacted! : :shell_out_compacted
[ %w{command arg1 arg2}, "command arg1 arg2" ].each do |command|
it "#{method} defaults to 900 seconds" do
expect(provider).to receive(stubbed_method).with(*command, timeout: 900)