summaryrefslogtreecommitdiff
path: root/spec/unit
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit')
-rw-r--r--spec/unit/audit/audit_event_proxy_spec.rb2
-rw-r--r--spec/unit/audit/audit_reporter_spec.rb26
-rw-r--r--spec/unit/cookbook/metadata_spec.rb2
-rw-r--r--spec/unit/http/validate_content_length_spec.rb10
-rw-r--r--spec/unit/knife/bootstrap_spec.rb2
-rw-r--r--spec/unit/lwrp_spec.rb8
-rw-r--r--spec/unit/property_spec.rb24
-rw-r--r--spec/unit/provider/cookbook_file_spec.rb3
-rw-r--r--spec/unit/provider/cron/unix_spec.rb11
-rw-r--r--spec/unit/provider/cron_spec.rb59
-rw-r--r--spec/unit/provider/file_spec.rb3
-rw-r--r--spec/unit/provider/group/dscl_spec.rb15
-rw-r--r--spec/unit/provider/group/gpasswd_spec.rb7
-rw-r--r--spec/unit/provider/group/groupmod_spec.rb9
-rw-r--r--spec/unit/provider/group/pw_spec.rb7
-rw-r--r--spec/unit/provider/link_spec.rb8
-rw-r--r--spec/unit/provider/log_spec.rb31
-rw-r--r--spec/unit/provider/package/apt_spec.rb6
-rw-r--r--spec/unit/provider/package/bff_spec.rb4
-rw-r--r--spec/unit/provider/package/homebrew_spec.rb3
-rw-r--r--spec/unit/provider/package/rubygems_spec.rb2
-rw-r--r--spec/unit/provider/package_spec.rb15
-rw-r--r--spec/unit/provider/registry_key_spec.rb8
-rw-r--r--spec/unit/provider/remote_file_spec.rb3
-rw-r--r--spec/unit/provider/service/macosx_spec.rb6
-rw-r--r--spec/unit/provider/service/windows_spec.rb13
-rw-r--r--spec/unit/provider/template_spec.rb6
-rw-r--r--spec/unit/provider/user/windows_spec.rb3
-rw-r--r--spec/unit/provider/zypper_repository_spec.rb6
-rw-r--r--spec/unit/resource/openssl_rsa_private_key_spec.rb (renamed from spec/unit/resource/openssl_rsa_private_key.rb)0
-rw-r--r--spec/unit/resource/openssl_rsa_public_key_spec.rb (renamed from spec/unit/resource/openssl_rsa_public_key.rb)0
-rw-r--r--spec/unit/resource/sudo_spec.rb5
-rw-r--r--spec/unit/resource/swap_file_spec.rb40
-rw-r--r--spec/unit/resource/sysctl_spec.rb56
-rw-r--r--spec/unit/resource/windows_ad_join.rb45
-rw-r--r--spec/unit/resource/windows_feature_dism.rb14
-rw-r--r--spec/unit/resource/windows_feature_powershell.rb14
-rw-r--r--spec/unit/resource/windows_pagefile_spec.rb10
-rw-r--r--spec/unit/resource_reporter_spec.rb2
39 files changed, 361 insertions, 127 deletions
diff --git a/spec/unit/audit/audit_event_proxy_spec.rb b/spec/unit/audit/audit_event_proxy_spec.rb
index 820e670f1c..0e35343352 100644
--- a/spec/unit/audit/audit_event_proxy_spec.rb
+++ b/spec/unit/audit/audit_event_proxy_spec.rb
@@ -44,7 +44,7 @@ describe Chef::Audit::AuditEventProxy do
let(:parents) { [double("ExampleGroup")] }
it "notifies control_group_started event" do
- expect(Chef::Log).to receive(:debug).
+ expect(Chef::Log).to receive(:trace).
with("Entered \`control_group\` block named poots")
expect(events).to receive(:control_group_started).
with(description)
diff --git a/spec/unit/audit/audit_reporter_spec.rb b/spec/unit/audit/audit_reporter_spec.rb
index 5239364113..3edee46932 100644
--- a/spec/unit/audit/audit_reporter_spec.rb
+++ b/spec/unit/audit/audit_reporter_spec.rb
@@ -34,8 +34,8 @@ describe Chef::Audit::AuditReporter do
describe "#audit_phase_start" do
- it "notifies audit phase start to debug log" do
- expect(Chef::Log).to receive(:debug).with(/Audit Reporter starting/)
+ it "notifies audit phase start to trace log" do
+ expect(Chef::Log).to receive(:trace).with(/Audit Reporter starting/)
reporter.audit_phase_start(run_status)
end
@@ -126,8 +126,8 @@ EOM
let(:response) { double("response", :code => code) }
before do
- expect(Chef::Log).to receive(:debug).with(/Sending audit report/)
- expect(Chef::Log).to receive(:debug).with(/Audit Report/)
+ expect(Chef::Log).to receive(:trace).with(/Sending audit report/)
+ expect(Chef::Log).to receive(:trace).with(/Audit Report/)
allow(error).to receive(:response).and_return(response)
expect(error).to receive(:respond_to?).with(:response).and_return(true)
end
@@ -137,7 +137,7 @@ EOM
let(:code) { "404" }
it "logs that the server doesn't support audit reporting" do
- expect(Chef::Log).to receive(:debug).with(/Server doesn't support audit reporting/)
+ expect(Chef::Log).to receive(:trace).with(/Server doesn't support audit reporting/)
reporter.run_completed(node)
end
end
@@ -203,12 +203,12 @@ EOM
context "when auditing is not enabled" do
before do
- allow(Chef::Log).to receive(:debug)
+ allow(Chef::Log).to receive(:trace)
end
it "doesn't send reports" do
expect(reporter).to receive(:auditing_enabled?).and_return(false)
- expect(Chef::Log).to receive(:debug).with("Audit Reports are disabled. Skipping sending reports.")
+ expect(Chef::Log).to receive(:trace).with("Audit Reports are disabled. Skipping sending reports.")
reporter.run_completed(node)
end
@@ -217,13 +217,13 @@ EOM
context "when the run fails before audits" do
before do
- allow(Chef::Log).to receive(:debug)
+ allow(Chef::Log).to receive(:trace)
end
it "doesn't send reports" do
expect(reporter).to receive(:auditing_enabled?).and_return(true)
expect(reporter).to receive(:run_status).and_return(nil)
- expect(Chef::Log).to receive(:debug).with("Run failed before audit mode was initialized, not sending audit report to server")
+ expect(Chef::Log).to receive(:trace).with("Run failed before audit mode was initialized, not sending audit report to server")
reporter.run_completed(node)
end
@@ -313,8 +313,8 @@ EOM
describe "#audit_phase_complete" do
include_context "audit data"
- it "notifies audit phase finished to debug log" do
- expect(Chef::Log).to receive(:debug).with(/Audit Reporter completed/)
+ it "notifies audit phase finished to trace log" do
+ expect(Chef::Log).to receive(:trace).with(/Audit Reporter completed/)
reporter.audit_phase_complete("Output from audit mode")
end
@@ -331,8 +331,8 @@ EOM
let(:error) { double("Exception") }
- it "notifies audit phase failed to debug log" do
- expect(Chef::Log).to receive(:debug).with(/Audit Reporter failed/)
+ it "notifies audit phase failed to trace log" do
+ expect(Chef::Log).to receive(:trace).with(/Audit Reporter failed/)
reporter.audit_phase_failed(error, "Output from audit mode")
end
diff --git a/spec/unit/cookbook/metadata_spec.rb b/spec/unit/cookbook/metadata_spec.rb
index a91feec26d..a2cb35e60d 100644
--- a/spec/unit/cookbook/metadata_spec.rb
+++ b/spec/unit/cookbook/metadata_spec.rb
@@ -871,7 +871,7 @@ describe Chef::Cookbook::Metadata do
describe "from_file" do
it "ignores unknown metadata fields in metadata.rb files" do
- expect(Chef::Log).to receive(:debug).with(/ignoring method some_spiffy_new_metadata_field/)
+ expect(Chef::Log).to receive(:trace).with(/ignoring method some_spiffy_new_metadata_field/)
Tempfile.open("metadata.rb") do |f|
f.write <<-EOF
some_spiffy_new_metadata_field "stuff its set to"
diff --git a/spec/unit/http/validate_content_length_spec.rb b/spec/unit/http/validate_content_length_spec.rb
index 5067d36d38..1f24acb94a 100644
--- a/spec/unit/http/validate_content_length_spec.rb
+++ b/spec/unit/http/validate_content_length_spec.rb
@@ -85,8 +85,8 @@ describe Chef::HTTP::ValidateContentLength do
before(:each) do
@original_log_level = Chef::Log.level
- Chef::Log.level = :debug
- allow(Chef::Log).to receive(:debug) do |message|
+ Chef::Log.level = :trace
+ allow(Chef::Log).to receive(:trace) do |message|
debug_stream.puts message
end
end
@@ -111,7 +111,7 @@ describe Chef::HTTP::ValidateContentLength do
describe "when running #{req_type} request" do
let(:request_type) { req_type.to_sym }
- it "should skip validation and log for debug" do
+ it "should skip validation and log for trace" do
run_content_length_validation
expect(debug_output).to include("HTTP server did not include a Content-Length header in response")
end
@@ -126,7 +126,7 @@ describe Chef::HTTP::ValidateContentLength do
describe "when running #{req_type} request" do
let(:request_type) { req_type.to_sym }
- it "should skip validation and log for debug" do
+ it "should skip validation and log for trace" do
run_content_length_validation
expect(debug_output).to include("HTTP server responded with a negative Content-Length header (-1), cannot identify truncated downloads.")
end
@@ -180,7 +180,7 @@ describe Chef::HTTP::ValidateContentLength do
describe "when running #{req_type} request" do
let(:request_type) { req_type.to_sym }
- it "should skip validation and log for debug" do
+ it "should skip validation and log for trace" do
run_content_length_validation
expect(debug_output).to include("Transfer-Encoding header is set, skipping Content-Length check.")
end
diff --git a/spec/unit/knife/bootstrap_spec.rb b/spec/unit/knife/bootstrap_spec.rb
index 81c0b8a6cf..624261fb8b 100644
--- a/spec/unit/knife/bootstrap_spec.rb
+++ b/spec/unit/knife/bootstrap_spec.rb
@@ -118,7 +118,7 @@ describe Chef::Knife::Bootstrap do
let(:bootstrap_template) { File.expand_path(File.join(CHEF_SPEC_DATA, "bootstrap", "test.erb")) }
it "loads the given file as the template" do
- expect(Chef::Log).to receive(:debug)
+ expect(Chef::Log).to receive(:trace)
expect(knife.find_template).to eq(File.expand_path(File.join(CHEF_SPEC_DATA, "bootstrap", "test.erb")))
end
end
diff --git a/spec/unit/lwrp_spec.rb b/spec/unit/lwrp_spec.rb
index 009bc5f4b1..4423ccf64e 100644
--- a/spec/unit/lwrp_spec.rb
+++ b/spec/unit/lwrp_spec.rb
@@ -57,7 +57,7 @@ describe "LWRP" do
Object.const_set("LwrpFoo", Class.new)
file = File.expand_path( "lwrp/resources/foo.rb", CHEF_SPEC_DATA)
expect(Chef::Log).not_to receive(:info).with(/Skipping/)
- expect(Chef::Log).not_to receive(:debug).with(/anymore/)
+ expect(Chef::Log).not_to receive(:trace).with(/anymore/)
Chef::Resource::LWRPBase.build_from_file("lwrp", file, nil)
Object.send(:remove_const, "LwrpFoo")
end
@@ -66,7 +66,7 @@ describe "LWRP" do
Object.const_set("LwrpBuckPasser", Class.new)
file = File.expand_path( "lwrp/providers/buck_passer.rb", CHEF_SPEC_DATA)
expect(Chef::Log).not_to receive(:info).with(/Skipping/)
- expect(Chef::Log).not_to receive(:debug).with(/anymore/)
+ expect(Chef::Log).not_to receive(:trace).with(/anymore/)
Chef::Provider::LWRPBase.build_from_file("lwrp", file, nil)
Object.send(:remove_const, "LwrpBuckPasser")
end
@@ -81,7 +81,7 @@ describe "LWRP" do
end
Dir[File.expand_path( "lwrp/resources/*", CHEF_SPEC_DATA)].each do |file|
- expect(Chef::Log).to receive(:debug).with(/Skipping/)
+ expect(Chef::Log).to receive(:trace).with(/Skipping/)
Chef::Resource::LWRPBase.build_from_file("lwrp", file, nil)
end
end
@@ -92,7 +92,7 @@ describe "LWRP" do
end
Dir[File.expand_path( "lwrp/providers/*", CHEF_SPEC_DATA)].each do |file|
- expect(Chef::Log).to receive(:debug).with(/Skipping/)
+ expect(Chef::Log).to receive(:trace).with(/Skipping/)
Chef::Provider::LWRPBase.build_from_file("lwrp", file, nil)
end
end
diff --git a/spec/unit/property_spec.rb b/spec/unit/property_spec.rb
index 996585ab98..79c4baa89f 100644
--- a/spec/unit/property_spec.rb
+++ b/spec/unit/property_spec.rb
@@ -118,6 +118,19 @@ describe "Chef::Resource.property" do
end
end
+ context "deprecated properties" do
+ it "does not create a deprecation warning on definition" do
+ expect { resource_class.class_eval { property :x, String, deprecated: 10 } }.not_to raise_error Chef::Exceptions::DeprecatedFeatureError
+ end
+
+ with_property ":x, deprecated: 'a deprecated property'" do
+ it "deprecated properties emit a deprecation warning" do
+ expect(Chef).to receive(:deprecated).with(:property, "a deprecated property")
+ expect(resource.x 10).to eq 10
+ end
+ end
+ end
+
with_property ":x, name_property: true" do
context "and subclass" do
let(:subresource_class) do
@@ -1143,6 +1156,17 @@ describe "Chef::Resource.property" do
end
+ context "with aliased properties" do
+ with_property ":real, Integer" do
+ it "should set the real property and emit a deprecation message" do
+ expect(Chef).to receive(:deprecated).with(:property, "we don't like the deprecated property no more")
+ resource_class.class_eval { deprecated_property_alias :deprecated, :real, "we don't like the deprecated property no more" }
+ resource.deprecated 10
+ expect(resource.real).to eq 10
+ end
+ end
+ end
+
context "redefining Object methods" do
it "disallows redefining Object methods" do
expect { resource_class.class_eval { property :hash } }.to raise_error(ArgumentError)
diff --git a/spec/unit/provider/cookbook_file_spec.rb b/spec/unit/provider/cookbook_file_spec.rb
index f49cc7d3da..f27392de5d 100644
--- a/spec/unit/provider/cookbook_file_spec.rb
+++ b/spec/unit/provider/cookbook_file_spec.rb
@@ -25,7 +25,8 @@ require "support/shared/unit/provider/file"
describe Chef::Provider::CookbookFile do
let(:node) { double("Chef::Node") }
let(:events) { double("Chef::Events").as_null_object } # mock all the methods
- let(:run_context) { double("Chef::RunContext", :node => node, :events => events) }
+ let(:logger) { double("Mixlib::Log::Child").as_null_object }
+ let(:run_context) { double("Chef::RunContext", :node => node, :events => events, :logger => logger) }
let(:enclosing_directory) do
canonicalize_path(File.expand_path(File.join(CHEF_SPEC_DATA, "templates")))
end
diff --git a/spec/unit/provider/cron/unix_spec.rb b/spec/unit/provider/cron/unix_spec.rb
index 5e1fcb35ab..62b941c4aa 100644
--- a/spec/unit/provider/cron/unix_spec.rb
+++ b/spec/unit/provider/cron/unix_spec.rb
@@ -41,10 +41,15 @@ describe Chef::Provider::Cron::Unix do
let(:exitstatus) { 0 }
let(:shell_out) { double("Mixlib::ShellOut", :status => status, :stdout => stdout, :stderr => stderr) }
+ let(:logger) { double("Mixlib::Log::Child").as_null_object }
+
it "is a Chef::Provider:Cron" do
expect(provider).to be_a(Chef::Provider::Cron)
end
+ before do
+ allow(run_context).to receive(:logger).and_return(logger)
+ end
describe "read_crontab" do
let(:stderr) { "" }
let(:stdout) do
@@ -59,7 +64,7 @@ describe Chef::Provider::Cron::Unix do
end
before do
- allow(Chef::Log).to receive(:debug)
+ allow(logger).to receive(:trace)
allow(shell_out).to receive(:format_for_exception).and_return("formatted command output")
allow(provider).to receive(:shell_out).with("/usr/bin/crontab -l", :user => username).and_return(shell_out)
end
@@ -83,7 +88,7 @@ describe Chef::Provider::Cron::Unix do
it "logs the crontab output to debug" do
provider.send(:read_crontab)
- expect(Chef::Log).to have_received(:debug).with("formatted command output")
+ expect(logger).to have_received(:trace).with("formatted command output")
end
end
@@ -98,7 +103,7 @@ describe Chef::Provider::Cron::Unix do
it "logs the crontab output to debug" do
provider.send(:read_crontab) rescue nil
- expect(Chef::Log).to have_received(:debug).with("formatted command output")
+ expect(logger).to have_received(:trace).with("formatted command output")
end
end
end
diff --git a/spec/unit/provider/cron_spec.rb b/spec/unit/provider/cron_spec.rb
index ef629ebd52..5673ecc317 100644
--- a/spec/unit/provider/cron_spec.rb
+++ b/spec/unit/provider/cron_spec.rb
@@ -19,16 +19,23 @@
require "spec_helper"
describe Chef::Provider::Cron do
+ let(:logger) { double("Mixlib::Log::Child").as_null_object }
+
+ before do
+ @node = Chef::Node.new
+ @events = Chef::EventDispatch::Dispatcher.new
+ @run_context = Chef::RunContext.new(@node, {}, @events)
+ allow(@run_context).to receive(:logger).and_return(logger)
+
+ @new_resource = Chef::Resource::Cron.new("cronhole some stuff", @run_context)
+ @new_resource.user "root"
+ @new_resource.minute "30"
+ @new_resource.command "/bin/true"
+ @provider = Chef::Provider::Cron.new(@new_resource, @run_context)
+ end
+
describe "when with special time string" do
before do
- @node = Chef::Node.new
- @events = Chef::EventDispatch::Dispatcher.new
- @run_context = Chef::RunContext.new(@node, {}, @events)
-
- @new_resource = Chef::Resource::Cron.new("cronhole some stuff", @run_context)
- @new_resource.user "root"
- @new_resource.minute "30"
- @new_resource.command "/bin/true"
@new_resource.time :reboot
@provider = Chef::Provider::Cron.new(@new_resource, @run_context)
end
@@ -113,7 +120,7 @@ CRONTAB
end
it "should report the match" do
- expect(Chef::Log).to receive(:debug).with("Found cron '#{@new_resource.name}'")
+ expect(logger).to receive(:trace).with("Found cron '#{@new_resource.name}'")
@provider.load_current_resource
end
@@ -141,18 +148,6 @@ CRONTAB
end
end
- before do
- @node = Chef::Node.new
- @events = Chef::EventDispatch::Dispatcher.new
- @run_context = Chef::RunContext.new(@node, {}, @events)
-
- @new_resource = Chef::Resource::Cron.new("cronhole some stuff", @run_context)
- @new_resource.user "root"
- @new_resource.minute "30"
- @new_resource.command "/bin/true"
- @provider = Chef::Provider::Cron.new(@new_resource, @run_context)
- end
-
describe "when examining the current system state" do
context "with no crontab for the user" do
before :each do
@@ -166,7 +161,7 @@ CRONTAB
end
it "should report an empty crontab" do
- expect(Chef::Log).to receive(:debug).with("Cron empty for '#{@new_resource.user}'")
+ expect(logger).to receive(:trace).with("Cron empty for '#{@new_resource.user}'")
@provider.load_current_resource
end
end
@@ -190,7 +185,7 @@ CRONTAB
end
it "should report no entry found" do
- expect(Chef::Log).to receive(:debug).with("Cron '#{@new_resource.name}' not found")
+ expect(logger).to receive(:trace).with("Cron '#{@new_resource.name}' not found")
@provider.load_current_resource
end
@@ -296,7 +291,7 @@ CRONTAB
end
it "should report the match" do
- expect(Chef::Log).to receive(:debug).with("Found cron '#{@new_resource.name}'")
+ expect(logger).to receive(:trace).with("Found cron '#{@new_resource.name}'")
@provider.load_current_resource
end
end
@@ -332,7 +327,7 @@ CRONTAB
end
it "should report the match" do
- expect(Chef::Log).to receive(:debug).with("Found cron '#{@new_resource.name}'")
+ expect(logger).to receive(:trace).with("Found cron '#{@new_resource.name}'")
@provider.load_current_resource
end
end
@@ -478,7 +473,7 @@ TEST=LOL
end
it "should log the action" do
- expect(Chef::Log).to receive(:info).with("cron[cronhole some stuff] added crontab entry")
+ expect(logger).to receive(:info).with("cron[cronhole some stuff] added crontab entry")
@provider.run_action(:create)
end
end
@@ -540,7 +535,7 @@ TEST=LOL
end
it "should log the action" do
- expect(Chef::Log).to receive(:info).with("cron[cronhole some stuff] added crontab entry")
+ expect(logger).to receive(:info).with("cron[cronhole some stuff] added crontab entry")
@provider.run_action(:create)
end
end
@@ -605,7 +600,7 @@ TEST=LOL
end
it "should log the action" do
- expect(Chef::Log).to receive(:info).with("cron[cronhole some stuff] updated crontab entry")
+ expect(logger).to receive(:info).with("cron[cronhole some stuff] updated crontab entry")
@provider.run_action(:create)
end
end
@@ -719,8 +714,8 @@ CRONTAB
end
it "should log nothing changed" do
- expect(Chef::Log).to receive(:debug).with("Found cron '#{@new_resource.name}'")
- expect(Chef::Log).to receive(:debug).with("Skipping existing cron entry '#{@new_resource.name}'")
+ expect(logger).to receive(:trace).with("Found cron '#{@new_resource.name}'")
+ expect(logger).to receive(:trace).with("Skipping existing cron entry '#{@new_resource.name}'")
@provider.run_action(:create)
end
end
@@ -739,7 +734,7 @@ CRONTAB
it "should do nothing" do
expect(@provider).not_to receive(:write_crontab)
- expect(Chef::Log).not_to receive(:info)
+ expect(logger).not_to receive(:info)
@provider.run_action(:delete)
end
@@ -806,7 +801,7 @@ FOO=test
end
it "should log the action" do
- expect(Chef::Log).to receive(:info).with("#{@new_resource} deleted crontab entry")
+ expect(logger).to receive(:info).with("#{@new_resource} deleted crontab entry")
@provider.run_action(:delete)
end
end
diff --git a/spec/unit/provider/file_spec.rb b/spec/unit/provider/file_spec.rb
index d8d4ed2286..fed9cd5ece 100644
--- a/spec/unit/provider/file_spec.rb
+++ b/spec/unit/provider/file_spec.rb
@@ -34,7 +34,8 @@ describe Chef::Provider::File do
let(:node) { double("Chef::Node") }
let(:events) { double("Chef::Events").as_null_object } # mock all the methods
- let(:run_context) { double("Chef::RunContext", :node => node, :events => events) }
+ let(:logger) { double("Mixlib::Log::Child").as_null_object }
+ let(:run_context) { double("Chef::RunContext", :node => node, :events => events, :logger => logger) }
let(:enclosing_directory) do
canonicalize_path(File.expand_path(File.join(CHEF_SPEC_DATA, "templates")))
end
diff --git a/spec/unit/provider/group/dscl_spec.rb b/spec/unit/provider/group/dscl_spec.rb
index cf3f0237f5..6e40e41579 100644
--- a/spec/unit/provider/group/dscl_spec.rb
+++ b/spec/unit/provider/group/dscl_spec.rb
@@ -19,10 +19,13 @@
require "spec_helper"
describe Chef::Provider::Group::Dscl do
+ let(:logger) { double("Mixlib::Log::Child").as_null_object }
+
before do
@node = Chef::Node.new
@events = Chef::EventDispatch::Dispatcher.new
@run_context = Chef::RunContext.new(@node, {}, @events)
+ allow(@run_context).to receive(:logger).and_return(logger)
@new_resource = Chef::Resource::Group.new("aj")
@current_resource = Chef::Resource::Group.new("aj")
@provider = Chef::Provider::Group::Dscl.new(@new_resource, @run_context)
@@ -45,8 +48,7 @@ describe Chef::Provider::Group::Dscl do
describe "safe_dscl" do
before do
- @node = Chef::Node.new
- @provider = Chef::Provider::Group::Dscl.new(@node, @new_resource)
+ @provider = Chef::Provider::Group::Dscl.new(@new_resource, @run_context)
allow(@provider).to receive(:dscl).and_return(["cmd", @status, "stdout", "stderr"])
end
@@ -93,8 +95,7 @@ describe Chef::Provider::Group::Dscl do
describe "get_free_gid" do
before do
- @node = Chef::Node.new
- @provider = Chef::Provider::Group::Dscl.new(@node, @new_resource)
+ @provider = Chef::Provider::Group::Dscl.new(@new_resource, @run_context)
allow(@provider).to receive(:safe_dscl).and_return("\naj 200\njt 201\n")
end
@@ -115,8 +116,6 @@ describe Chef::Provider::Group::Dscl do
describe "gid_used?" do
before do
- @node = Chef::Node.new
- @provider = Chef::Provider::Group::Dscl.new(@node, @new_resource)
allow(@provider).to receive(:safe_dscl).and_return(<<-eos
someprogram somethingElse:gid = (
500
@@ -197,7 +196,7 @@ describe Chef::Provider::Group::Dscl do
end
it "should log an appropriate message" do
- expect(Chef::Log).to receive(:debug).with("group[aj] removing group members all your base")
+ expect(logger).to receive(:trace).with("group[aj] removing group members all your base")
@provider.set_members
end
@@ -215,7 +214,7 @@ describe Chef::Provider::Group::Dscl do
end
it "should log an appropriate debug message" do
- expect(Chef::Log).to receive(:debug).with("group[aj] setting group members all, your, base")
+ expect(logger).to receive(:trace).with("group[aj] setting group members all, your, base")
@provider.set_members
end
diff --git a/spec/unit/provider/group/gpasswd_spec.rb b/spec/unit/provider/group/gpasswd_spec.rb
index add87bf008..287951a1a9 100644
--- a/spec/unit/provider/group/gpasswd_spec.rb
+++ b/spec/unit/provider/group/gpasswd_spec.rb
@@ -19,10 +19,13 @@
require "spec_helper"
describe Chef::Provider::Group::Gpasswd, "modify_group_members" do
+ let(:logger) { double("Mixlib::Log::Child").as_null_object }
+
before do
@node = Chef::Node.new
@events = Chef::EventDispatch::Dispatcher.new
@run_context = Chef::RunContext.new(@node, {}, @events)
+ allow(@run_context).to receive(:logger).and_return(logger)
@new_resource = Chef::Resource::Group.new("wheel")
@new_resource.members %w{lobster rage fist}
@new_resource.append false
@@ -65,7 +68,7 @@ describe Chef::Provider::Group::Gpasswd, "modify_group_members" do
end
it "logs a message and sets group's members to 'none'" do
- expect(Chef::Log).to receive(:debug).with("group[wheel] setting group members to: none")
+ expect(logger).to receive(:trace).with("group[wheel] setting group members to: none")
expect(@provider).to receive(:shell_out!).with("gpasswd", "-M", "", "wheel")
@provider.modify_group_members
end
@@ -85,7 +88,7 @@ describe Chef::Provider::Group::Gpasswd, "modify_group_members" do
describe "when the resource specifies group members" do
it "should log an appropriate debug message" do
- expect(Chef::Log).to receive(:debug).with("group[wheel] setting group members to: lobster, rage, fist")
+ expect(logger).to receive(:trace).with("group[wheel] setting group members to: lobster, rage, fist")
allow(@provider).to receive(:shell_out!)
@provider.modify_group_members
end
diff --git a/spec/unit/provider/group/groupmod_spec.rb b/spec/unit/provider/group/groupmod_spec.rb
index 6629b718d0..3f36a5b8a6 100644
--- a/spec/unit/provider/group/groupmod_spec.rb
+++ b/spec/unit/provider/group/groupmod_spec.rb
@@ -19,10 +19,13 @@
require "spec_helper"
describe Chef::Provider::Group::Groupmod do
+ let(:logger) { double("Mixlib::Log::Child").as_null_object }
+
before do
@node = Chef::Node.new
@events = Chef::EventDispatch::Dispatcher.new
@run_context = Chef::RunContext.new(@node, {}, @events)
+ allow(@run_context).to receive(:logger).and_return(logger)
@new_resource = Chef::Resource::Group.new("wheel")
@new_resource.gid 123
@new_resource.members %w{lobster rage fist}
@@ -61,7 +64,7 @@ describe Chef::Provider::Group::Groupmod do
end
it "logs a message and sets group's members to 'none', then removes existing group members" do
- expect(Chef::Log).to receive(:debug).with("group[wheel] setting group members to: none")
+ expect(logger).to receive(:trace).with("group[wheel] setting group members to: none")
expect(@provider).to receive(:shell_out!).with("group", "mod", "-n", "wheel_bak", "wheel")
expect(@provider).to receive(:shell_out!).with("group", "add", "-g", "123", "-o", "wheel")
expect(@provider).to receive(:shell_out!).with("group", "del", "wheel_bak")
@@ -76,7 +79,7 @@ describe Chef::Provider::Group::Groupmod do
end
it "logs a message and does not modify group membership" do
- expect(Chef::Log).to receive(:debug).with("group[wheel] not changing group members, the group has no members to add")
+ expect(logger).to receive(:trace).with("group[wheel] not changing group members, the group has no members to add")
expect(@provider).not_to receive(:shell_out!)
@provider.manage_group
end
@@ -89,7 +92,7 @@ describe Chef::Provider::Group::Groupmod do
end
it "updates group membership correctly" do
- allow(Chef::Log).to receive(:debug)
+ allow(logger).to receive(:trace)
expect(@provider).to receive(:shell_out!).with("group", "mod", "-n", "wheel_bak", "wheel")
expect(@provider).to receive(:shell_out!).with("user", "mod", "-G", "wheel", "lobster")
expect(@provider).to receive(:shell_out!).with("group", "add", "-g", "123", "-o", "wheel")
diff --git a/spec/unit/provider/group/pw_spec.rb b/spec/unit/provider/group/pw_spec.rb
index ee9ceda8c2..736ba0671b 100644
--- a/spec/unit/provider/group/pw_spec.rb
+++ b/spec/unit/provider/group/pw_spec.rb
@@ -19,10 +19,13 @@
require "spec_helper"
describe Chef::Provider::Group::Pw do
+ let(:logger) { double("Mixlib::Log::Child").as_null_object }
+
before do
@node = Chef::Node.new
@events = Chef::EventDispatch::Dispatcher.new
@run_context = Chef::RunContext.new(@node, {}, @events)
+ allow(@run_context).to receive(:logger).and_return(logger)
@new_resource = Chef::Resource::Group.new("wheel")
@new_resource.gid 50
@@ -93,7 +96,7 @@ describe Chef::Provider::Group::Pw do
end
it "should log an appropriate message" do
- expect(Chef::Log).to receive(:debug).with("group[wheel] removing group members: all,your,base")
+ expect(logger).to receive(:trace).with("group[wheel] removing group members: all,your,base")
@provider.set_members_options
end
@@ -109,7 +112,7 @@ describe Chef::Provider::Group::Pw do
end
it "should log an appropriate debug message" do
- expect(Chef::Log).to receive(:debug).with("group[wheel] adding group members: all,your,base")
+ expect(logger).to receive(:trace).with("group[wheel] adding group members: all,your,base")
@provider.set_members_options
end
diff --git a/spec/unit/provider/link_spec.rb b/spec/unit/provider/link_spec.rb
index b233fac72b..10dbdc1766 100644
--- a/spec/unit/provider/link_spec.rb
+++ b/spec/unit/provider/link_spec.rb
@@ -26,10 +26,12 @@ if Chef::Platform.windows?
end
describe Chef::Resource::Link do
+ let(:logger) { double("Mixlib::Log::Child").as_null_object }
let(:provider) do
node = Chef::Node.new
@events = Chef::EventDispatch::Dispatcher.new
run_context = Chef::RunContext.new(node, {}, @events)
+ allow(run_context).to receive(:logger).and_return(logger)
Chef::Provider::Link.new(new_resource, run_context)
end
let(:new_resource) do
@@ -270,7 +272,7 @@ describe Chef::Resource::Link do
it "invokes Dir.delete method to delete the link" do
expect(::Dir).to receive(:delete).with(provider.new_resource.target_file)
- expect(Chef::Log).to receive(:info).with("#{provider.new_resource} deleted")
+ expect(logger).to receive(:info).with("#{provider.new_resource} deleted")
provider.run_action(:delete)
end
end
@@ -283,7 +285,7 @@ describe Chef::Resource::Link do
it "invokes File.delete method to delete the link" do
expect(::File).to receive(:delete).with(provider.new_resource.target_file)
- expect(Chef::Log).to receive(:info).with("#{provider.new_resource} deleted")
+ expect(logger).to receive(:info).with("#{provider.new_resource} deleted")
provider.run_action(:delete)
end
end
@@ -296,7 +298,7 @@ describe Chef::Resource::Link do
it "invokes File.delete method to delete the link" do
expect(::File).to receive(:delete).with(provider.new_resource.target_file)
- expect(Chef::Log).to receive(:info).with("#{provider.new_resource} deleted")
+ expect(logger).to receive(:info).with("#{provider.new_resource} deleted")
provider.run_action(:delete)
end
end
diff --git a/spec/unit/provider/log_spec.rb b/spec/unit/provider/log_spec.rb
index ce7b1af55a..deb2024640 100644
--- a/spec/unit/provider/log_spec.rb
+++ b/spec/unit/provider/log_spec.rb
@@ -32,44 +32,49 @@ describe Chef::Provider::Log::ChefLog do
let(:provider) { Chef::Provider::Log::ChefLog.new(new_resource, run_context) }
- it "should write the string to the Chef::Log object at default level (info)" do
- expect(Chef::Log).to receive(:info).with(log_str).and_return(true)
+ let(:logger) { double("Mixlib::Log::Child").as_null_object }
+ before do
+ allow(run_context).to receive(:logger).and_return(logger)
+ end
+
+ it "should write the string to the logger object at default level (info)" do
+ expect(logger).to receive(:info).with(log_str).and_return(true)
provider.run_action(:write)
end
- it "should write the string to the Chef::Log object at debug level" do
+ it "should write the string to the logger object at debug level" do
new_resource.level :debug
- expect(Chef::Log).to receive(:debug).with(log_str).and_return(true)
+ expect(logger).to receive(:debug).with(log_str).and_return(true)
provider.run_action(:write)
end
- it "should write the string to the Chef::Log object at info level" do
+ it "should write the string to the logger object at info level" do
new_resource.level :info
- expect(Chef::Log).to receive(:info).with(log_str).and_return(true)
+ expect(logger).to receive(:info).with(log_str).and_return(true)
provider.run_action(:write)
end
- it "should write the string to the Chef::Log object at warn level" do
+ it "should write the string to the logger object at warn level" do
new_resource.level :warn
- expect(Chef::Log).to receive(:warn).with(log_str).and_return(true)
+ expect(logger).to receive(:warn).with(log_str).and_return(true)
provider.run_action(:write)
end
- it "should write the string to the Chef::Log object at error level" do
+ it "should write the string to the logger object at error level" do
new_resource.level :error
- expect(Chef::Log).to receive(:error).with(log_str).and_return(true)
+ expect(logger).to receive(:error).with(log_str).and_return(true)
provider.run_action(:write)
end
- it "should write the string to the Chef::Log object at fatal level" do
+ it "should write the string to the logger object at fatal level" do
new_resource.level :fatal
- expect(Chef::Log).to receive(:fatal).with(log_str).and_return(true)
+ expect(logger).to receive(:fatal).with(log_str).and_return(true)
provider.run_action(:write)
end
it "should print the string in why-run mode" do
Chef::Config[:why_run] = true
- expect(Chef::Log).to receive(:info).with(log_str).and_return(true)
+ expect(logger).to receive(:info).with(log_str).and_return(true)
provider.run_action(:write)
end
diff --git a/spec/unit/provider/package/apt_spec.rb b/spec/unit/provider/package/apt_spec.rb
index b461a39673..78c517b9a0 100644
--- a/spec/unit/provider/package/apt_spec.rb
+++ b/spec/unit/provider/package/apt_spec.rb
@@ -20,6 +20,7 @@ require "spec_helper"
require "ostruct"
describe Chef::Provider::Package::Apt do
+ let(:logger) { double("Mixlib::Log::Child").as_null_object }
# XXX: sorry this is ugly and was done quickly to get 12.0.2 out, this file needs a rewrite to use
# let blocks and shared examples
@@ -27,6 +28,7 @@ describe Chef::Provider::Package::Apt do
@node = Chef::Node.new
@events = Chef::EventDispatch::Dispatcher.new
@run_context = Chef::RunContext.new(@node, {}, @events)
+ allow(@run_context).to receive(:logger).and_return(logger)
@new_resource = Chef::Resource::AptPackage.new("irssi", @run_context)
@status = double("Status", :exitstatus => 0)
@@ -418,7 +420,7 @@ mpg123 1.12.1-0ubuntu1
).and_return(instance_double(
Mixlib::ShellOut, stdout: "irssi")
)
- expect(Chef::Log).to receive(:debug).with("#{@provider.new_resource} is already locked")
+ expect(logger).to receive(:trace).with("#{@provider.new_resource} is already locked")
@provider.new_resource.package_name = ["irssi"]
@provider.action_lock
@@ -440,7 +442,7 @@ mpg123 1.12.1-0ubuntu1
).and_return(instance_double(
Mixlib::ShellOut, stdout: "")
)
- expect(Chef::Log).to receive(:debug).with("#{@provider.new_resource} is already unlocked")
+ expect(logger).to receive(:trace).with("#{@provider.new_resource} is already unlocked")
@provider.new_resource.package_name = ["irssi"]
@provider.action_unlock
diff --git a/spec/unit/provider/package/bff_spec.rb b/spec/unit/provider/package/bff_spec.rb
index 1018f2d3e9..abe1d4155c 100644
--- a/spec/unit/provider/package/bff_spec.rb
+++ b/spec/unit/provider/package/bff_spec.rb
@@ -19,10 +19,12 @@
require "spec_helper"
describe Chef::Provider::Package::Bff do
+ let(:logger) { double("Mixlib::Log::Child").as_null_object }
before(:each) do
@node = Chef::Node.new
@events = Chef::EventDispatch::Dispatcher.new
@run_context = Chef::RunContext.new(@node, {}, @events)
+ allow(@run_context).to receive(:logger).and_return(logger)
@new_resource = Chef::Resource::Package.new("samba.base")
@new_resource.source("/tmp/samba.base")
@@ -79,7 +81,7 @@ describe Chef::Provider::Package::Bff do
status = double("Status", :stdout => info, :exitstatus => 0)
expect(@provider).to receive(:shell_out).with("installp", "-L", "-d", "/tmp/samba.base", timeout: 900).and_return(status)
expect(@provider).to receive(:shell_out).with("lslpp", "-lcq", "samba.base", timeout: 900).and_return(@empty_status)
- expect(Chef::Log).to receive(:warn).once.with(%r{bff package by product name})
+ expect(logger).to receive(:warn).once.with(%r{bff package by product name})
@provider.load_current_resource
expect(@provider.current_resource.package_name).to eq("samba.base")
diff --git a/spec/unit/provider/package/homebrew_spec.rb b/spec/unit/provider/package/homebrew_spec.rb
index 572c54e83d..833fa7bd3e 100644
--- a/spec/unit/provider/package/homebrew_spec.rb
+++ b/spec/unit/provider/package/homebrew_spec.rb
@@ -20,7 +20,8 @@ require "spec_helper"
describe Chef::Provider::Package::Homebrew do
let(:node) { Chef::Node.new }
let(:events) { double("Chef::Events").as_null_object }
- let(:run_context) { double("Chef::RunContext", node: node, events: events) }
+ let(:logger) { double("Mixlib::Log::Child").as_null_object }
+ let(:run_context) { double("Chef::RunContext", node: node, events: events, logger: logger) }
let(:new_resource) { Chef::Resource::HomebrewPackage.new("emacs") }
let(:current_resource) { Chef::Resource::HomebrewPackage.new("emacs") }
diff --git a/spec/unit/provider/package/rubygems_spec.rb b/spec/unit/provider/package/rubygems_spec.rb
index 071cba23d8..28bd371539 100644
--- a/spec/unit/provider/package/rubygems_spec.rb
+++ b/spec/unit/provider/package/rubygems_spec.rb
@@ -33,8 +33,10 @@ require "ostruct"
describe Chef::Provider::Package::Rubygems::CurrentGemEnvironment do
include GemspecBackcompatCreator
+ let(:logger) { double("Mixlib::Log::Child").as_null_object }
before do
@gem_env = Chef::Provider::Package::Rubygems::CurrentGemEnvironment.new
+ allow(@gem_env).to receive(:logger).and_return(logger)
end
it "determines the gem paths from the in memory rubygems" do
diff --git a/spec/unit/provider/package_spec.rb b/spec/unit/provider/package_spec.rb
index 8333d5bd0d..da74c932a8 100644
--- a/spec/unit/provider/package_spec.rb
+++ b/spec/unit/provider/package_spec.rb
@@ -26,6 +26,7 @@ describe Chef::Provider::Package do
node
end
let(:events) { Chef::EventDispatch::Dispatcher.new }
+ let(:logger) { double("Mixlib::Log::Child").as_null_object }
let(:run_context) { Chef::RunContext.new(node, {}, events) }
let(:new_resource) { Chef::Resource::Package.new("install emacs") }
let(:current_resource) { Chef::Resource::Package.new("install emacs") }
@@ -39,6 +40,10 @@ describe Chef::Provider::Package do
provider
end
+ before do
+ allow(run_context).to receive(:logger).and_return(logger)
+ end
+
describe "when installing a package" do
before(:each) do
provider.current_resource = current_resource
@@ -166,7 +171,7 @@ describe Chef::Provider::Package do
it "should print the word 'uninstalled' if there was no original version" do
allow(current_resource).to receive(:version).and_return(nil)
- expect(Chef::Log).to receive(:info).with("package[install emacs] upgraded emacs to 1.0")
+ expect(logger).to receive(:info).with("package[install emacs] upgraded emacs to 1.0")
provider.run_action(:upgrade)
expect(new_resource).to be_updated_by_last_action
end
@@ -287,7 +292,7 @@ describe Chef::Provider::Package do
expect(provider).to receive(:get_preseed_file).and_return("/var/cache/preseed-test")
allow(provider).to receive(:preseed_package).and_return(true)
allow(provider).to receive(:reconfig_package).and_return(true)
- expect(Chef::Log).to receive(:info).with("package[install emacs] reconfigured")
+ expect(logger).to receive(:info).with("package[install emacs] reconfigured")
expect(provider).to receive(:reconfig_package)
provider.run_action(:reconfig)
expect(new_resource).to be_updated
@@ -296,7 +301,7 @@ describe Chef::Provider::Package do
it "should debug log and not reconfigure the package if the package is not installed" do
allow(current_resource).to receive(:version).and_return(nil)
- expect(Chef::Log).to receive(:debug).with("package[install emacs] is NOT installed - nothing to do")
+ expect(logger).to receive(:trace).with("package[install emacs] is NOT installed - nothing to do")
expect(provider).not_to receive(:reconfig_package)
provider.run_action(:reconfig)
expect(new_resource).not_to be_updated_by_last_action
@@ -305,7 +310,7 @@ describe Chef::Provider::Package do
it "should debug log and not reconfigure the package if no response_file is given" do
allow(current_resource).to receive(:version).and_return("1.0")
allow(new_resource).to receive(:response_file).and_return(nil)
- expect(Chef::Log).to receive(:debug).with("package[install emacs] no response_file provided - nothing to do")
+ expect(logger).to receive(:trace).with("package[install emacs] no response_file provided - nothing to do")
expect(provider).not_to receive(:reconfig_package)
provider.run_action(:reconfig)
expect(new_resource).not_to be_updated_by_last_action
@@ -316,7 +321,7 @@ describe Chef::Provider::Package do
allow(new_resource).to receive(:response_file).and_return(true)
expect(provider).to receive(:get_preseed_file).and_return(false)
allow(provider).to receive(:preseed_package).and_return(false)
- expect(Chef::Log).to receive(:debug).with("package[install emacs] preseeding has not changed - nothing to do")
+ expect(logger).to receive(:trace).with("package[install emacs] preseeding has not changed - nothing to do")
expect(provider).not_to receive(:reconfig_package)
provider.run_action(:reconfig)
expect(new_resource).not_to be_updated_by_last_action
diff --git a/spec/unit/provider/registry_key_spec.rb b/spec/unit/provider/registry_key_spec.rb
index 3fb9468f5d..096fe9b9ed 100644
--- a/spec/unit/provider/registry_key_spec.rb
+++ b/spec/unit/provider/registry_key_spec.rb
@@ -313,7 +313,13 @@ describe Chef::Provider::RegistryKey do
end
describe Chef::Provider::RegistryKey, "key_missing?" do
- let(:provider) { Chef::Provider::RegistryKey.new(nil, nil) }
+ let(:node) { Chef::Node.new }
+ let(:events) { double("Chef::Events").as_null_object }
+ let(:logger) { double("Mixlib::Log::Child").as_null_object }
+ let(:run_context) { double("Chef::RunContext", node: node, events: events, logger: logger) }
+ let(:new_resource) { Chef::Resource::RegistryKey.new("emacs") }
+ let(:provider) { Chef::Provider::RegistryKey.new(new_resource, run_context) }
+
let(:all_keys_present_in_all_hash) do
[ { :name => "input1_value1", :type => :string, :data => "my_value1" },
{ :name => "input1_value2", :type => :string, :data => "my_value2" },
diff --git a/spec/unit/provider/remote_file_spec.rb b/spec/unit/provider/remote_file_spec.rb
index 6ceb1d450d..3f91377c60 100644
--- a/spec/unit/provider/remote_file_spec.rb
+++ b/spec/unit/provider/remote_file_spec.rb
@@ -36,7 +36,8 @@ describe Chef::Provider::RemoteFile do
let(:node) { double("Chef::Node") }
let(:events) { double("Chef::Events").as_null_object } # mock all the methods
- let(:run_context) { double("Chef::RunContext", :node => node, :events => events) }
+ let(:logger) { double("Mixlib::Log::Child").as_null_object }
+ let(:run_context) { double("Chef::RunContext", :node => node, :events => events, :logger => logger) }
let(:enclosing_directory) do
canonicalize_path(File.expand_path(File.join(CHEF_SPEC_DATA, "templates")))
end
diff --git a/spec/unit/provider/service/macosx_spec.rb b/spec/unit/provider/service/macosx_spec.rb
index 704c7a802e..5f8bbc4a39 100644
--- a/spec/unit/provider/service/macosx_spec.rb
+++ b/spec/unit/provider/service/macosx_spec.rb
@@ -44,6 +44,7 @@ describe Chef::Provider::Service::Macosx do
context "when service name is given as" do
let(:node) { Chef::Node.new }
let(:events) { Chef::EventDispatch::Dispatcher.new }
+ let(:logger) { double("Mixlib::Log::Child").as_null_object }
let(:run_context) { Chef::RunContext.new(node, {}, events) }
let(:provider) { described_class.new(new_resource, run_context) }
let(:launchctl_stdout) { StringIO.new }
@@ -73,6 +74,7 @@ XML
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)
@@ -260,7 +262,7 @@ SVC_LIST
it "shows warning message if service is already running" do
allow(current_resource).to receive(:running).and_return(true)
- expect(Chef::Log).to receive(:debug).with("macosx_service[#{service_name}] already running, not starting")
+ expect(logger).to receive(:trace).with("macosx_service[#{service_name}] already running, not starting")
provider.start_service
end
@@ -292,7 +294,7 @@ SVC_LIST
it "shows warning message if service is not running" do
allow(current_resource).to receive(:running).and_return(false)
- expect(Chef::Log).to receive(:debug).with("macosx_service[#{service_name}] not running, not stopping")
+ expect(logger).to receive(:trace).with("macosx_service[#{service_name}] not running, not stopping")
provider.stop_service
end
diff --git a/spec/unit/provider/service/windows_spec.rb b/spec/unit/provider/service/windows_spec.rb
index ce9154cb72..7cfc645b32 100644
--- a/spec/unit/provider/service/windows_spec.rb
+++ b/spec/unit/provider/service/windows_spec.rb
@@ -23,6 +23,8 @@ require "mixlib/shellout"
describe Chef::Provider::Service::Windows, "load_current_resource", :windows_only do
include_context "Win32"
+ let(:logger) { double("Mixlib::Log::Child").as_null_object }
+
let(:chef_service_name) { "chef-client" }
let(:new_resource) { Chef::Resource::WindowsService.new(chef_service_name) }
@@ -77,8 +79,9 @@ describe Chef::Provider::Service::Windows, "load_current_resource", :windows_onl
end
let(:provider) do
- prvdr = Chef::Provider::Service::Windows.new(new_resource,
- Chef::RunContext.new(Chef::Node.new, {}, Chef::EventDispatch::Dispatcher.new))
+ run_context = Chef::RunContext.new(Chef::Node.new, {}, Chef::EventDispatch::Dispatcher.new)
+ allow(run_context).to receive(:logger).and_return(logger)
+ prvdr = Chef::Provider::Service::Windows.new(new_resource, run_context)
prvdr.current_resource = Chef::Resource::WindowsService.new("current-chef")
prvdr
end
@@ -268,7 +271,7 @@ describe Chef::Provider::Service::Windows, "load_current_resource", :windows_onl
end
it "logs debug message" do
- expect(Chef::Log).to receive(:debug).with("windows_service[#{chef_service_name}] already exists - nothing to do")
+ expect(logger).to receive(:trace).with("windows_service[#{chef_service_name}] already exists - nothing to do")
provider.action_create
end
@@ -348,7 +351,7 @@ describe Chef::Provider::Service::Windows, "load_current_resource", :windows_onl
end
it "logs debug message" do
- expect(Chef::Log).to receive(:debug).with("windows_service[#{chef_service_name}] does not exist - nothing to do")
+ expect(logger).to receive(:trace).with("windows_service[#{chef_service_name}] does not exist - nothing to do")
provider.action_delete
end
@@ -421,7 +424,7 @@ describe Chef::Provider::Service::Windows, "load_current_resource", :windows_onl
end
it "logs warning" do
- expect(Chef::Log).to receive(:warn)
+ expect(logger).to receive(:warn)
.with("windows_service[#{chef_service_name}] does not exist. Maybe you need to prepend action :create")
provider.action_configure
end
diff --git a/spec/unit/provider/template_spec.rb b/spec/unit/provider/template_spec.rb
index 306fd6ea71..9f69772bc8 100644
--- a/spec/unit/provider/template_spec.rb
+++ b/spec/unit/provider/template_spec.rb
@@ -26,7 +26,8 @@ require "support/shared/unit/provider/file"
describe Chef::Provider::Template do
let(:node) { double("Chef::Node") }
let(:events) { double("Chef::Events").as_null_object } # mock all the methods
- let(:run_context) { double("Chef::RunContext", :node => node, :events => events) }
+ let(:logger) { double("Mixlib::Log::Child").as_null_object }
+ let(:run_context) { double("Chef::RunContext", :node => node, :events => events, :logger => logger) }
let(:enclosing_directory) do
canonicalize_path(File.expand_path(File.join(CHEF_SPEC_DATA, "templates")))
end
@@ -58,9 +59,6 @@ describe Chef::Provider::Template do
context "when creating the template" do
- let(:node) { double("Chef::Node") }
- let(:events) { double("Chef::Events").as_null_object } # mock all the methods
- let(:run_context) { double("Chef::RunContext", :node => node, :events => events) }
let(:enclosing_directory) do
canonicalize_path(File.expand_path(File.join(CHEF_SPEC_DATA, "templates")))
end
diff --git a/spec/unit/provider/user/windows_spec.rb b/spec/unit/provider/user/windows_spec.rb
index 82f3c1ab2a..179926e5e6 100644
--- a/spec/unit/provider/user/windows_spec.rb
+++ b/spec/unit/provider/user/windows_spec.rb
@@ -28,11 +28,14 @@ class Chef
end
describe Chef::Provider::User::Windows do
+ let(:logger) { double("Mixlib::Log::Child").as_null_object }
+
before(:each) do
@node = Chef::Node.new
@new_resource = Chef::Resource::User::WindowsUser.new("monkey")
@events = Chef::EventDispatch::Dispatcher.new
@run_context = Chef::RunContext.new(@node, {}, @events)
+ allow(@run_context).to receive(:logger).and_return(logger)
@current_resource = Chef::Resource::User::WindowsUser.new("monkey")
@net_user = double("Chef::Util::Windows::NetUser")
diff --git a/spec/unit/provider/zypper_repository_spec.rb b/spec/unit/provider/zypper_repository_spec.rb
index a366a33e86..2509452672 100644
--- a/spec/unit/provider/zypper_repository_spec.rb
+++ b/spec/unit/provider/zypper_repository_spec.rb
@@ -35,10 +35,12 @@ EOF
describe Chef::Provider::ZypperRepository do
let(:new_resource) { Chef::Resource::ZypperRepository.new("Nginx Repository") }
+ let(:logger) { double("Mixlib::Log::Child").as_null_object }
let(:provider) do
node = Chef::Node.new
events = Chef::EventDispatch::Dispatcher.new
run_context = Chef::RunContext.new(node, {}, events)
+ allow(run_context).to receive(:logger).and_return(logger)
Chef::Provider::ZypperRepository.new(new_resource, run_context)
end
@@ -58,7 +60,7 @@ describe Chef::Provider::ZypperRepository do
it "skips key import if gpgautoimportkeys is false" do
new_resource.gpgautoimportkeys(false)
expect(provider).to receive(:declare_resource)
- expect(Chef::Log).to receive(:debug)
+ expect(logger).to receive(:trace)
provider.run_action(:create)
end
end
@@ -117,7 +119,7 @@ describe Chef::Provider::ZypperRepository do
describe "#install_gpg_key" do
it "skips installing the key if a nil value for key is passed" do
- expect(Chef::Log).to receive(:debug)
+ expect(logger).to receive(:trace)
provider.install_gpg_key(nil)
end
end
diff --git a/spec/unit/resource/openssl_rsa_private_key.rb b/spec/unit/resource/openssl_rsa_private_key_spec.rb
index 67bebf17fe..67bebf17fe 100644
--- a/spec/unit/resource/openssl_rsa_private_key.rb
+++ b/spec/unit/resource/openssl_rsa_private_key_spec.rb
diff --git a/spec/unit/resource/openssl_rsa_public_key.rb b/spec/unit/resource/openssl_rsa_public_key_spec.rb
index d624e10338..d624e10338 100644
--- a/spec/unit/resource/openssl_rsa_public_key.rb
+++ b/spec/unit/resource/openssl_rsa_public_key_spec.rb
diff --git a/spec/unit/resource/sudo_spec.rb b/spec/unit/resource/sudo_spec.rb
index 660eb285da..8f5103597c 100644
--- a/spec/unit/resource/sudo_spec.rb
+++ b/spec/unit/resource/sudo_spec.rb
@@ -80,6 +80,11 @@ describe Chef::Resource::Sudo do
expect(resource.config_prefix).to eql("/private/etc")
end
+ it "it sets the config prefix to /usr/local/etc on FreeBSD" do
+ node.automatic[:platform_family] = "freebsd"
+ expect(resource.config_prefix).to eql("/usr/local/etc")
+ end
+
it "it sets the config prefix to /opt/local/etc on smartos" do
node.automatic[:platform_family] = "smartos"
expect(resource.config_prefix).to eql("/opt/local/etc")
diff --git a/spec/unit/resource/swap_file_spec.rb b/spec/unit/resource/swap_file_spec.rb
new file mode 100644
index 0000000000..905e12646a
--- /dev/null
+++ b/spec/unit/resource/swap_file_spec.rb
@@ -0,0 +1,40 @@
+#
+# Copyright:: Copyright 2018, 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 "spec_helper"
+
+describe Chef::Resource::SwapFile do
+ let(:resource) { Chef::Resource::SwapFile.new("swapfile") }
+
+ it "sets resource name as :swap_file" do
+ expect(resource.resource_name).to eql(:swap_file)
+ end
+
+ it "sets the path as its name" do
+ expect(resource.path).to eql("swapfile")
+ end
+
+ it "sets the default action as :create" do
+ expect(resource.action).to eql([:create])
+ end
+
+ it "supports :create and :remove actions" do
+ expect { resource.action :create }.not_to raise_error
+ expect { resource.action :remove }.not_to raise_error
+ expect { resource.action :delete }.to raise_error(ArgumentError)
+ end
+end
diff --git a/spec/unit/resource/sysctl_spec.rb b/spec/unit/resource/sysctl_spec.rb
new file mode 100644
index 0000000000..934db9b9e2
--- /dev/null
+++ b/spec/unit/resource/sysctl_spec.rb
@@ -0,0 +1,56 @@
+#
+# Copyright:: Copyright 2018, 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 "spec_helper"
+
+describe Chef::Resource::Sysctl do
+ let(:resource) { Chef::Resource::Sysctl.new("something.something") }
+
+ it "sets resource name as :sysctl" do
+ expect(resource.resource_name).to eql(:sysctl)
+ end
+
+ it "sets the default action as :apply" do
+ expect(resource.action).to eql([:apply])
+ end
+
+ it "sets the key property as its name property" do
+ expect(resource.key).to eql("something.something")
+ end
+
+ it "coerces Arrays in the value property to space delimited Strings" do
+ resource.value [1, 2, 3]
+ expect(resource.value).to eql("1 2 3")
+ end
+
+ it "coerces Integers in the value property to Strings" do
+ resource.value 1
+ expect(resource.value).to eql("1")
+ end
+
+ it "coerces Floats in the value property to Strings" do
+ resource.value 1.1
+ expect(resource.value).to eql("1.1")
+ end
+
+ it "supports :apply and :remove actions" do
+ expect { resource.action :apply }.not_to raise_error
+ expect { resource.action :remove }.not_to raise_error
+ expect { resource.action :delete }.to raise_error(ArgumentError)
+ expect { resource.action :install }.to raise_error(ArgumentError)
+ end
+end
diff --git a/spec/unit/resource/windows_ad_join.rb b/spec/unit/resource/windows_ad_join.rb
new file mode 100644
index 0000000000..7fd02c2021
--- /dev/null
+++ b/spec/unit/resource/windows_ad_join.rb
@@ -0,0 +1,45 @@
+#
+# Copyright:: Copyright 2018, 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 "spec_helper"
+
+describe Chef::Resource::WindowsAdJoin do
+ let(:resource) { Chef::Resource::WindowsAdJoin.new("example.com") }
+
+ it "sets resource name as :windows_ad_join" do
+ expect(resource.resource_name).to eql(:windows_ad_join)
+ end
+
+ it "sets the domain_name as its name" do
+ expect(resource.domain_name).to eql("example.com")
+ end
+
+ it "only accepts FQDNs for the domain_name property" do
+ expect { resource.domain_name "example" }.to raise_error(ArgumentError)
+ end
+
+ it "sets the default action as :join" do
+ expect(resource.action).to eql([:join])
+ end
+
+ it "accepts :immediate, :delayed, or :never values for 'reboot' property" do
+ expect { resource.reboot :immediate }.not_to raise_error
+ expect { resource.reboot :delayed }.not_to raise_error
+ expect { resource.reboot :never }.not_to raise_error
+ expect { resource.reboot :nopenope }.to raise_error(ArgumentError)
+ end
+end
diff --git a/spec/unit/resource/windows_feature_dism.rb b/spec/unit/resource/windows_feature_dism.rb
index 3885f4813e..1004b75ba9 100644
--- a/spec/unit/resource/windows_feature_dism.rb
+++ b/spec/unit/resource/windows_feature_dism.rb
@@ -18,7 +18,7 @@
require "spec_helper"
describe Chef::Resource::WindowsFeatureDism do
- let(:resource) { Chef::Resource::WindowsFeatureDism.new("SNMP") }
+ let(:resource) { Chef::Resource::WindowsFeatureDism.new(%w{SNMP DHCP}) }
it "sets resource name as :windows_feature_dism" do
expect(resource.resource_name).to eql(:windows_feature_dism)
@@ -28,7 +28,17 @@ describe Chef::Resource::WindowsFeatureDism do
expect(resource.action).to eql([:install])
end
- it "sets the feature_name property as its name and coerces it to an array" do
+ it "sets the feature_name property as its name property" do
+ expect(resource.feature_name).to eql(%w{SNMP DHCP})
+ end
+
+ it "coerces comma separated lists of features to arrays" do
+ resource.feature_name "SNMP, DHCP"
+ expect(resource.feature_name).to eql(%w{SNMP DHCP})
+ end
+
+ it "coerces a single feature as a String into an array" do
+ resource.feature_name "SNMP"
expect(resource.feature_name).to eql(["SNMP"])
end
diff --git a/spec/unit/resource/windows_feature_powershell.rb b/spec/unit/resource/windows_feature_powershell.rb
index 02f308ca73..5ea226575c 100644
--- a/spec/unit/resource/windows_feature_powershell.rb
+++ b/spec/unit/resource/windows_feature_powershell.rb
@@ -18,7 +18,7 @@
require "spec_helper"
describe Chef::Resource::WindowsFeaturePowershell do
- let(:resource) { Chef::Resource::WindowsFeaturePowershell.new("SNMP") }
+ let(:resource) { Chef::Resource::WindowsFeaturePowershell.new(%w{SNMP DHCP}) }
it "sets resource name as :windows_feature_powershell" do
expect(resource.resource_name).to eql(:windows_feature_powershell)
@@ -28,7 +28,17 @@ describe Chef::Resource::WindowsFeaturePowershell do
expect(resource.action).to eql([:install])
end
- it "sets the feature_name property as its name and coerces it to an array" do
+ it "sets the feature_name property as its name property" do
+ expect(resource.feature_name).to eql(%w{SNMP DHCP})
+ end
+
+ it "coerces comma separated lists of features to arrays" do
+ resource.feature_name "SNMP, DHCP"
+ expect(resource.feature_name).to eql(%w{SNMP DHCP})
+ end
+
+ it "coerces a single feature as a String into an array" do
+ resource.feature_name "SNMP"
expect(resource.feature_name).to eql(["SNMP"])
end
diff --git a/spec/unit/resource/windows_pagefile_spec.rb b/spec/unit/resource/windows_pagefile_spec.rb
index 8ff06bb3f0..dd6353eccb 100644
--- a/spec/unit/resource/windows_pagefile_spec.rb
+++ b/spec/unit/resource/windows_pagefile_spec.rb
@@ -18,19 +18,19 @@
require "spec_helper"
describe Chef::Resource::WindowsPagefile do
- let(:resource) { Chef::Resource::WindowsPagefile.new("C:/pagefile.sys") }
+ let(:resource) { Chef::Resource::WindowsPagefile.new("C:\\pagefile.sys") }
it "sets resource name as :windows_pagefile" do
expect(resource.resource_name).to eql(:windows_pagefile)
end
it "sets the path as its name" do
- expect(resource.path).to eql("C:/pagefile.sys")
+ expect(resource.path).to eql("C:\\pagefile.sys")
end
- it "coerces backslashes in the path property to forward slashes" do
- resource.path 'C:\pagefile.sys'
- expect(resource.path).to eql("C:/pagefile.sys")
+ it "coerces forward slashes in the path property to back slashes" do
+ resource.path "C:/pagefile.sys"
+ expect(resource.path).to eql("C:\\pagefile.sys")
end
it "sets the default action as :set" do
diff --git a/spec/unit/resource_reporter_spec.rb b/spec/unit/resource_reporter_spec.rb
index 0ea704084c..97a4fe4b30 100644
--- a/spec/unit/resource_reporter_spec.rb
+++ b/spec/unit/resource_reporter_spec.rb
@@ -635,7 +635,7 @@ describe Chef::ResourceReporter do
end
it "prints an error about the 404" do
- expect(Chef::Log).to receive(:debug).with(/404/)
+ expect(Chef::Log).to receive(:trace).with(/404/)
@resource_reporter.run_started(@run_status)
end