summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/functional/resource/powershell_script_spec.rb75
-rw-r--r--spec/functional/resource/windows_certificate_spec.rb2
-rw-r--r--spec/functional/resource/windows_service_spec.rb3
-rw-r--r--spec/functional/win32/service_manager_spec.rb2
-rw-r--r--spec/integration/client/client_spec.rb3
-rw-r--r--spec/spec_helper.rb5
-rw-r--r--spec/support/platform_helpers.rb5
-rw-r--r--spec/support/shared/functional/windows_script.rb17
-rw-r--r--spec/support/shared/unit/script_resource.rb4
-rw-r--r--spec/unit/cookbook/metadata_spec.rb11
-rw-r--r--spec/unit/encrypted_data_bag_item/check_encrypted_spec.rb2
-rw-r--r--spec/unit/encrypted_data_bag_item_spec.rb4
-rw-r--r--spec/unit/knife/core/ui_spec.rb16
-rw-r--r--spec/unit/mixin/shell_out_spec.rb56
-rw-r--r--spec/unit/platform/query_helpers_spec.rb145
-rw-r--r--spec/unit/provider/directory_spec.rb21
-rw-r--r--spec/unit/provider/powershell_script_spec.rb84
-rw-r--r--spec/unit/provider/service/macosx_spec.rb424
-rw-r--r--spec/unit/resource/powershell_script_spec.rb5
19 files changed, 300 insertions, 584 deletions
diff --git a/spec/functional/resource/powershell_script_spec.rb b/spec/functional/resource/powershell_script_spec.rb
index 74ece0d33c..32a128ac72 100644
--- a/spec/functional/resource/powershell_script_spec.rb
+++ b/spec/functional/resource/powershell_script_spec.rb
@@ -55,8 +55,6 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
end
it "returns the exit status 27 for a powershell script that exits with 27" do
- pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server?
-
file = Tempfile.new(["foo", ".ps1"])
begin
file.write "exit 27"
@@ -73,7 +71,6 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
let (:negative_exit_status) { -27 }
let (:unsigned_exit_status) { (-negative_exit_status ^ 65535) + 1 }
it "returns the exit status -27 as a signed integer or an unsigned 16-bit 2's complement value of 65509 for a powershell script that exits with -27" do
- pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server?
# Versions of PowerShell prior to 4.0 return a 16-bit unsigned value --
# PowerShell 4.0 and later versions return a 32-bit signed value.
@@ -98,8 +95,6 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
end
it "returns the process exit code" do
- pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server?
-
resource.code(arbitrary_nonzero_process_exit_code_content)
resource.returns(arbitrary_nonzero_process_exit_code)
resource.run_action(:run)
@@ -118,34 +113,24 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
end
it "returns 1 if the last command was a cmdlet that failed" do
- pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server?
-
resource.code(cmdlet_exit_code_not_found_content)
resource.returns(1)
resource.run_action(:run)
end
it "returns 1 if the last command was a cmdlet that failed and was preceded by a successfully executed non-cmdlet Windows binary" do
- pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server?
-
resource.code([windows_process_exit_code_success_content, cmdlet_exit_code_not_found_content].join(";"))
resource.returns(1)
expect { resource.run_action(:run) }.not_to raise_error
end
it "raises a Mixlib::ShellOut::ShellCommandFailed error if the script is not syntactically correct" do
- pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server?
-
resource.code("if({)")
resource.returns(0)
expect { resource.run_action(:run) }.to raise_error(Mixlib::ShellOut::ShellCommandFailed)
end
it "raises an error if the script is not syntactically correct even if returns is set to 1 which is what powershell.exe returns for syntactically invalid scripts" do
- # This test fails because shell_out expects the exit status to be 1, but it is actually 0
- # The error is a false-positive.
- skip "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server?
-
resource.code("if({)")
resource.returns(1)
expect { resource.run_action(:run) }.to raise_error(Mixlib::ShellOut::ShellCommandFailed)
@@ -160,32 +145,24 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
# errors than 0 or 1, we return that instead, which is acceptable
# since callers can test for nonzero rather than testing for 1.
it "returns 1 if the last command was a cmdlet that failed and was preceded by an unsuccessfully executed non-cmdlet Windows binary" do
- pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server?
-
resource.code([arbitrary_nonzero_process_exit_code_content, cmdlet_exit_code_not_found_content].join(";"))
resource.returns(arbitrary_nonzero_process_exit_code)
resource.run_action(:run)
end
it "returns 0 if the last command was a non-cmdlet Windows binary that succeeded and was preceded by a failed cmdlet" do
- pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server?
-
resource.code([cmdlet_exit_code_success_content, arbitrary_nonzero_process_exit_code_content].join(";"))
resource.returns(arbitrary_nonzero_process_exit_code)
resource.run_action(:run)
end
it "returns a specific error code if the last command was a non-cmdlet Windows binary that failed and was preceded by cmdlet that succeeded" do
- pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server?
-
resource.code([cmdlet_exit_code_success_content, arbitrary_nonzero_process_exit_code_content].join(";"))
resource.returns(arbitrary_nonzero_process_exit_code)
resource.run_action(:run)
end
it "returns a specific error code if the last command was a non-cmdlet Windows binary that failed and was preceded by cmdlet that failed" do
- pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server?
-
resource.code([cmdlet_exit_code_not_found_content, arbitrary_nonzero_process_exit_code_content].join(";"))
resource.returns(arbitrary_nonzero_process_exit_code)
resource.run_action(:run)
@@ -204,8 +181,6 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
end
it "returns 1 for $false as the last line of the script when convert_boolean_return is true" do
- pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server?
-
resource.convert_boolean_return true
resource.code "$false"
resource.returns(1)
@@ -245,8 +220,6 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
end
it "returns 1 if an invalid flag is passed to the interpreter" do
- pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server?
-
resource.code(cmdlet_exit_code_success_content)
resource.flags(invalid_powershell_interpreter_flag)
resource.returns(1)
@@ -318,7 +291,7 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
expect(source_contains_case_insensitive_content?( get_script_output, "AMD64" )).to eq(true)
end
- it "executes a script with a 32-bit process if :i386 arch is specified", :not_supported_on_nano do
+ it "executes a script with a 32-bit process if :i386 arch is specified" do
resource.code(processor_architecture_script_content + " | out-file -encoding ASCII #{script_output_path}")
resource.architecture(:i386)
resource.returns(0)
@@ -326,12 +299,6 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
expect(source_contains_case_insensitive_content?( get_script_output, "x86" )).to eq(true)
end
-
- it "raises an error when executing a script with a 32-bit process on Windows Nano Server", :windows_nano_only do
- resource.code(processor_architecture_script_content + " | out-file -encoding ASCII #{script_output_path}")
- expect { resource.architecture(:i386) }.to raise_error(Chef::Exceptions::Win32ArchitectureIncorrect,
- "cannot execute script with requested architecture 'i386' on Windows Nano Server")
- end
end
describe "when executing guards" do
@@ -385,8 +352,6 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
end
it "evaluates a powershell $false for a not_if block as true" do
- pending "powershell.exe always exits with $true on nano" if Chef::Platform.windows_nano_server?
-
resource.not_if "$false"
expect(resource.should_skip?(:run)).to be_falsey
end
@@ -397,8 +362,6 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
end
it "evaluates a powershell $false for an only_if block as false" do
- pending "powershell.exe always exits with $true on nano" if Chef::Platform.windows_nano_server?
-
resource.only_if "$false"
expect(resource.should_skip?(:run)).to be_truthy
end
@@ -419,8 +382,6 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
end
it "evaluates a non-zero powershell exit status for not_if as true" do
- pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server?
-
resource.not_if "exit 37"
expect(resource.should_skip?(:run)).to be_falsey
end
@@ -431,8 +392,6 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
end
it "evaluates a failed executable exit status for not_if as false" do
- pending "powershell.exe always exits with success on nano" if Chef::Platform.windows_nano_server?
-
resource.not_if windows_process_exit_code_not_found_content
expect(resource.should_skip?(:run)).to be_falsey
end
@@ -443,8 +402,6 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
end
it "evaluates a failed executable exit status for only_if as false" do
- pending "powershell.exe always exits with success on nano" if Chef::Platform.windows_nano_server?
-
resource.only_if windows_process_exit_code_not_found_content
expect(resource.should_skip?(:run)).to be_truthy
end
@@ -455,8 +412,6 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
end
it "evaluates a failed cmdlet exit status for not_if as true" do
- pending "powershell.exe always exits with success on nano" if Chef::Platform.windows_nano_server?
-
resource.not_if "throw 'up'"
expect(resource.should_skip?(:run)).to be_falsey
end
@@ -467,8 +422,6 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
end
it "evaluates a failed cmdlet exit status for only_if as false" do
- pending "powershell.exe always exits with success on nano" if Chef::Platform.windows_nano_server?
-
resource.only_if "throw 'up'"
expect(resource.should_skip?(:run)).to be_truthy
end
@@ -511,36 +464,30 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
end
it "evaluates a 64-bit resource with a 64-bit guard and interprets boolean true as nonzero status code", :windows64_only do
- pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server?
-
resource.architecture :x86_64
resource.only_if "exit [int32]($env:PROCESSOR_ARCHITECTURE -eq 'AMD64')"
expect(resource.should_skip?(:run)).to be_truthy
end
- it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean false as zero status code", :not_supported_on_nano do
+ it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean false as zero status code" do
resource.architecture :i386
resource.only_if "exit [int32]($env:PROCESSOR_ARCHITECTURE -ne 'X86')"
expect(resource.should_skip?(:run)).to be_falsey
end
- it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean true as nonzero status code", :not_supported_on_nano do
+ it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean true as nonzero status code" do
resource.architecture :i386
resource.only_if "exit [int32]($env:PROCESSOR_ARCHITECTURE -eq 'X86')"
expect(resource.should_skip?(:run)).to be_truthy
end
it "evaluates a simple boolean false as nonzero status code when convert_boolean_return is true for only_if" do
- pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server?
-
resource.convert_boolean_return true
resource.only_if "$false"
expect(resource.should_skip?(:run)).to be_truthy
end
it "evaluates a simple boolean false as nonzero status code when convert_boolean_return is true for not_if" do
- pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server?
-
resource.convert_boolean_return true
resource.not_if "$false"
expect(resource.should_skip?(:run)).to be_falsey
@@ -558,41 +505,33 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
expect(resource.should_skip?(:run)).to be_truthy
end
- it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean false as zero status code using convert_boolean_return for only_if", :not_supported_on_nano do
+ it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean false as zero status code using convert_boolean_return for only_if" do
resource.convert_boolean_return true
resource.architecture :i386
resource.only_if "$env:PROCESSOR_ARCHITECTURE -eq 'X86'"
expect(resource.should_skip?(:run)).to be_falsey
end
- it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean false as zero status code using convert_boolean_return for not_if", :not_supported_on_nano do
+ it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean false as zero status code using convert_boolean_return for not_if" do
resource.convert_boolean_return true
resource.architecture :i386
resource.not_if "$env:PROCESSOR_ARCHITECTURE -ne 'X86'"
expect(resource.should_skip?(:run)).to be_falsey
end
- it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean true as nonzero status code using convert_boolean_return for only_if", :not_supported_on_nano do
+ it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean true as nonzero status code using convert_boolean_return for only_if" do
resource.convert_boolean_return true
resource.architecture :i386
resource.only_if "$env:PROCESSOR_ARCHITECTURE -ne 'X86'"
expect(resource.should_skip?(:run)).to be_truthy
end
- it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean true as nonzero status code using convert_boolean_return for not_if", :not_supported_on_nano do
+ it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean true as nonzero status code using convert_boolean_return for not_if" do
resource.convert_boolean_return true
resource.architecture :i386
resource.not_if "$env:PROCESSOR_ARCHITECTURE -eq 'X86'"
expect(resource.should_skip?(:run)).to be_truthy
end
-
- it "raises an error when a 32-bit guard is used on Windows Nano Server", :windows_nano_only do
- resource.only_if "$true", architecture: :i386
- expect { resource.run_action(:run) }.to raise_error(
- Chef::Exceptions::Win32ArchitectureIncorrect,
- /cannot execute script with requested architecture 'i386' on Windows Nano Server/
- )
- end
end
end
diff --git a/spec/functional/resource/windows_certificate_spec.rb b/spec/functional/resource/windows_certificate_spec.rb
index 9b79de6a77..d17bb0b1fe 100644
--- a/spec/functional/resource/windows_certificate_spec.rb
+++ b/spec/functional/resource/windows_certificate_spec.rb
@@ -47,7 +47,7 @@ module WindowsCertificateHelper
end
end
-describe Chef::Resource::WindowsCertificate, :windows_only, :appveyor_only do
+describe Chef::Resource::WindowsCertificate, :windows_only do
include WindowsCertificateHelper
let(:stdout) { StringIO.new }
diff --git a/spec/functional/resource/windows_service_spec.rb b/spec/functional/resource/windows_service_spec.rb
index 999b235df1..1ebffd1833 100644
--- a/spec/functional/resource/windows_service_spec.rb
+++ b/spec/functional/resource/windows_service_spec.rb
@@ -18,8 +18,7 @@
require "spec_helper"
-describe Chef::Resource::WindowsService, :windows_only, :system_windows_service_gem_only, :appveyor_only, broken: true do
- # Marking as broken. This test is causing appveyor tests to exit with 116.
+describe Chef::Resource::WindowsService, :windows_only, :system_windows_service_gem_only do
include_context "using Win32::Service"
diff --git a/spec/functional/win32/service_manager_spec.rb b/spec/functional/win32/service_manager_spec.rb
index bb8ed54c0e..220cc3c183 100644
--- a/spec/functional/win32/service_manager_spec.rb
+++ b/spec/functional/win32/service_manager_spec.rb
@@ -33,7 +33,7 @@ end
# directories.
#
-describe "Chef::Application::WindowsServiceManager", :windows_only, :system_windows_service_gem_only, :appveyor_only do
+describe "Chef::Application::WindowsServiceManager", :windows_only, :system_windows_service_gem_only do
include_context "using Win32::Service"
diff --git a/spec/integration/client/client_spec.rb b/spec/integration/client/client_spec.rb
index b1763da1f0..e2d1c9532e 100644
--- a/spec/integration/client/client_spec.rb
+++ b/spec/integration/client/client_spec.rb
@@ -540,8 +540,7 @@ describe "chef-client" do
end
end
- # Fails on appveyor, but works locally on windows and on windows hosts in Ci.
- context "when using recipe-url", :skip_appveyor do
+ context "when using recipe-url" do
before(:each) do
start_tiny_server
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 3154e2f255..605f920125 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -140,9 +140,6 @@ RSpec.configure do |config|
config.filter_run_excluding volatile_on_solaris: true if solaris?
config.filter_run_excluding volatile_from_verify: false
- config.filter_run_excluding skip_appveyor: true if ENV["APPVEYOR"]
- config.filter_run_excluding appveyor_only: true unless ENV["APPVEYOR"]
-
config.filter_run_excluding skip_buildkite: true if ENV["BUILDKITE"]
config.filter_run_excluding windows_only: true unless windows?
@@ -153,11 +150,9 @@ RSpec.configure do |config|
config.filter_run_excluding not_supported_on_aix: true if aix?
config.filter_run_excluding not_supported_on_solaris: true if solaris?
config.filter_run_excluding not_supported_on_gce: true if gce?
- config.filter_run_excluding not_supported_on_nano: true if windows_nano_server?
config.filter_run_excluding win2012r2_only: true unless windows_2012r2?
config.filter_run_excluding windows64_only: true unless windows64?
config.filter_run_excluding windows32_only: true unless windows32?
- config.filter_run_excluding windows_nano_only: true unless windows_nano_server?
config.filter_run_excluding windows_gte_10: true unless windows_gte_10?
config.filter_run_excluding windows_lt_10: true if windows_gte_10?
config.filter_run_excluding ruby64_only: true unless ruby_64bit?
diff --git a/spec/support/platform_helpers.rb b/spec/support/platform_helpers.rb
index c92b3dca39..f9d8955f1e 100644
--- a/spec/support/platform_helpers.rb
+++ b/spec/support/platform_helpers.rb
@@ -88,11 +88,6 @@ def windows_powershell_dsc?
supports_dsc
end
-def windows_nano_server?
- require "chef/platform/query_helpers"
- Chef::Platform.windows_nano_server?
-end
-
def windows_user_right?(right)
return false unless windows?
diff --git a/spec/support/shared/functional/windows_script.rb b/spec/support/shared/functional/windows_script.rb
index 49fd727055..eca63a6af3 100644
--- a/spec/support/shared/functional/windows_script.rb
+++ b/spec/support/shared/functional/windows_script.rb
@@ -99,7 +99,7 @@ shared_context Chef::Resource::WindowsScript do
end
end
- context "when the guard's architecture is specified as 32-bit", :not_supported_on_nano do
+ context "when the guard's architecture is specified as 32-bit" do
let (:guard_architecture) { :i386 }
it "executes a 32-bit guard" do
resource.only_if resource_guard_command, architecture: guard_architecture
@@ -107,17 +107,6 @@ shared_context Chef::Resource::WindowsScript do
expect(get_guard_process_architecture).to eq("x86")
end
end
-
- context "when the guard's architecture is specified as 32-bit", :windows_nano_only do
- let (:guard_architecture) { :i386 }
- it "raises an error" do
- resource.only_if resource_guard_command, architecture: guard_architecture
- expect { resource.run_action(:run) }.to raise_error(
- Chef::Exceptions::Win32ArchitectureIncorrect,
- /cannot execute script with requested architecture 'i386' on Windows Nano Server/
- )
- end
- end
end
end
@@ -218,8 +207,6 @@ shared_context Chef::Resource::WindowsScript do
context "when evaluating guards" do
it "has a guard_interpreter attribute set to the short name of the resource" do
- pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server?
-
expect(resource.guard_interpreter).to eq(resource.resource_name)
resource.not_if "findstr.exe /thiscommandhasnonzeroexitstatus"
expect(Chef::Resource).to receive(:resource_for_node).and_call_original
@@ -238,7 +225,7 @@ shared_context Chef::Resource::WindowsScript do
it_behaves_like "a script resource with architecture attribute"
end
- context "when the architecture attribute is :i386", :not_supported_on_nano do
+ context "when the architecture attribute is :i386" do
let(:resource_architecture) { :i386 }
it_behaves_like "a script resource with architecture attribute"
end
diff --git a/spec/support/shared/unit/script_resource.rb b/spec/support/shared/unit/script_resource.rb
index 83d7d9dfe6..3c158afd6b 100644
--- a/spec/support/shared/unit/script_resource.rb
+++ b/spec/support/shared/unit/script_resource.rb
@@ -30,7 +30,7 @@ shared_examples_for "a script resource" do
expect(script_resource.resource_name).to eql(resource_name)
end
- it "should set command to nil on the resource", chef: ">= 13" do
+ it "should set command to nil on the resource" do
expect(script_resource.command).to be nil
end
@@ -44,7 +44,7 @@ shared_examples_for "a script resource" do
expect(script_resource.flags.strip).to eql("-f")
end
- it "should raise an exception if users set command on the resource", chef: ">= 13" do
+ it "should raise an exception if users set command on the resource" do
expect { script_resource.command("foo") }.to raise_error(Chef::Exceptions::Script)
end
diff --git a/spec/unit/cookbook/metadata_spec.rb b/spec/unit/cookbook/metadata_spec.rb
index 6de2ab2a08..3c52198310 100644
--- a/spec/unit/cookbook/metadata_spec.rb
+++ b/spec/unit/cookbook/metadata_spec.rb
@@ -267,16 +267,7 @@ describe Chef::Cookbook::Metadata do
end
end
- it "strips out self-dependencies", chef: "< 13" do
- metadata.name("foo")
- expect(Chef::Log).to receive(:warn).with(
- "Ignoring self-dependency in cookbook foo, please remove it (in the future this will be fatal)."
- )
- metadata.depends("foo")
- expect(metadata.dependencies).to eql({})
- end
-
- it "errors on self-dependencies", chef: ">= 13" do
+ it "errors on self-dependencies" do
metadata.name("foo")
expect { metadata.depends("foo") }.to raise_error
# FIXME: add the error type
diff --git a/spec/unit/encrypted_data_bag_item/check_encrypted_spec.rb b/spec/unit/encrypted_data_bag_item/check_encrypted_spec.rb
index f8fcb654d9..f7968dd3fb 100644
--- a/spec/unit/encrypted_data_bag_item/check_encrypted_spec.rb
+++ b/spec/unit/encrypted_data_bag_item/check_encrypted_spec.rb
@@ -85,7 +85,7 @@ describe Chef::EncryptedDataBagItem::CheckEncrypted do
end
end
- context "when encryption version is 3", :aes_256_gcm_only, ruby: "~> 2.0.0" do
+ context "when encryption version is 3", :aes_256_gcm_only do
include_examples "encryption detected" do
let(:version) { 3 }
let(:encryptor) { Chef::EncryptedDataBagItem::Encryptor::Version3Encryptor }
diff --git a/spec/unit/encrypted_data_bag_item_spec.rb b/spec/unit/encrypted_data_bag_item_spec.rb
index f406aa2ad0..64f62c6d21 100644
--- a/spec/unit/encrypted_data_bag_item_spec.rb
+++ b/spec/unit/encrypted_data_bag_item_spec.rb
@@ -97,7 +97,7 @@ describe Chef::EncryptedDataBagItem::Encryptor do
Chef::Config[:data_bag_encrypt_version] = 3
end
- context "on supported platforms", :aes_256_gcm_only, ruby: "~> 2.0.0" do
+ context "on supported platforms", :aes_256_gcm_only do
it "creates a version 3 encryptor" do
expect(encryptor).to be_a_instance_of(Chef::EncryptedDataBagItem::Encryptor::Version3Encryptor)
@@ -166,7 +166,7 @@ describe Chef::EncryptedDataBagItem::Decryptor do
context "when decrypting a version 3 (JSON+aes-256-gcm+random iv+auth tag) encrypted value" do
- context "on supported platforms", :aes_256_gcm_only, ruby: "~> 2.0.0" do
+ context "on supported platforms", :aes_256_gcm_only do
let(:encrypted_value) do
Chef::EncryptedDataBagItem::Encryptor::Version3Encryptor.new(plaintext_data, encryption_key).for_encrypted_item
diff --git a/spec/unit/knife/core/ui_spec.rb b/spec/unit/knife/core/ui_spec.rb
index dfe906fdc1..e870926b3f 100644
--- a/spec/unit/knife/core/ui_spec.rb
+++ b/spec/unit/knife/core/ui_spec.rb
@@ -507,6 +507,22 @@ describe Chef::Knife::UI do
end
end
+ describe "color" do
+ context "when ui.color? => true" do
+ it "returns colored output" do
+ expect(@ui).to receive(:color?).and_return(true)
+ expect(@ui.color("a_bus_is", :yellow)).to eql("\e[33ma_bus_is\e[0m")
+ end
+ end
+
+ context "when ui.color? => false" do
+ it "returns plain output" do
+ expect(@ui).to receive(:color?).and_return(false)
+ expect(@ui.color("a_bus_is", :yellow)).to eql("a_bus_is")
+ end
+ end
+ end
+
describe "confirm" do
let(:stdout) { StringIO.new }
let(:output) { stdout.string }
diff --git a/spec/unit/mixin/shell_out_spec.rb b/spec/unit/mixin/shell_out_spec.rb
index afa3687a15..f2b0295bf6 100644
--- a/spec/unit/mixin/shell_out_spec.rb
+++ b/spec/unit/mixin/shell_out_spec.rb
@@ -246,35 +246,33 @@ describe Chef::Mixin::ShellOut do
let(:new_resource) { CustomResource.new("foo") }
let(:provider) { new_resource.provider_for_action(:install) }
- describe "on Chef-15", chef: ">= 15" do
- %i{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
+ %i{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
diff --git a/spec/unit/platform/query_helpers_spec.rb b/spec/unit/platform/query_helpers_spec.rb
index d5e4d09029..3ed86cdc4c 100644
--- a/spec/unit/platform/query_helpers_spec.rb
+++ b/spec/unit/platform/query_helpers_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Bryan McLellan <btm@loftninjas.org>
-# Copyright:: Copyright 2014-2018, Chef Software Inc.
+# Copyright:: Copyright 2014-2020, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,149 +18,6 @@
require "spec_helper"
-describe "Chef::Platform#windows_nano_server?" do
- include_context "Win32"
-
- let(:key) { "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Server\\ServerLevels" }
- let(:key_query_value) { 0x0001 }
- let(:access) { key_query_value | 0x0100 }
- let(:hive) { double("Win32::Registry::HKEY_LOCAL_MACHINE") }
- let(:registry) { double("Win32::Registry") }
-
- before(:all) do
- Win32::Registry = Class.new
- Win32::Registry::Error = Class.new(RuntimeError)
- end
-
- before do
- Win32::Registry::HKEY_LOCAL_MACHINE = hive
- Win32::Registry::KEY_QUERY_VALUE = key_query_value
- end
-
- after do
- Win32::Registry.send(:remove_const, "HKEY_LOCAL_MACHINE") if defined?(Win32::Registry::HKEY_LOCAL_MACHINE)
- Win32::Registry.send(:remove_const, "KEY_QUERY_VALUE") if defined?(Win32::Registry::KEY_QUERY_VALUE)
- end
-
- it "returns false early when not on windows" do
- allow(ChefUtils).to receive(:windows?).and_return(false)
- expect(Chef::Platform).to_not receive(:require)
- expect(Chef::Platform.windows_nano_server?).to be false
- end
-
- it "returns true when the registry value is 1" do
- allow(ChefUtils).to receive(:windows?).and_return(true)
- allow(Chef::Platform).to receive(:require).with("win32/registry")
- expect(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open)
- .with(key, access)
- .and_yield(registry)
- expect(registry).to receive(:[]).with("NanoServer").and_return(1)
- expect(Chef::Platform.windows_nano_server?).to be true
- end
-
- it "returns false when the registry value is not 1" do
- allow(ChefUtils).to receive(:windows?).and_return(true)
- allow(Chef::Platform).to receive(:require).with("win32/registry")
- expect(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open)
- .with(key, access)
- .and_yield(registry)
- expect(registry).to receive(:[]).with("NanoServer").and_return(0)
- expect(Chef::Platform.windows_nano_server?).to be false
- end
-
- it "returns false when the registry value does not exist" do
- allow(ChefUtils).to receive(:windows?).and_return(true)
- allow(Chef::Platform).to receive(:require).with("win32/registry")
- expect(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open)
- .with(key, access)
- .and_yield(registry)
- expect(registry).to receive(:[]).with("NanoServer")
- .and_raise(Win32::Registry::Error, "The system cannot find the file specified.")
- expect(Chef::Platform.windows_nano_server?).to be false
- end
-
- it "returns false when the registry key does not exist" do
- allow(ChefUtils).to receive(:windows?).and_return(true)
- allow(Chef::Platform).to receive(:require).with("win32/registry")
- expect(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open)
- .with(key, access)
- .and_raise(Win32::Registry::Error, "The system cannot find the file specified.")
- expect(Chef::Platform.windows_nano_server?).to be false
- end
-end
-
-describe "Chef::Platform#supports_msi?" do
- include_context "Win32" # clear and restore Win32:: namespace
-
- let(:key) { "System\\CurrentControlSet\\Services\\msiserver" }
- let(:key_query_value) { 0x0001 }
- let(:access) { key_query_value }
- let(:hive) { double("Win32::Registry::HKEY_LOCAL_MACHINE") }
- let(:registry) { double("Win32::Registry") }
-
- before(:all) do
- Win32::Registry = Class.new
- Win32::Registry::Error = Class.new(RuntimeError)
- end
-
- before do
- Win32::Registry::HKEY_LOCAL_MACHINE = hive
- Win32::Registry::KEY_QUERY_VALUE = key_query_value
- end
-
- after do
- Win32::Registry.send(:remove_const, "HKEY_LOCAL_MACHINE") if defined?(Win32::Registry::HKEY_LOCAL_MACHINE)
- Win32::Registry.send(:remove_const, "KEY_QUERY_VALUE") if defined?(Win32::Registry::KEY_QUERY_VALUE)
- end
-
- it "returns false early when not on windows" do
- allow(ChefUtils).to receive(:windows?).and_return(false)
- expect(Chef::Platform).to_not receive(:require)
- expect(Chef::Platform.supports_msi?).to be false
- end
-
- it "returns true when the registry key exists" do
- allow(ChefUtils).to receive(:windows?).and_return(true)
- allow(Chef::Platform).to receive(:require).with("win32/registry")
- expect(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open)
- .with(key, access)
- .and_yield(registry)
- expect(Chef::Platform.supports_msi?).to be true
- end
-
- it "returns false when the registry key does not exist" do
- allow(ChefUtils).to receive(:windows?).and_return(true)
- allow(Chef::Platform).to receive(:require).with("win32/registry")
- expect(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open)
- .with(key, access)
- .and_raise(Win32::Registry::Error, "The system cannot find the file specified.")
- expect(Chef::Platform.supports_msi?).to be false
- end
-end
-
-describe "Chef::Platform#supports_dsc?" do
- it "returns false if PowerShell is not present" do
- node = Chef::Node.new
- expect(Chef::Platform.supports_dsc?(node)).to be_falsey
- end
-
- ["1.0", "2.0", "3.0"].each do |version|
- it "returns false for PowerShell #{version}" do
- node = Chef::Node.new
- node.automatic[:languages][:powershell][:version] = version
- expect(Chef::Platform.supports_dsc?(node)).to be_falsey
- end
- end
-
- ["4.0", "5.0"].each do |version|
- it "returns true for PowerShell #{version}" do
- node = Chef::Node.new
- node.automatic[:languages][:powershell][:version] = version
- expect(Chef::Platform.supports_dsc?(node)).to be_truthy
- end
- end
-end
-
describe "Chef::Platform#supports_dsc_invoke_resource?" do
it "returns false if powershell is not present" do
node = Chef::Node.new
diff --git a/spec/unit/provider/directory_spec.rb b/spec/unit/provider/directory_spec.rb
index 4672db7d8d..995b35bfa0 100644
--- a/spec/unit/provider/directory_spec.rb
+++ b/spec/unit/provider/directory_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Adam Jacob (<adam@chef.io>)
-# Copyright:: Copyright 2008-2016, Chef Software Inc.
+# Copyright:: Copyright 2008-2020, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -201,33 +201,22 @@ describe Chef::Provider::Directory do
end
end
- describe "on OS X" do
+ describe "on macOS" do
before do
- allow(node).to receive(:[]).with("platform").and_return("mac_os_x")
+ allow(ChefUtils).to receive(:macos?).and_return(true)
new_resource.path "/usr/bin/chef_test"
new_resource.recursive false
allow_any_instance_of(Chef::Provider::File).to receive(:do_selinux)
end
- it "os x 10.10 can write to sip locations" do
- allow(node).to receive(:[]).with("platform_version").and_return("10.10")
- allow(Dir).to receive(:mkdir).and_return([true], [])
- allow(::File).to receive(:directory?).and_return(true)
- allow(Chef::FileAccessControl).to receive(:writable?).and_return(true)
- directory.run_action(:create)
- expect(new_resource).to be_updated
- end
-
- it "os x 10.11 cannot write to sip locations" do
- allow(node).to receive(:[]).with("platform_version").and_return("10.11")
+ it "macOS cannot write to sip locations" do
allow(::File).to receive(:directory?).and_return(true)
allow(Chef::FileAccessControl).to receive(:writable?).and_return(false)
expect { directory.run_action(:create) }.to raise_error(Chef::Exceptions::InsufficientPermissions)
end
- it "os x 10.11 can write to sip exlcusions" do
+ it "macOS can write to sip exclusions" do
new_resource.path "/usr/local/chef_test"
- allow(node).to receive(:[]).with("platform_version").and_return("10.11")
allow(::File).to receive(:directory?).and_return(true)
allow(Dir).to receive(:mkdir).and_return([true], [])
allow(Chef::FileAccessControl).to receive(:writable?).and_return(false)
diff --git a/spec/unit/provider/powershell_script_spec.rb b/spec/unit/provider/powershell_script_spec.rb
index cca0f34067..43af9cee2c 100644
--- a/spec/unit/provider/powershell_script_spec.rb
+++ b/spec/unit/provider/powershell_script_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Adam Edwards (<adamed@chef.io>)
-# Copyright:: Copyright 2013-2017, Chef Software Inc.
+# Copyright:: Copyright 2013-2020, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -53,73 +53,33 @@ describe Chef::Provider::PowershellScript, "action_run" do
end
context "when setting interpreter flags" do
- context "on nano" do
- before(:each) do
- allow(Chef::Platform).to receive(:windows_nano_server?).and_return(true)
- allow(provider).to receive(:is_forced_32bit).and_return(false)
- os_info_double = double("os_info")
- allow(provider.run_context.node["kernel"]).to receive(:[]).with("os_info").and_return(os_info_double)
- allow(os_info_double).to receive(:[]).with("system_directory").and_return("C:\\Windows\\system32")
- end
-
- it "sets the -Command flag as the last flag" do
- flags = provider.command.split(" ").keep_if { |flag| flag =~ /^-/ }
- expect(flags.pop).to eq("-Command")
- end
+ before(:each) do
+ allow(provider).to receive(:is_forced_32bit).and_return(false)
+ os_info_double = double("os_info")
+ allow(provider.run_context.node["kernel"]).to receive(:[]).with("os_info").and_return(os_info_double)
+ allow(os_info_double).to receive(:[]).with("system_directory").and_return("C:\\Windows\\system32")
end
- context "not on nano" do
- before(:each) do
- allow(Chef::Platform).to receive(:windows_nano_server?).and_return(false)
- allow(provider).to receive(:is_forced_32bit).and_return(false)
- os_info_double = double("os_info")
- allow(provider.run_context.node["kernel"]).to receive(:[]).with("os_info").and_return(os_info_double)
- allow(os_info_double).to receive(:[]).with("system_directory").and_return("C:\\Windows\\system32")
- end
-
- it "sets the -File flag as the last flag" do
- flags = provider.command.split(" ").keep_if { |flag| flag =~ /^-/ }
- expect(flags.pop).to eq("-File")
- end
-
- let(:execution_policy_flag) do
- provider_flags = provider.flags.split(" ")
- # Last occurance of "executionpolicy"
- execution_policy_index = provider_flags.map(&:downcase).rindex("-executionpolicy")
+ it "sets the -File flag as the last flag" do
+ flags = provider.command.split(" ").keep_if { |flag| flag =~ /^-/ }
+ expect(flags.pop).to eq("-File")
+ end
- execution_policy_index ? provider_flags[execution_policy_index + 1] : nil
- end
+ let(:execution_policy_flag) do
+ provider_flags = provider.flags.split(" ")
+ # Last occurance of "executionpolicy"
+ execution_policy_index = provider_flags.map(&:downcase).rindex("-executionpolicy")
- context "when running with an unspecified PowerShell version" do
- let(:powershell_version) { nil }
- it "sets default -ExecutionPolicy flag to 'Unrestricted'" do
- expect(execution_policy_flag.downcase).to eq("unrestricted".downcase)
- end
- it "sets user defined -ExecutionPolicy flag to 'RemoteSigned'" do
- set_user_defined_flag
- expect(execution_policy_flag.downcase).to eq("RemoteSigned".downcase)
- end
- end
+ execution_policy_index ? provider_flags[execution_policy_index + 1] : nil
+ end
- { "2.0" => "Unrestricted",
- "2.5" => "Unrestricted",
- "3.0" => "Bypass",
- "3.6" => "Bypass",
- "4.0" => "Bypass",
- "5.0" => "Bypass" }.each do |version_policy|
- let(:powershell_version) { version_policy[0].to_f }
- context "when running PowerShell version #{version_policy[0]}" do
- let(:powershell_version) { version_policy[0].to_f }
+ it "sets default -ExecutionPolicy flag to 'Bypass'" do
+ expect(execution_policy_flag).to eq("Bypass")
+ end
- it "sets default -ExecutionPolicy flag to '#{version_policy[1]}'" do
- expect(execution_policy_flag.downcase).to eq(version_policy[1].downcase)
- end
- it "sets user defined -ExecutionPolicy flag to 'RemoteSigned'" do
- set_user_defined_flag
- expect(execution_policy_flag.downcase).to eq("RemoteSigned".downcase)
- end
- end
- end
+ it "sets user defined -ExecutionPolicy flag to 'RemoteSigned'" do
+ set_user_defined_flag
+ expect(execution_policy_flag).to eq("RemoteSigned")
end
end
end
diff --git a/spec/unit/provider/service/macosx_spec.rb b/spec/unit/provider/service/macosx_spec.rb
index 420fd329f6..9327d07cdd 100644
--- a/spec/unit/provider/service/macosx_spec.rb
+++ b/spec/unit/provider/service/macosx_spec.rb
@@ -1,6 +1,7 @@
#
# Author:: Igor Afonov <afonov@gmail.com>
# Copyright:: Copyright 2011-2016, Igor Afonov
+# Copyright:: Copyright 2020, Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -61,276 +62,271 @@ describe Chef::Provider::Service::Macosx do
%w{Daemon Agent}.each do |service_type|
["redis-server", "io.redis.redis-server"].each do |service_name|
- ["10.9", "10.10", "10.11"].each do |platform_version|
- let(:plist) { "/Library/LaunchDaemons/io.redis.redis-server.plist" }
- let(:session) { StringIO.new }
- if service_type == "Agent"
- let(:plist) { "/Library/LaunchAgents/io.redis.redis-server.plist" }
- let(:session) { "-S Aqua " }
- let(:su_cmd) { "su -l igor -c" }
- if platform_version == "10.9"
- let(:su_cmd) { "su igor -c" }
- end
- end
- let(:service_label) { "io.redis.redis-server" }
- before do
- allow(run_context).to receive(:logger).and_return(logger)
- allow(Dir).to receive(:glob).and_return([plist], [])
- @stat = double("File::Stat", { uid: 501 })
- allow(File).to receive(:stat).and_return(@stat)
- @getpwuid = double("Etc::Passwd", { name: "mikedodge04" })
- allow(Etc).to receive(:getpwuid).and_return(@getpwuid)
- allow(node).to receive(:[]).with("platform_version").and_return(platform_version)
- cmd = "launchctl list #{service_label}"
- allow(provider).to receive(:shell_out)
- .with(/(#{su_cmd} '#{cmd}'|#{cmd})/, default_env: false)
- .and_return(double("Status",
- stdout: launchctl_stdout, exitstatus: 0))
- allow(File).to receive(:exists?).and_return([true], [])
- allow(provider).to receive(:shell_out!)
- .with(/plutil -convert xml1 -o/, default_env: false)
- .and_return(double("Status", stdout: plutil_stdout))
- end
+ let(:plist) { "/Library/LaunchDaemons/io.redis.redis-server.plist" }
+ let(:session) { StringIO.new }
+ if service_type == "Agent"
+ let(:plist) { "/Library/LaunchAgents/io.redis.redis-server.plist" }
+ let(:session) { "-S Aqua " }
+ let(:su_cmd) { "su -l igor -c" }
+ end
+ let(:service_label) { "io.redis.redis-server" }
+ before do
+ allow(run_context).to receive(:logger).and_return(logger)
+ allow(Dir).to receive(:glob).and_return([plist], [])
+ @stat = double("File::Stat", { uid: 501 })
+ allow(File).to receive(:stat).and_return(@stat)
+ @getpwuid = double("Etc::Passwd", { name: "mikedodge04" })
+ allow(Etc).to receive(:getpwuid).and_return(@getpwuid)
+ allow(node).to receive(:[]).with("platform_version").and_return("10.11.1")
+ cmd = "launchctl list #{service_label}"
+ allow(provider).to receive(:shell_out)
+ .with(/(#{su_cmd} '#{cmd}'|#{cmd})/, default_env: false)
+ .and_return(double("Status",
+ stdout: launchctl_stdout, exitstatus: 0))
+ allow(File).to receive(:exists?).and_return([true], [])
+ allow(provider).to receive(:shell_out!)
+ .with(/plutil -convert xml1 -o/, default_env: false)
+ .and_return(double("Status", stdout: plutil_stdout))
+ end
- context "#{service_name} that is a #{service_type} running Osx #{platform_version}" do
- let(:new_resource) { Chef::Resource::MacosxService.new(service_name) }
- let!(:current_resource) { Chef::Resource::MacosxService.new(service_name) }
+ context "#{service_name} that is a #{service_type}" do
+ let(:new_resource) { Chef::Resource::MacosxService.new(service_name) }
+ let!(:current_resource) { Chef::Resource::MacosxService.new(service_name) }
- describe "#load_current_resource" do
+ describe "#load_current_resource" do
- # CHEF-5223 "you can't glob for a file that hasn't been converged
- # onto the node yet."
- context "when the plist doesn't exist" do
+ # CHEF-5223 "you can't glob for a file that hasn't been converged
+ # onto the node yet."
+ context "when the plist doesn't exist" do
- def run_resource_setup_for_action(action)
- new_resource.action(action)
- provider.action = action
- provider.load_current_resource
- provider.define_resource_requirements
- provider.process_resource_requirements
- end
+ def run_resource_setup_for_action(action)
+ new_resource.action(action)
+ provider.action = action
+ provider.load_current_resource
+ provider.define_resource_requirements
+ provider.process_resource_requirements
+ end
- before do
- allow(Dir).to receive(:glob).and_return([])
- allow(File).to receive(:exists?).and_return([true], [])
- allow(provider).to receive(:shell_out!)
- .with(/plutil -convert xml1 -o/)
- .and_raise(Mixlib::ShellOut::ShellCommandFailed)
- end
+ before do
+ allow(Dir).to receive(:glob).and_return([])
+ allow(File).to receive(:exists?).and_return([true], [])
+ allow(provider).to receive(:shell_out!)
+ .with(/plutil -convert xml1 -o/)
+ .and_raise(Mixlib::ShellOut::ShellCommandFailed)
+ end
- it "works for action :nothing" do
- expect { run_resource_setup_for_action(:nothing) }.not_to raise_error
- end
+ it "works for action :nothing" do
+ expect { run_resource_setup_for_action(:nothing) }.not_to raise_error
+ end
- it "works for action :start" do
- expect { run_resource_setup_for_action(:start) }.not_to raise_error
- end
+ it "works for action :start" do
+ expect { run_resource_setup_for_action(:start) }.not_to raise_error
+ end
- it "errors if action is :enable" do
- expect { run_resource_setup_for_action(:enable) }.to raise_error(Chef::Exceptions::Service)
- end
+ it "errors if action is :enable" do
+ expect { run_resource_setup_for_action(:enable) }.to raise_error(Chef::Exceptions::Service)
+ end
- it "errors if action is :disable" do
- expect { run_resource_setup_for_action(:disable) }.to raise_error(Chef::Exceptions::Service)
- end
+ it "errors if action is :disable" do
+ expect { run_resource_setup_for_action(:disable) }.to raise_error(Chef::Exceptions::Service)
end
+ end
- context "when launchctl returns pid in service list" do
- let(:launchctl_stdout) { StringIO.new <<~SVC_LIST }
- {
- "LimitLoadToSessionType" = "System";
- "Label" = "io.redis.redis-server";
- "TimeOut" = 30;
- "OnDemand" = false;
- "LastExitStatus" = 0;
- "PID" = 62803;
- "Program" = "do_some.sh";
- "ProgramArguments" = (
- "path/to/do_something.sh";
- "-f";
- );
- };
- SVC_LIST
+ context "when launchctl returns pid in service list" do
+ let(:launchctl_stdout) { StringIO.new <<~SVC_LIST }
+ {
+ "LimitLoadToSessionType" = "System";
+ "Label" = "io.redis.redis-server";
+ "TimeOut" = 30;
+ "OnDemand" = false;
+ "LastExitStatus" = 0;
+ "PID" = 62803;
+ "Program" = "do_some.sh";
+ "ProgramArguments" = (
+ "path/to/do_something.sh";
+ "-f";
+ );
+ };
+ SVC_LIST
- before do
- provider.load_current_resource
- end
+ before do
+ provider.load_current_resource
+ end
- it "sets resource running state to true" do
- expect(provider.current_resource.running).to be_truthy
- end
+ it "sets resource running state to true" do
+ expect(provider.current_resource.running).to be_truthy
+ end
- it "sets resouce enabled state to true" do
- expect(provider.current_resource.enabled).to be_truthy
- end
+ it "sets resouce enabled state to true" do
+ expect(provider.current_resource.enabled).to be_truthy
end
+ end
- describe "running unsupported actions" do
- before do
- allow(Dir).to receive(:glob).and_return([(plist).to_s], [])
- allow(File).to receive(:exists?).and_return([true], [])
- end
- it "should throw an exception when reload action is attempted" do
- expect { provider.run_action(:reload) }.to raise_error(Chef::Exceptions::UnsupportedAction)
- end
+ describe "running unsupported actions" do
+ before do
+ allow(Dir).to receive(:glob).and_return([(plist).to_s], [])
+ allow(File).to receive(:exists?).and_return([true], [])
end
- context "when launchctl returns empty service pid" do
- let(:launchctl_stdout) { StringIO.new <<~SVC_LIST }
- {
- "LimitLoadToSessionType" = "System";
- "Label" = "io.redis.redis-server";
- "TimeOut" = 30;
- "OnDemand" = false;
- "LastExitStatus" = 0;
- "Program" = "do_some.sh";
- "ProgramArguments" = (
- "path/to/do_something.sh";
- "-f";
- );
- };
- SVC_LIST
+ it "should throw an exception when reload action is attempted" do
+ expect { provider.run_action(:reload) }.to raise_error(Chef::Exceptions::UnsupportedAction)
+ end
+ end
+ context "when launchctl returns empty service pid" do
+ let(:launchctl_stdout) { StringIO.new <<~SVC_LIST }
+ {
+ "LimitLoadToSessionType" = "System";
+ "Label" = "io.redis.redis-server";
+ "TimeOut" = 30;
+ "OnDemand" = false;
+ "LastExitStatus" = 0;
+ "Program" = "do_some.sh";
+ "ProgramArguments" = (
+ "path/to/do_something.sh";
+ "-f";
+ );
+ };
+ SVC_LIST
- before do
- provider.load_current_resource
- end
+ before do
+ provider.load_current_resource
+ end
- it "sets resource running state to false" do
- expect(provider.current_resource.running).to be_falsey
- end
+ it "sets resource running state to false" do
+ expect(provider.current_resource.running).to be_falsey
+ end
- it "sets resouce enabled state to true" do
- expect(provider.current_resource.enabled).to be_truthy
- end
+ it "sets resouce enabled state to true" do
+ expect(provider.current_resource.enabled).to be_truthy
end
+ end
- context "when launchctl doesn't return service entry at all" do
- let(:launchctl_stdout) { StringIO.new <<~SVC_LIST }
- Could not find service "io.redis.redis-server" in domain for system
- SVC_LIST
+ context "when launchctl doesn't return service entry at all" do
+ let(:launchctl_stdout) { StringIO.new <<~SVC_LIST }
+ Could not find service "io.redis.redis-server" in domain for system
+ SVC_LIST
- it "sets service running state to false" do
+ it "sets service running state to false" do
+ provider.load_current_resource
+ expect(provider.current_resource.running).to be_falsey
+ end
+
+ context "and plist for service is not available" do
+ before do
+ allow(Dir).to receive(:glob).and_return([])
provider.load_current_resource
- expect(provider.current_resource.running).to be_falsey
end
- context "and plist for service is not available" do
- before do
- allow(Dir).to receive(:glob).and_return([])
- provider.load_current_resource
- end
-
- it "sets resouce enabled state to false" do
- expect(provider.current_resource.enabled).to be_falsey
- end
+ it "sets resouce enabled state to false" do
+ expect(provider.current_resource.enabled).to be_falsey
end
+ end
- context "and plist for service is available" do
- before do
- allow(Dir).to receive(:glob).and_return([(plist).to_s], [])
- provider.load_current_resource
- end
+ context "and plist for service is available" do
+ before do
+ allow(Dir).to receive(:glob).and_return([(plist).to_s], [])
+ provider.load_current_resource
+ end
- it "sets resouce enabled state to true" do
- expect(provider.current_resource.enabled).to be_truthy
- end
+ it "sets resouce enabled state to true" do
+ expect(provider.current_resource.enabled).to be_truthy
end
+ end
- describe "and several plists match service name" do
- it "throws exception" do
- allow(Dir).to receive(:glob).and_return([(plist).to_s,
- "/Users/wtf/something.plist"])
- provider.load_current_resource
- provider.define_resource_requirements
- expect { provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service)
- end
+ describe "and several plists match service name" do
+ it "throws exception" do
+ allow(Dir).to receive(:glob).and_return([(plist).to_s,
+ "/Users/wtf/something.plist"])
+ provider.load_current_resource
+ provider.define_resource_requirements
+ expect { provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service)
end
end
end
- describe "#start_service" do
- before do
- allow(Chef::Resource::MacosxService).to receive(:new).and_return(current_resource)
- provider.load_current_resource
- allow(current_resource).to receive(:running).and_return(false)
- end
+ end
+ describe "#start_service" do
+ before do
+ allow(Chef::Resource::MacosxService).to receive(:new).and_return(current_resource)
+ provider.load_current_resource
+ allow(current_resource).to receive(:running).and_return(false)
+ end
- it "calls the start command if one is specified and service is not running" do
- allow(new_resource).to receive(:start_command).and_return("cowsay dirty")
+ it "calls the start command if one is specified and service is not running" do
+ allow(new_resource).to receive(:start_command).and_return("cowsay dirty")
- expect(provider).to receive(:shell_out!).with("cowsay dirty", default_env: false)
- provider.start_service
- end
+ expect(provider).to receive(:shell_out!).with("cowsay dirty", default_env: false)
+ provider.start_service
+ end
- it "shows warning message if service is already running" do
- allow(current_resource).to receive(:running).and_return(true)
- expect(logger).to receive(:trace).with("macosx_service[#{service_name}] already running, not starting")
+ it "shows warning message if service is already running" do
+ allow(current_resource).to receive(:running).and_return(true)
+ expect(logger).to receive(:trace).with("macosx_service[#{service_name}] already running, not starting")
- provider.start_service
- end
+ provider.start_service
+ end
- it "starts service via launchctl if service found" do
- cmd = "launchctl load -w " + session + plist
- expect(provider).to receive(:shell_out)
- .with(/(#{su_cmd} .#{cmd}.|#{cmd})/, default_env: false)
- .and_return(0)
+ it "starts service via launchctl if service found" do
+ cmd = "launchctl load -w " + session + plist
+ expect(provider).to receive(:shell_out)
+ .with(/(#{su_cmd} .#{cmd}.|#{cmd})/, default_env: false)
+ .and_return(0)
- provider.start_service
- end
+ provider.start_service
end
+ end
- describe "#stop_service" do
- before do
- allow(Chef::Resource::MacosxService).to receive(:new).and_return(current_resource)
+ describe "#stop_service" do
+ before do
+ allow(Chef::Resource::MacosxService).to receive(:new).and_return(current_resource)
- provider.load_current_resource
- allow(current_resource).to receive(:running).and_return(true)
- end
+ provider.load_current_resource
+ allow(current_resource).to receive(:running).and_return(true)
+ end
- it "calls the stop command if one is specified and service is running" do
- allow(new_resource).to receive(:stop_command).and_return("kill -9 123")
+ it "calls the stop command if one is specified and service is running" do
+ allow(new_resource).to receive(:stop_command).and_return("kill -9 123")
- expect(provider).to receive(:shell_out!).with("kill -9 123", default_env: false)
- provider.stop_service
- end
+ expect(provider).to receive(:shell_out!).with("kill -9 123", default_env: false)
+ provider.stop_service
+ end
- it "shows warning message if service is not running" do
- allow(current_resource).to receive(:running).and_return(false)
- expect(logger).to receive(:trace).with("macosx_service[#{service_name}] not running, not stopping")
+ it "shows warning message if service is not running" do
+ allow(current_resource).to receive(:running).and_return(false)
+ expect(logger).to receive(:trace).with("macosx_service[#{service_name}] not running, not stopping")
- provider.stop_service
- end
+ provider.stop_service
+ end
- it "stops the service via launchctl if service found" do
- cmd = "launchctl unload -w " + plist
- expect(provider).to receive(:shell_out)
- .with(/(#{su_cmd} .#{cmd}.|#{cmd})/, default_env: false)
- .and_return(0)
+ it "stops the service via launchctl if service found" do
+ cmd = "launchctl unload -w " + plist
+ expect(provider).to receive(:shell_out)
+ .with(/(#{su_cmd} .#{cmd}.|#{cmd})/, default_env: false)
+ .and_return(0)
- provider.stop_service
- end
+ provider.stop_service
end
+ end
- describe "#restart_service" do
- before do
- allow(Chef::Resource::Service).to receive(:new).and_return(current_resource)
+ describe "#restart_service" do
+ before do
+ allow(Chef::Resource::Service).to receive(:new).and_return(current_resource)
- provider.load_current_resource
- allow(current_resource).to receive(:running).and_return(true)
- allow(provider).to receive(:sleep)
- end
+ provider.load_current_resource
+ allow(current_resource).to receive(:running).and_return(true)
+ allow(provider).to receive(:sleep)
+ end
- it "issues a command if given" do
- allow(new_resource).to receive(:restart_command).and_return("reload that thing")
+ it "issues a command if given" do
+ allow(new_resource).to receive(:restart_command).and_return("reload that thing")
- expect(provider).to receive(:shell_out!).with("reload that thing", default_env: false)
- provider.restart_service
- end
+ expect(provider).to receive(:shell_out!).with("reload that thing", default_env: false)
+ provider.restart_service
+ end
- it "stops and then starts service" do
- expect(provider).to receive(:unload_service)
- expect(provider).to receive(:load_service)
+ it "stops and then starts service" do
+ expect(provider).to receive(:unload_service)
+ expect(provider).to receive(:load_service)
- provider.restart_service
- end
+ provider.restart_service
end
end
end
diff --git a/spec/unit/resource/powershell_script_spec.rb b/spec/unit/resource/powershell_script_spec.rb
index 5566f32725..ce6b8ecea4 100644
--- a/spec/unit/resource/powershell_script_spec.rb
+++ b/spec/unit/resource/powershell_script_spec.rb
@@ -47,11 +47,6 @@ describe Chef::Resource::PowershellScript do
expect(@resource.convert_boolean_return).to eq(false)
end
- it "raises an error when architecture is i386 on Windows Nano Server" do
- allow(Chef::Platform).to receive(:windows_nano_server?).and_return(true)
- expect { @resource.architecture(:i386) }.to raise_error(Chef::Exceptions::Win32ArchitectureIncorrect, "cannot execute script with requested architecture 'i386' on Windows Nano Server")
- end
-
context "when using guards" do
let(:resource) { @resource }
before(:each) do