summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2019-11-08 14:06:33 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2019-11-08 14:06:33 -0800
commit8a7e29d52882c39d0c903eef83bd3472e4f334af (patch)
treea25a7b76416e07ebdb54e569fb0006079cf012db /spec
parentc31625406530b560fab02b11fa2447955ed2faef (diff)
downloadchef-8a7e29d52882c39d0c903eef83bd3472e4f334af.tar.gz
Add chef-utils gem with various recipe DSL helpers
This is the implementation of [RFC-087](https://github.com/chef-boneyard/chef-rfc/blob/master/rfc087-distro-sugar-helpers.md) although some of the specifics have been iterated on and changed. The documentation will be in the [README.md](https://github.com/chef/chef/tree/master/chef-utils/README.md) once this is merged. While this PR mostly moves chef-sugar utilities into core-chef via this chef-utils gem, the scope of the chef-utils gem should be considered larger than just that. As an example this PR moves the Mash class into this gem for reuse in ohai as well. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'spec')
-rw-r--r--spec/functional/event_loggers/windows_eventlog_spec.rb2
-rw-r--r--spec/functional/mixin/user_context_spec.rb4
-rw-r--r--spec/functional/rebooter_spec.rb2
-rw-r--r--spec/functional/resource/cookbook_file_spec.rb4
-rw-r--r--spec/functional/resource/template_spec.rb2
-rw-r--r--spec/functional/win32/crypto_spec.rb2
-rw-r--r--spec/functional/win32/security_spec.rb2
-rw-r--r--spec/functional/win32/service_manager_spec.rb2
-rw-r--r--spec/functional/win32/sid_spec.rb4
-rw-r--r--spec/functional/win32/version_info_spec.rb2
-rw-r--r--spec/functional/win32/versions_spec.rb2
-rw-r--r--spec/integration/knife/config_get_profile_spec.rb4
-rw-r--r--spec/integration/knife/config_get_spec.rb4
-rw-r--r--spec/integration/knife/config_list_profiles_spec.rb4
-rw-r--r--spec/integration/knife/config_use_profile_spec.rb4
-rw-r--r--spec/integration/knife/list_spec.rb4
-rw-r--r--spec/integration/solo/solo_spec.rb2
-rw-r--r--spec/support/matchers/leak.rb2
-rw-r--r--spec/support/mock/platform.rb2
-rw-r--r--spec/support/platform_helpers.rb2
-rw-r--r--spec/support/shared/integration/integration_helper.rb2
-rw-r--r--spec/support/shared/integration/knife_support.rb2
-rw-r--r--spec/support/shared/unit/provider/file.rb8
-rw-r--r--spec/unit/application/client_spec.rb4
-rw-r--r--spec/unit/application_spec.rb2
-rw-r--r--spec/unit/chef_fs/file_pattern_spec.rb4
-rw-r--r--spec/unit/chef_fs/path_util_spec.rb6
-rw-r--r--spec/unit/client_spec.rb4
-rw-r--r--spec/unit/cookbook/cookbook_version_loader_spec.rb2
-rw-r--r--spec/unit/cookbook/syntax_check_spec.rb4
-rw-r--r--spec/unit/cookbook_loader_spec.rb2
-rw-r--r--spec/unit/data_bag_spec.rb4
-rw-r--r--spec/unit/dsl/platform_introspection_spec.rb32
-rw-r--r--spec/unit/file_content_management/deploy/mv_windows_spec.rb2
-rw-r--r--spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb2
-rw-r--r--spec/unit/knife/core/gem_glob_loader_spec.rb2
-rw-r--r--spec/unit/knife/core/hashed_command_loader_spec.rb2
-rw-r--r--spec/unit/knife/core/subcommand_loader_spec.rb2
-rw-r--r--spec/unit/knife/core/ui_spec.rb4
-rw-r--r--spec/unit/knife/data_bag_from_file_spec.rb4
-rw-r--r--spec/unit/knife/environment_from_file_spec.rb4
-rw-r--r--spec/unit/knife/supermarket_install_spec.rb2
-rw-r--r--spec/unit/mash_spec.rb51
-rw-r--r--spec/unit/mixin/path_sanity_spec.rb6
-rw-r--r--spec/unit/mixin/shell_out_spec.rb5
-rw-r--r--spec/unit/mixin/template_spec.rb8
-rw-r--r--spec/unit/mixin/user_context_spec.rb6
-rw-r--r--spec/unit/node_map_spec.rb24
-rw-r--r--spec/unit/platform/query_helpers_spec.rb18
-rw-r--r--spec/unit/provider/execute_spec.rb2
-rw-r--r--spec/unit/provider/link_spec.rb10
-rw-r--r--spec/unit/provider/package/windows/exe_spec.rb2
-rw-r--r--spec/unit/provider/package/windows_spec.rb4
-rw-r--r--spec/unit/provider/remote_file/fetcher_spec.rb4
-rw-r--r--spec/unit/provider/remote_file/local_file_spec.rb2
-rw-r--r--spec/unit/provider/remote_file/network_file_spec.rb2
-rw-r--r--spec/unit/provider/script_spec.rb4
-rw-r--r--spec/unit/provider/subversion_spec.rb6
-rw-r--r--spec/unit/provider/user/dscl_spec.rb2
-rw-r--r--spec/unit/provider_resolver_spec.rb102
-rw-r--r--spec/unit/resource/cookbook_file_spec.rb6
-rw-r--r--spec/unit/resource/remote_file_spec.rb6
-rw-r--r--spec/unit/role_spec.rb4
-rw-r--r--spec/unit/shell_spec.rb2
-rw-r--r--spec/unit/util/selinux_spec.rb4
-rw-r--r--spec/unit/win32/error_spec.rb2
-rw-r--r--spec/unit/win32/link_spec.rb2
-rw-r--r--spec/unit/win32/security_spec.rb2
-rw-r--r--spec/unit/windows_service_spec.rb2
69 files changed, 202 insertions, 242 deletions
diff --git a/spec/functional/event_loggers/windows_eventlog_spec.rb b/spec/functional/event_loggers/windows_eventlog_spec.rb
index ca15d3e38d..d6c4c481f3 100644
--- a/spec/functional/event_loggers/windows_eventlog_spec.rb
+++ b/spec/functional/event_loggers/windows_eventlog_spec.rb
@@ -19,7 +19,7 @@
require "spec_helper"
require "securerandom"
require "chef/event_loggers/windows_eventlog"
-if Chef::Platform.windows?
+if ChefUtils.windows?
require "win32/eventlog"
include Win32
end
diff --git a/spec/functional/mixin/user_context_spec.rb b/spec/functional/mixin/user_context_spec.rb
index b6b8b057d5..0fe5f08824 100644
--- a/spec/functional/mixin/user_context_spec.rb
+++ b/spec/functional/mixin/user_context_spec.rb
@@ -17,8 +17,8 @@
require "spec_helper"
-require "chef/win32/api" if Chef::Platform.windows?
-require "chef/win32/api/error" if Chef::Platform.windows?
+require "chef/win32/api" if ChefUtils.windows?
+require "chef/win32/api/error" if ChefUtils.windows?
require "chef/mixin/user_context"
describe Chef::Mixin::UserContext, windows_only: true do
diff --git a/spec/functional/rebooter_spec.rb b/spec/functional/rebooter_spec.rb
index 747978cc96..689570c580 100644
--- a/spec/functional/rebooter_spec.rb
+++ b/spec/functional/rebooter_spec.rb
@@ -72,7 +72,7 @@ describe Chef::Platform::Rebooter do
shared_context "test a reboot method" do
def test_rebooter_method(method_sym, is_windows, is_solaris, expected_reboot_str)
- allow(ChefConfig).to receive(:windows?).and_return(is_windows)
+ allow(ChefUtils).to receive(:windows?).and_return(is_windows)
node.automatic["os"] = node.automatic["platform"] = node.automatic["platform_family"] = "solaris2" if is_solaris
expect(rebooter).to receive(:shell_out!).once.with(expected_reboot_str)
expect(rebooter).to receive(:raise).with(Chef::Exceptions::Reboot)
diff --git a/spec/functional/resource/cookbook_file_spec.rb b/spec/functional/resource/cookbook_file_spec.rb
index 6e964a6499..37d31188ac 100644
--- a/spec/functional/resource/cookbook_file_spec.rb
+++ b/spec/functional/resource/cookbook_file_spec.rb
@@ -68,11 +68,11 @@ describe Chef::Resource::CookbookFile do
let(:path) { File.join(windows_non_temp_dir, make_tmpname(file_base)) }
before do
- FileUtils.mkdir_p(windows_non_temp_dir) if Chef::Platform.windows?
+ FileUtils.mkdir_p(windows_non_temp_dir) if ChefUtils.windows?
end
after do
- FileUtils.rm_r(windows_non_temp_dir) if Chef::Platform.windows? && File.exists?(windows_non_temp_dir)
+ FileUtils.rm_r(windows_non_temp_dir) if ChefUtils.windows? && File.exists?(windows_non_temp_dir)
end
end
diff --git a/spec/functional/resource/template_spec.rb b/spec/functional/resource/template_spec.rb
index feef97dd27..63a950db95 100644
--- a/spec/functional/resource/template_spec.rb
+++ b/spec/functional/resource/template_spec.rb
@@ -203,7 +203,7 @@ describe Chef::Resource::Template do
it "output should contain platform's line endings" do
resource.run_action(:create)
binread(path).each_line do |line|
- expect(line).to end_with(Chef::Platform.windows? ? "\r\n" : "\n")
+ expect(line).to end_with(ChefUtils.windows? ? "\r\n" : "\n")
end
end
end
diff --git a/spec/functional/win32/crypto_spec.rb b/spec/functional/win32/crypto_spec.rb
index 70d3f42cfb..ab51e4d681 100644
--- a/spec/functional/win32/crypto_spec.rb
+++ b/spec/functional/win32/crypto_spec.rb
@@ -17,7 +17,7 @@
#
require "spec_helper"
-if Chef::Platform.windows?
+if ChefUtils.windows?
require "chef/win32/crypto"
end
diff --git a/spec/functional/win32/security_spec.rb b/spec/functional/win32/security_spec.rb
index a72088a079..3eb7bedd48 100644
--- a/spec/functional/win32/security_spec.rb
+++ b/spec/functional/win32/security_spec.rb
@@ -19,7 +19,7 @@
require "spec_helper"
require "mixlib/shellout"
require "chef/mixin/user_context"
-if Chef::Platform.windows?
+if ChefUtils.windows?
require "chef/win32/security"
end
diff --git a/spec/functional/win32/service_manager_spec.rb b/spec/functional/win32/service_manager_spec.rb
index abc8118835..bb8ed54c0e 100644
--- a/spec/functional/win32/service_manager_spec.rb
+++ b/spec/functional/win32/service_manager_spec.rb
@@ -17,7 +17,7 @@
#
require "spec_helper"
-if Chef::Platform.windows?
+if ChefUtils.windows?
require "chef/application/windows_service_manager"
end
diff --git a/spec/functional/win32/sid_spec.rb b/spec/functional/win32/sid_spec.rb
index eac62d88b6..bdc570dfe6 100644
--- a/spec/functional/win32/sid_spec.rb
+++ b/spec/functional/win32/sid_spec.rb
@@ -17,12 +17,12 @@
#
require "spec_helper"
-if Chef::Platform.windows?
+if ChefUtils.windows?
require "chef/win32/security"
end
describe "Chef::ReservedNames::Win32::SID", :windows_only do
- if Chef::Platform.windows?
+ if ChefUtils.windows?
SID ||= Chef::ReservedNames::Win32::Security::SID
end
diff --git a/spec/functional/win32/version_info_spec.rb b/spec/functional/win32/version_info_spec.rb
index b5570732a0..988339fd7a 100644
--- a/spec/functional/win32/version_info_spec.rb
+++ b/spec/functional/win32/version_info_spec.rb
@@ -17,7 +17,7 @@
#
require "spec_helper"
-if Chef::Platform.windows?
+if ChefUtils.windows?
require "chef/win32/file/version_info"
end
diff --git a/spec/functional/win32/versions_spec.rb b/spec/functional/win32/versions_spec.rb
index 19bd0e3875..9ce21c49f9 100644
--- a/spec/functional/win32/versions_spec.rb
+++ b/spec/functional/win32/versions_spec.rb
@@ -17,7 +17,7 @@
#
require "spec_helper"
-if Chef::Platform.windows?
+if ChefUtils.windows?
require "chef/win32/version"
end
diff --git a/spec/integration/knife/config_get_profile_spec.rb b/spec/integration/knife/config_get_profile_spec.rb
index e97b24b869..d17d572f13 100644
--- a/spec/integration/knife/config_get_profile_spec.rb
+++ b/spec/integration/knife/config_get_profile_spec.rb
@@ -50,7 +50,7 @@ describe "knife config get-profile", :workstation do
ENV["KNIFE_HOME"] = old_knife_home
ENV["HOME"] = old_home
Dir.chdir(old_wd)
- ENV[ChefConfig.windows? ? "CD" : "PWD"] = Dir.pwd
+ ENV[ChefUtils.windows? ? "CD" : "PWD"] = Dir.pwd
ChefConfig::PathHelper.per_tool_home_environment = nil
end
end
@@ -60,7 +60,7 @@ describe "knife config get-profile", :workstation do
# because it has to run after the before set in the "with a chef repo" shared context.
directory("repo")
Dir.chdir(path_to("repo"))
- ENV[ChefConfig.windows? ? "CD" : "PWD"] = Dir.pwd
+ ENV[ChefUtils.windows? ? "CD" : "PWD"] = Dir.pwd
ENV["HOME"] = path_to(".")
end
diff --git a/spec/integration/knife/config_get_spec.rb b/spec/integration/knife/config_get_spec.rb
index 83150a39b8..7719ee2bd0 100644
--- a/spec/integration/knife/config_get_spec.rb
+++ b/spec/integration/knife/config_get_spec.rb
@@ -54,7 +54,7 @@ describe "knife config get", :workstation do
ENV["KNIFE_HOME"] = old_knife_home
ENV["HOME"] = old_home
Dir.chdir(old_wd)
- ENV[ChefConfig.windows? ? "CD" : "PWD"] = Dir.pwd
+ ENV[ChefUtils.windows? ? "CD" : "PWD"] = Dir.pwd
ChefConfig::PathHelper.per_tool_home_environment = nil
end
end
@@ -64,7 +64,7 @@ describe "knife config get", :workstation do
# because it has to run after the before set in the "with a chef repo" shared context.
directory("repo")
Dir.chdir(path_to("repo"))
- ENV[ChefConfig.windows? ? "CD" : "PWD"] = Dir.pwd
+ ENV[ChefUtils.windows? ? "CD" : "PWD"] = Dir.pwd
ENV["HOME"] = path_to(".")
end
diff --git a/spec/integration/knife/config_list_profiles_spec.rb b/spec/integration/knife/config_list_profiles_spec.rb
index 044b50b5be..7ac4ef755e 100644
--- a/spec/integration/knife/config_list_profiles_spec.rb
+++ b/spec/integration/knife/config_list_profiles_spec.rb
@@ -44,7 +44,7 @@ describe "knife config list-profiles", :workstation do
ensure
ENV["HOME"] = old_home
Dir.chdir(old_wd)
- ENV[ChefConfig.windows? ? "CD" : "PWD"] = Dir.pwd
+ ENV[ChefUtils.windows? ? "CD" : "PWD"] = Dir.pwd
end
end
@@ -53,7 +53,7 @@ describe "knife config list-profiles", :workstation do
# because it has to run after the before set in the "with a chef repo" shared context.
directory("repo")
Dir.chdir(path_to("repo"))
- ENV[ChefConfig.windows? ? "CD" : "PWD"] = Dir.pwd
+ ENV[ChefUtils.windows? ? "CD" : "PWD"] = Dir.pwd
ENV["HOME"] = path_to(".")
end
diff --git a/spec/integration/knife/config_use_profile_spec.rb b/spec/integration/knife/config_use_profile_spec.rb
index a021dbbe6f..4ea9012212 100644
--- a/spec/integration/knife/config_use_profile_spec.rb
+++ b/spec/integration/knife/config_use_profile_spec.rb
@@ -51,7 +51,7 @@ describe "knife config use-profile", :workstation do
ENV["KNIFE_HOME"] = old_knife_home
ENV["HOME"] = old_home
Dir.chdir(old_wd)
- ENV[ChefConfig.windows? ? "CD" : "PWD"] = Dir.pwd
+ ENV[ChefUtils.windows? ? "CD" : "PWD"] = Dir.pwd
ChefConfig::PathHelper.per_tool_home_environment = nil
end
end
@@ -61,7 +61,7 @@ describe "knife config use-profile", :workstation do
# because it has to run after the before set in the "with a chef repo" shared context.
directory("repo")
Dir.chdir(path_to("repo"))
- ENV[ChefConfig.windows? ? "CD" : "PWD"] = Dir.pwd
+ ENV[ChefUtils.windows? ? "CD" : "PWD"] = Dir.pwd
ENV["HOME"] = path_to(".")
end
diff --git a/spec/integration/knife/list_spec.rb b/spec/integration/knife/list_spec.rb
index 830dd0e428..9689c9e6c8 100644
--- a/spec/integration/knife/list_spec.rb
+++ b/spec/integration/knife/list_spec.rb
@@ -466,7 +466,7 @@ describe "knife list", :workstation do
end
end
- when_the_repository "has a cookbooks directory and a symlinked cookbooks directory", skip: (Chef::Platform.windows?) do
+ when_the_repository "has a cookbooks directory and a symlinked cookbooks directory", skip: (ChefUtils.windows?) do
before do
directory "cookbooks"
symlink "symlinked", "cookbooks"
@@ -503,7 +503,7 @@ describe "knife list", :workstation do
end
end
- when_the_repository "has a real_cookbooks directory and a cookbooks symlink to it", skip: (Chef::Platform.windows?) do
+ when_the_repository "has a real_cookbooks directory and a cookbooks symlink to it", skip: (ChefUtils.windows?) do
before do
directory "real_cookbooks"
symlink "cookbooks", "real_cookbooks"
diff --git a/spec/integration/solo/solo_spec.rb b/spec/integration/solo/solo_spec.rb
index 451943e225..c62b2ec6b0 100644
--- a/spec/integration/solo/solo_spec.rb
+++ b/spec/integration/solo/solo_spec.rb
@@ -4,7 +4,7 @@ require "chef/run_lock"
require "chef/config"
require "timeout"
require "fileutils"
-require "chef/win32/security" if Chef::Platform.windows?
+require "chef/win32/security" if ChefUtils.windows?
require "chef/dist"
describe Chef::Dist::SOLOEXEC do
diff --git a/spec/support/matchers/leak.rb b/spec/support/matchers/leak.rb
index 5f22c1c151..6b456af934 100644
--- a/spec/support/matchers/leak.rb
+++ b/spec/support/matchers/leak.rb
@@ -60,7 +60,7 @@ module Matchers
def profiler
@profiler ||= begin
- if Chef::Platform.windows?
+ if ChefUtils.windows?
require File.join(File.dirname(__FILE__), "..", "platforms", "prof", "win32")
RSpec::Prof::Win32::Profiler.new
else
diff --git a/spec/support/mock/platform.rb b/spec/support/mock/platform.rb
index 2cf605c741..b0a6258276 100644
--- a/spec/support/mock/platform.rb
+++ b/spec/support/mock/platform.rb
@@ -6,7 +6,7 @@
# testing code that mixes in platform specific modules like +Chef::Mixin::Securable+
# or +Chef::FileAccessControl+
def platform_mock(platform = :unix)
- allow(ChefConfig).to receive(:windows?).and_return(platform == :windows ? true : false)
+ allow(ChefUtils).to receive(:windows?).and_return(platform == :windows ? true : false)
ENV["SYSTEMDRIVE"] = (platform == :windows ? "C:" : nil)
if platform == :windows
diff --git a/spec/support/platform_helpers.rb b/spec/support/platform_helpers.rb
index 3ac657d84e..7c2edc426d 100644
--- a/spec/support/platform_helpers.rb
+++ b/spec/support/platform_helpers.rb
@@ -35,6 +35,8 @@ def ruby_32bit?
end
def windows?
+ # NOTE this deliberately does not use ChefUtils.windows? because otherwise it would
+ # pick up the node out of tests, while this tests the hosts running the specs.
!!(RUBY_PLATFORM =~ /mswin|mingw|windows/)
end
diff --git a/spec/support/shared/integration/integration_helper.rb b/spec/support/shared/integration/integration_helper.rb
index f0dfd1dc43..af57e21c73 100644
--- a/spec/support/shared/integration/integration_helper.rb
+++ b/spec/support/shared/integration/integration_helper.rb
@@ -128,7 +128,7 @@ module IntegrationSupport
# TODO: "force" actually means "silence all exceptions". this
# silences a weird permissions error on Windows that we should track
# down, but for now there's no reason for it to blow up our CI.
- FileUtils.remove_entry_secure(@repository_dir, force = Chef::Platform.windows?)
+ FileUtils.remove_entry_secure(@repository_dir, force = ChefUtils.windows?)
ensure
@repository_dir = nil
end
diff --git a/spec/support/shared/integration/knife_support.rb b/spec/support/shared/integration/knife_support.rb
index 07d95f17cc..8de665c370 100644
--- a/spec/support/shared/integration/knife_support.rb
+++ b/spec/support/shared/integration/knife_support.rb
@@ -181,7 +181,7 @@ module KnifeSupport
expect(stderr_actual).to eq(expected[:stderr])
end
stdout_actual = @stdout
- if Chef::Platform.windows?
+ if ChefUtils.windows?
stderr_actual = stderr_actual.gsub("\r\n", "\n")
stdout_actual = stdout_actual.gsub("\r\n", "\n")
end
diff --git a/spec/support/shared/unit/provider/file.rb b/spec/support/shared/unit/provider/file.rb
index 2771a371d4..36b19675c2 100644
--- a/spec/support/shared/unit/provider/file.rb
+++ b/spec/support/shared/unit/provider/file.rb
@@ -1,6 +1,6 @@
#
# Author:: Lamont Granquist (<lamont@chef.io>)
-# Copyright:: Copyright 2013-2016, Chef Software, Inc.
+# Copyright:: Copyright 2013-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -256,7 +256,7 @@ shared_examples_for Chef::Provider::File do
context "examining file security metadata on Unix with a file that exists" do
before do
# fake that we're on unix even if we're on windows
- allow(ChefConfig).to receive(:windows?).and_return(false)
+ allow(ChefUtils).to receive(:windows?).and_return(false)
# mock up the filesystem to behave like unix
setup_normal_file
stat_struct = double("::File.stat", mode: 0600, uid: 0, gid: 0, mtime: 10000)
@@ -332,7 +332,7 @@ shared_examples_for Chef::Provider::File do
context "examining file security metadata on Unix with a file that does not exist" do
before do
# fake that we're on unix even if we're on windows
- allow(ChefConfig).to receive(:windows?).and_return(false)
+ allow(ChefUtils).to receive(:windows?).and_return(false)
setup_missing_file
end
@@ -381,7 +381,7 @@ shared_examples_for Chef::Provider::File do
before do
# fake that we're on unix even if we're on windows
- allow(ChefConfig).to receive(:windows?).and_return(false)
+ allow(ChefUtils).to receive(:windows?).and_return(false)
# mock up the filesystem to behave like unix
setup_normal_file
stat_struct = double("::File.stat", mode: 0600, uid: 0, gid: 0, mtime: 10000)
diff --git a/spec/unit/application/client_spec.rb b/spec/unit/application/client_spec.rb
index d4ed403197..b99f1b0126 100644
--- a/spec/unit/application/client_spec.rb
+++ b/spec/unit/application/client_spec.rb
@@ -323,7 +323,7 @@ describe Chef::Application::Client, "reconfigure" do
it "should terminate with message when interval is given" do
Chef::Config[:interval] = 600
- allow(ChefConfig).to receive(:windows?).and_return(false)
+ allow(ChefUtils).to receive(:windows?).and_return(false)
expect(Chef::Application).to receive(:fatal!).with(
/Unforked .* interval runs are disabled by default\.
Configuration settings:
@@ -336,7 +336,7 @@ Enable .* interval runs by setting `:client_fork = true` in your config file or
context "when interval is given on windows" do
before do
Chef::Config[:interval] = 600
- allow(ChefConfig).to receive(:windows?).and_return(true)
+ allow(ChefUtils).to receive(:windows?).and_return(true)
end
it "should terminate" do
diff --git a/spec/unit/application_spec.rb b/spec/unit/application_spec.rb
index 7a787d1f3f..24a453a240 100644
--- a/spec/unit/application_spec.rb
+++ b/spec/unit/application_spec.rb
@@ -277,7 +277,7 @@ describe Chef::Application do
end
end
- if Chef::Platform.windows?
+ if ChefUtils.windows?
it_behaves_like "sets log_location", :win_evt, Chef::Log::WinEvt
it_behaves_like "sets log_location", "win_evt", Chef::Log::WinEvt
else
diff --git a/spec/unit/chef_fs/file_pattern_spec.rb b/spec/unit/chef_fs/file_pattern_spec.rb
index 58cdbb28c2..856be5de0d 100644
--- a/spec/unit/chef_fs/file_pattern_spec.rb
+++ b/spec/unit/chef_fs/file_pattern_spec.rb
@@ -157,7 +157,7 @@ describe Chef::ChefFS::FilePattern do
end
end
- context 'with simple pattern "a\*\b"', skip: (Chef::Platform.windows?) do
+ context 'with simple pattern "a\*\b"', skip: (ChefUtils.windows?) do
let(:pattern) { Chef::ChefFS::FilePattern.new('a\*\b') }
it "match?" do
expect(pattern.match?("a*b")).to be_truthy
@@ -264,7 +264,7 @@ describe Chef::ChefFS::FilePattern do
end
end
- context 'with star pattern "/abc/d[a-z][0-9]f/ghi"', skip: (Chef::Platform.windows?) do
+ context 'with star pattern "/abc/d[a-z][0-9]f/ghi"', skip: (ChefUtils.windows?) do
let(:pattern) { Chef::ChefFS::FilePattern.new("/abc/d[a-z][0-9]f/ghi") }
it "match?" do
expect(pattern.match?("/abc/de1f/ghi")).to be_truthy
diff --git a/spec/unit/chef_fs/path_util_spec.rb b/spec/unit/chef_fs/path_util_spec.rb
index 93205a1815..70679a5d07 100644
--- a/spec/unit/chef_fs/path_util_spec.rb
+++ b/spec/unit/chef_fs/path_util_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Kartik Null Cating-Subramanian (<ksubramanian@chef.io>)
-# Copyright:: Copyright 2015-2016, Chef Software Inc.
+# Copyright:: Copyright 2015-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -81,7 +81,7 @@ describe Chef::ChefFS::PathUtils do
end
it "handles root correctly" do
- if Chef::Platform.windows?
+ if ChefUtils.windows?
expect(Chef::ChefFS::PathUtils.realest_path("C:/")).to eq("C:/")
else
expect(Chef::ChefFS::PathUtils.realest_path("/")).to eq("/")
@@ -91,7 +91,7 @@ describe Chef::ChefFS::PathUtils do
context "invoking descendant_path" do
it "handles paths with various casing on windows" do
- allow(Chef::ChefFS).to receive(:windows?) { true }
+ allow(ChefUtils).to receive(:windows?) { true }
expect(Chef::ChefFS::PathUtils.descendant_path("C:/ab/b/c", "C:/AB/B")).to eq("c")
expect(Chef::ChefFS::PathUtils.descendant_path("C:/ab/b/c", "c:/ab/B")).to eq("c")
end
diff --git a/spec/unit/client_spec.rb b/spec/unit/client_spec.rb
index 5182717af8..3a400575c0 100644
--- a/spec/unit/client_spec.rb
+++ b/spec/unit/client_spec.rb
@@ -670,7 +670,7 @@ describe Chef::Client do
describe "windows_admin_check" do
context "platform is not windows" do
before do
- allow(ChefConfig).to receive(:windows?).and_return(false)
+ allow(ChefUtils).to receive(:windows?).and_return(false)
end
it "shouldn't be called" do
@@ -681,7 +681,7 @@ describe Chef::Client do
context "platform is windows" do
before do
- allow(ChefConfig).to receive(:windows?).and_return(true)
+ allow(ChefUtils).to receive(:windows?).and_return(true)
end
it "should be called" do
diff --git a/spec/unit/cookbook/cookbook_version_loader_spec.rb b/spec/unit/cookbook/cookbook_version_loader_spec.rb
index c38af059f5..2cd86877cb 100644
--- a/spec/unit/cookbook/cookbook_version_loader_spec.rb
+++ b/spec/unit/cookbook/cookbook_version_loader_spec.rb
@@ -20,7 +20,7 @@ require "spec_helper"
describe Chef::Cookbook::CookbookVersionLoader do
before do
- allow(ChefConfig).to receive(:windows?) { false }
+ allow(ChefUtils).to receive(:windows?) { false }
end
describe "loading a cookbook" do
diff --git a/spec/unit/cookbook/syntax_check_spec.rb b/spec/unit/cookbook/syntax_check_spec.rb
index a24fa3ab2a..54dfab84b8 100644
--- a/spec/unit/cookbook/syntax_check_spec.rb
+++ b/spec/unit/cookbook/syntax_check_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Daniel DeLeo (<dan@chef.io>)
-# Copyright:: Copyright 2010-2016, Chef Software Inc.
+# Copyright:: Copyright 2010-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,7 +21,7 @@ require "chef/cookbook/syntax_check"
describe Chef::Cookbook::SyntaxCheck do
before do
- allow(ChefConfig).to receive(:windows?) { false }
+ allow(ChefUtils).to receive(:windows?) { false }
end
let(:cookbook_path) { File.join(CHEF_SPEC_DATA, "cookbooks", "openldap") }
diff --git a/spec/unit/cookbook_loader_spec.rb b/spec/unit/cookbook_loader_spec.rb
index a09bbd043f..f382c5d2dd 100644
--- a/spec/unit/cookbook_loader_spec.rb
+++ b/spec/unit/cookbook_loader_spec.rb
@@ -20,7 +20,7 @@ require "spec_helper"
describe Chef::CookbookLoader do
before do
- allow(ChefConfig).to receive(:windows?) { false }
+ allow(ChefUtils).to receive(:windows?) { false }
end
let(:repo_paths) do
[
diff --git a/spec/unit/data_bag_spec.rb b/spec/unit/data_bag_spec.rb
index 4b0ba42172..a0b6971efe 100644
--- a/spec/unit/data_bag_spec.rb
+++ b/spec/unit/data_bag_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Adam Jacob (<adam@chef.io>)
-# Copyright:: Copyright 2008-2016, Chef Software Inc.
+# Copyright:: Copyright 2008-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,7 +22,7 @@ require "chef/data_bag"
describe Chef::DataBag do
before(:each) do
@data_bag = Chef::DataBag.new
- allow(ChefConfig).to receive(:windows?) { false }
+ allow(ChefUtils).to receive(:windows?) { false }
end
describe "initialize" do
diff --git a/spec/unit/dsl/platform_introspection_spec.rb b/spec/unit/dsl/platform_introspection_spec.rb
index 7af233a769..227585a889 100644
--- a/spec/unit/dsl/platform_introspection_spec.rb
+++ b/spec/unit/dsl/platform_introspection_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Seth Falcon (<seth@chef.io>)
-# Copyright:: Copyright 2010-2016, Chef Software Inc.
+# Copyright:: Copyright 2010-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -127,3 +127,33 @@ describe Chef::DSL::PlatformIntrospection::PlatformFamilyDependentValue do
end
end
+
+describe "ChefHelper functions mixed into classes" do
+ METHODS = %i{windows? fedora_derived? bsd_based? rhel? aix? gentoo?}.freeze
+
+ METHODS.each do |method|
+ it "mixes #{method} into Chef::Resource instances" do
+ expect(Chef::Resource.instance_methods.include?(method)).to be true
+ end
+
+ it "mixes #{method} into Chef::Resource classes (provides lines, etc)" do
+ expect(Chef::Resource.respond_to?(method)).to be true
+ end
+
+ it "mixes #{method} into Chef::Provider instances (actions)" do
+ expect(Chef::Provider.instance_methods.include?(method)).to be true
+ end
+
+ it "mixes #{method} into Chef::Provider classes (provides lines, etc)" do
+ expect(Chef::Provider.respond_to?(method)).to be true
+ end
+
+ it "mixes #{method} into Chef::Recipe instances (recipe files)" do
+ expect(Chef::Recipe.instance_methods.include?(method)).to be true
+ end
+
+ it "mixes #{method} into Chef::Node instances (attribute files)" do
+ expect(Chef::Recipe.instance_methods.include?(method)).to be true
+ end
+ end
+end
diff --git a/spec/unit/file_content_management/deploy/mv_windows_spec.rb b/spec/unit/file_content_management/deploy/mv_windows_spec.rb
index 1aadf89d2d..51c3ff051e 100644
--- a/spec/unit/file_content_management/deploy/mv_windows_spec.rb
+++ b/spec/unit/file_content_management/deploy/mv_windows_spec.rb
@@ -18,7 +18,7 @@
require "spec_helper"
-unless Chef::Platform.windows?
+unless ChefUtils.windows?
class Chef
module ReservedNames
module Win32
diff --git a/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb b/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb
index 209d987e78..22ff5515f0 100644
--- a/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb
+++ b/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Daniel DeLeo (<dan@chef.io>)
-# Copyright:: Copyright 2012-2016, Chef Software Inc.
+# Copyright:: Copyright 2012-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/spec/unit/knife/core/gem_glob_loader_spec.rb b/spec/unit/knife/core/gem_glob_loader_spec.rb
index c8bd34d4a9..c761216733 100644
--- a/spec/unit/knife/core/gem_glob_loader_spec.rb
+++ b/spec/unit/knife/core/gem_glob_loader_spec.rb
@@ -23,7 +23,7 @@ describe Chef::Knife::SubcommandLoader::GemGlobLoader do
let(:plugin_dir) { File.join(home, ".chef", "plugins", "knife") }
before do
- allow(ChefConfig).to receive(:windows?) { false }
+ allow(ChefUtils).to receive(:windows?) { false }
Chef::Util::PathHelper.class_variable_set(:@@home_dir, home)
end
diff --git a/spec/unit/knife/core/hashed_command_loader_spec.rb b/spec/unit/knife/core/hashed_command_loader_spec.rb
index c463a36fb4..aa2ea3be51 100644
--- a/spec/unit/knife/core/hashed_command_loader_spec.rb
+++ b/spec/unit/knife/core/hashed_command_loader_spec.rb
@@ -19,7 +19,7 @@ require "spec_helper"
describe Chef::Knife::SubcommandLoader::HashedCommandLoader do
before do
- allow(ChefConfig).to receive(:windows?) { false }
+ allow(ChefUtils).to receive(:windows?) { false }
end
let(:plugin_manifest) do
diff --git a/spec/unit/knife/core/subcommand_loader_spec.rb b/spec/unit/knife/core/subcommand_loader_spec.rb
index 5db0bb73e5..3ab24d9a18 100644
--- a/spec/unit/knife/core/subcommand_loader_spec.rb
+++ b/spec/unit/knife/core/subcommand_loader_spec.rb
@@ -23,7 +23,7 @@ describe Chef::Knife::SubcommandLoader do
let(:plugin_dir) { File.join(home, ".chef", "plugins", "knife") }
before do
- allow(ChefConfig).to receive(:windows?) { false }
+ allow(ChefUtils).to receive(:windows?) { false }
Chef::Util::PathHelper.class_variable_set(:@@home_dir, home)
end
diff --git a/spec/unit/knife/core/ui_spec.rb b/spec/unit/knife/core/ui_spec.rb
index e5f19a4837..dfe906fdc1 100644
--- a/spec/unit/knife/core/ui_spec.rb
+++ b/spec/unit/knife/core/ui_spec.rb
@@ -3,7 +3,7 @@
# Author:: Tim Hinderliter (<tim@chef.io>)
# Author:: Daniel DeLeo (<dan@chef.io>)
# Author:: John Keiser (<jkeiser@chef.io>)
-# Copyright:: Copyright 2008-2017, Chef Software Inc.
+# Copyright:: Copyright 2008-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -482,7 +482,7 @@ describe Chef::Knife::UI do
before(:each) do
stdout = double("StringIO", tty?: true)
allow(@ui).to receive(:stdout).and_return(stdout)
- allow(ChefConfig).to receive(:windows?) { true }
+ allow(ChefUtils).to receive(:windows?) { true }
Chef::Config.reset
end
diff --git a/spec/unit/knife/data_bag_from_file_spec.rb b/spec/unit/knife/data_bag_from_file_spec.rb
index bc0ca330e8..86a60d858e 100644
--- a/spec/unit/knife/data_bag_from_file_spec.rb
+++ b/spec/unit/knife/data_bag_from_file_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Seth Falcon (<seth@chef.io>)
-# Copyright:: Copyright 2010-2016, Chef Software Inc.
+# Copyright:: Copyright 2010-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,7 +26,7 @@ Chef::Knife::DataBagFromFile.load_deps
describe Chef::Knife::DataBagFromFile do
before :each do
- allow(ChefConfig).to receive(:windows?) { false }
+ allow(ChefUtils).to receive(:windows?) { false }
Chef::Config[:node_name] = "webmonkey.example.com"
FileUtils.mkdir_p([db_folder, db_folder2])
db_file.write(Chef::JSONCompat.to_json(plain_data))
diff --git a/spec/unit/knife/environment_from_file_spec.rb b/spec/unit/knife/environment_from_file_spec.rb
index 11e05cb922..477db36a4c 100644
--- a/spec/unit/knife/environment_from_file_spec.rb
+++ b/spec/unit/knife/environment_from_file_spec.rb
@@ -1,7 +1,7 @@
#
# Author:: Stephen Delano (<stephen@ospcode.com>)
# Author:: Seth Falcon (<seth@ospcode.com>)
-# Copyright:: Copyright 2010-2016, Chef Software Inc.
+# Copyright:: Copyright 2010-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,7 +23,7 @@ Chef::Knife::EnvironmentFromFile.load_deps
describe Chef::Knife::EnvironmentFromFile do
before(:each) do
- allow(ChefConfig).to receive(:windows?) { false }
+ allow(ChefUtils).to receive(:windows?) { false }
@knife = Chef::Knife::EnvironmentFromFile.new
@stdout = StringIO.new
allow(@knife.ui).to receive(:stdout).and_return(@stdout)
diff --git a/spec/unit/knife/supermarket_install_spec.rb b/spec/unit/knife/supermarket_install_spec.rb
index 9c969106fc..3a43e78397 100644
--- a/spec/unit/knife/supermarket_install_spec.rb
+++ b/spec/unit/knife/supermarket_install_spec.rb
@@ -31,7 +31,7 @@ describe Chef::Knife::SupermarketInstall do
merge_updates_from: true)
end
let(:install_path) do
- if Chef::Platform.windows?
+ if ChefUtils.windows?
"C:/tmp/chef"
else
"/var/tmp/chef"
diff --git a/spec/unit/mash_spec.rb b/spec/unit/mash_spec.rb
deleted file mode 100644
index 0797e80f2c..0000000000
--- a/spec/unit/mash_spec.rb
+++ /dev/null
@@ -1,51 +0,0 @@
-#
-# Author:: Matthew Kent (<mkent@magoazul.com>)
-# Copyright:: Copyright 2011-2016, 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"
-require "chef/mash"
-
-describe Mash do
- it "should duplicate a simple key/value mash to a new mash" do
- data = { x: "one", y: "two", z: "three" }
- @orig = Mash.new(data)
- @copy = @orig.dup
- expect(@copy.to_hash).to eq(Mash.new(data).to_hash)
- @copy[:x] = "four"
- expect(@orig[:x]).to eq("one")
- end
-
- it "should duplicate a mash with an array to a new mash" do
- data = { x: "one", y: "two", z: [1, 2, 3] }
- @orig = Mash.new(data)
- @copy = @orig.dup
- expect(@copy.to_hash).to eq(Mash.new(data).to_hash)
- @copy[:z] << 4
- expect(@orig[:z]).to eq([1, 2, 3])
- end
-
- it "should duplicate a nested mash to a new mash" do
- data = { x: "one", y: "two", z: Mash.new({ a: [1, 2, 3] }) }
- @orig = Mash.new(data)
- @copy = @orig.dup
- expect(@copy.to_hash).to eq(Mash.new(data).to_hash)
- @copy[:z][:a] << 4
- expect(@orig[:z][:a]).to eq([1, 2, 3])
- end
-
- # add more!
-end
diff --git a/spec/unit/mixin/path_sanity_spec.rb b/spec/unit/mixin/path_sanity_spec.rb
index c9ed4e2595..ecea92c294 100644
--- a/spec/unit/mixin/path_sanity_spec.rb
+++ b/spec/unit/mixin/path_sanity_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Seth Chisamore (<schisamo@chef.io>)
-# Copyright:: Copyright 2011-2017, Chef Software Inc.
+# Copyright:: Copyright 2011-2019, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -35,7 +35,7 @@ describe Chef::Mixin::PathSanity do
@gem_bindir = "/some/gem/bin"
allow(Gem).to receive(:bindir).and_return(@gem_bindir)
allow(RbConfig::CONFIG).to receive(:[]).with("bindir").and_return(@ruby_bindir)
- allow(ChefConfig).to receive(:windows?).and_return(false)
+ allow(ChefUtils).to receive(:windows?).and_return(false)
end
it "adds all useful PATHs even if environment is an empty hash" do
@@ -83,7 +83,7 @@ describe Chef::Mixin::PathSanity do
gem_bindir = 'C:\gems\bin'
allow(Gem).to receive(:bindir).and_return(gem_bindir)
allow(RbConfig::CONFIG).to receive(:[]).with("bindir").and_return(ruby_bindir)
- allow(ChefConfig).to receive(:windows?).and_return(true)
+ allow(ChefUtils).to receive(:windows?).and_return(true)
env = { "PATH" => 'C:\Windows\system32;C:\mr\softie' }
@sanity.enforce_path_sanity(env)
expect(env["PATH"]).to eq("#{gem_bindir};#{ruby_bindir};C:\\Windows\\system32;C:\\mr\\softie")
diff --git a/spec/unit/mixin/shell_out_spec.rb b/spec/unit/mixin/shell_out_spec.rb
index 1c4f59b50b..afa3687a15 100644
--- a/spec/unit/mixin/shell_out_spec.rb
+++ b/spec/unit/mixin/shell_out_spec.rb
@@ -24,13 +24,12 @@ require "spec_helper"
require "chef/mixin/path_sanity"
describe Chef::Mixin::ShellOut do
- include Chef::Mixin::PathSanity
-
+ include ChefUtils::DSL::PathSanity
let(:shell_out_class) { Class.new { include Chef::Mixin::ShellOut } }
subject(:shell_out_obj) { shell_out_class.new }
def env_path
- if Chef::Platform.windows?
+ if ChefUtils.windows?
"Path"
else
"PATH"
diff --git a/spec/unit/mixin/template_spec.rb b/spec/unit/mixin/template_spec.rb
index 04071988ad..f629e7ee0f 100644
--- a/spec/unit/mixin/template_spec.rb
+++ b/spec/unit/mixin/template_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Adam Jacob (<adam@chef.io>)
-# Copyright:: Copyright 2008-2016, Chef Software Inc.
+# Copyright:: Copyright 2008-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,7 +21,7 @@ require "spec_helper"
require "cgi"
describe Chef::Mixin::Template, "render_template" do
- let(:sep) { Chef::Platform.windows? ? "\r\n" : "\n" }
+ let(:sep) { ChefUtils.windows? ? "\r\n" : "\n" }
before :each do
@context = Chef::Mixin::Template::TemplateContext.new({})
@@ -39,7 +39,7 @@ describe Chef::Mixin::Template, "render_template" do
describe "when running on windows" do
before do
- allow(ChefConfig).to receive(:windows?).and_return(true)
+ allow(ChefUtils).to receive(:windows?).and_return(true)
end
it "should render the templates with windows line endings" do
@@ -54,7 +54,7 @@ describe Chef::Mixin::Template, "render_template" do
describe "when running on unix" do
before do
- allow(ChefConfig).to receive(:windows?).and_return(false)
+ allow(ChefUtils).to receive(:windows?).and_return(false)
end
it "should render the templates with unix line endings" do
diff --git a/spec/unit/mixin/user_context_spec.rb b/spec/unit/mixin/user_context_spec.rb
index 31e182d042..c8add8a434 100644
--- a/spec/unit/mixin/user_context_spec.rb
+++ b/spec/unit/mixin/user_context_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Adam Edwards (<adamed@chef.io>)
-# Copyright:: Copyright (c) 2015 Chef Software, Inc.
+# Copyright:: Copyright (c) 2015-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -39,7 +39,7 @@ describe "a class that mixes in user_context" do
context "when running on Windows" do
before do
- allow(::Chef::Platform).to receive(:windows?).and_return(true)
+ allow(ChefUtils).to receive(:windows?).and_return(true)
allow(::Chef::Util::Windows::LogonSession).to receive(:new).and_return(logon_session)
end
@@ -97,7 +97,7 @@ describe "a class that mixes in user_context" do
context "when not running on Windows" do
before do
- allow(::Chef::Platform).to receive(:windows?).and_return(false)
+ allow(ChefUtils).to receive(:windows?).and_return(false)
end
it "raises a ::Chef::Exceptions::UnsupportedPlatform exception" do
diff --git a/spec/unit/node_map_spec.rb b/spec/unit/node_map_spec.rb
index 2b38f8cea5..444b297ea0 100644
--- a/spec/unit/node_map_spec.rb
+++ b/spec/unit/node_map_spec.rb
@@ -104,8 +104,8 @@ describe Chef::NodeMap do
end
it "returns nil when the platform_family does not match" do
- allow(node).to receive(:[]).with(:os).and_return("linux")
- allow(node).to receive(:[]).with(:platform_family).and_return("debian")
+ node.automatic["os"] = "linux"
+ node.automatic["platform_family"] = "debian"
expect(node_map.get(node, :thing)).to eql(nil)
end
end
@@ -174,26 +174,26 @@ describe Chef::NodeMap do
end
it "returns the value when the node matches" do
- allow(node).to receive(:[]).with(:platform_family).and_return("rhel")
- allow(node).to receive(:[]).with(:platform_version).and_return("7.0")
+ node.automatic["platform_family"] = "rhel"
+ node.automatic["platform_version"] = "7.0"
expect(node_map.get(node, :thing)).to eql(:foo)
end
it "returns nil when the block does not match" do
- allow(node).to receive(:[]).with(:platform_family).and_return("rhel")
- allow(node).to receive(:[]).with(:platform_version).and_return("6.4")
+ node.automatic["platform_family"] = "rhel"
+ node.automatic["platform_version"] = "6.4"
expect(node_map.get(node, :thing)).to eql(nil)
end
it "returns nil when the platform_family filter does not match" do
- allow(node).to receive(:[]).with(:platform_family).and_return("debian")
- allow(node).to receive(:[]).with(:platform_version).and_return("7.0")
+ node.automatic["platform_family"] = "debian"
+ node.automatic["platform_version"] = "7.0"
expect(node_map.get(node, :thing)).to eql(nil)
end
it "returns nil when both do not match" do
- allow(node).to receive(:[]).with(:platform_family).and_return("debian")
- allow(node).to receive(:[]).with(:platform_version).and_return("6.0")
+ node.automatic["platform_family"] = "debian"
+ node.automatic["platform_version"] = "6.0"
expect(node_map.get(node, :thing)).to eql(nil)
end
@@ -203,8 +203,8 @@ describe Chef::NodeMap do
end
it "returns the value when the node matches" do
- allow(node).to receive(:[]).with(:platform_family).and_return("rhel")
- allow(node).to receive(:[]).with(:platform_version).and_return("7.0")
+ node.automatic["platform_family"] = "rhel"
+ node.automatic["platform_version"] = "7.0"
expect(node_map.get(node, :thing)).to eql(:foo)
end
end
diff --git a/spec/unit/platform/query_helpers_spec.rb b/spec/unit/platform/query_helpers_spec.rb
index 22bfd150ee..d5e4d09029 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-2016, Chef Software, Inc.
+# Copyright:: Copyright 2014-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -43,13 +43,13 @@ describe "Chef::Platform#windows_nano_server?" do
end
it "returns false early when not on windows" do
- allow(ChefConfig).to receive(:windows?).and_return(false)
+ 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(ChefConfig).to receive(:windows?).and_return(true)
+ 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)
@@ -59,7 +59,7 @@ describe "Chef::Platform#windows_nano_server?" do
end
it "returns false when the registry value is not 1" do
- allow(ChefConfig).to receive(:windows?).and_return(true)
+ 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)
@@ -69,7 +69,7 @@ describe "Chef::Platform#windows_nano_server?" do
end
it "returns false when the registry value does not exist" do
- allow(ChefConfig).to receive(:windows?).and_return(true)
+ 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)
@@ -80,7 +80,7 @@ describe "Chef::Platform#windows_nano_server?" do
end
it "returns false when the registry key does not exist" do
- allow(ChefConfig).to receive(:windows?).and_return(true)
+ 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)
@@ -114,13 +114,13 @@ describe "Chef::Platform#supports_msi?" do
end
it "returns false early when not on windows" do
- allow(ChefConfig).to receive(:windows?).and_return(false)
+ 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(ChefConfig).to receive(:windows?).and_return(true)
+ 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)
@@ -129,7 +129,7 @@ describe "Chef::Platform#supports_msi?" do
end
it "returns false when the registry key does not exist" do
- allow(ChefConfig).to receive(:windows?).and_return(true)
+ 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)
diff --git a/spec/unit/provider/execute_spec.rb b/spec/unit/provider/execute_spec.rb
index 11eb70e396..60f2070c1c 100644
--- a/spec/unit/provider/execute_spec.rb
+++ b/spec/unit/provider/execute_spec.rb
@@ -42,7 +42,7 @@ describe Chef::Provider::Execute do
before do
allow(Chef::EventDispatch::EventsOutputStream).to receive(:new) { @live_stream }
- allow(ChefConfig).to receive(:windows?) { false }
+ allow(ChefUtils).to receive(:windows?) { false }
@original_log_level = Chef::Log.level
Chef::Log.level = :info
allow(STDOUT).to receive(:tty?).and_return(false)
diff --git a/spec/unit/provider/link_spec.rb b/spec/unit/provider/link_spec.rb
index fff2c1ffa8..154197e730 100644
--- a/spec/unit/provider/link_spec.rb
+++ b/spec/unit/provider/link_spec.rb
@@ -1,7 +1,7 @@
#
# Author:: AJ Christensen (<aj@junglist.gen.nz>)
# Author:: John Keiser (<jkeiser@chef.io>)
-# Copyright:: Copyright 2008-2016, Chef Software Inc.
+# Copyright:: Copyright 2008-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,7 +21,7 @@ require "ostruct"
require "spec_helper"
-if Chef::Platform.windows?
+if ChefUtils.windows?
require "chef/win32/file" # probably need this in spec_helper
end
@@ -41,7 +41,7 @@ describe Chef::Resource::Link do
end
def canonicalize(path)
- Chef::Platform.windows? ? path.tr("/", '\\') : path
+ ChefUtils.windows? ? path.tr("/", '\\') : path
end
describe "when the target is a symlink" do
@@ -359,7 +359,7 @@ describe Chef::Resource::Link do
provider.new_resource.name
).and_return(resource_link)
allow(resource_link).to receive(:verify_links_supported!)
- allow(Chef::Platform).to receive(:windows?).and_return(true)
+ allow(ChefUtils).to receive(:windows?).and_return(true)
end
context "soft links" do
@@ -389,7 +389,7 @@ describe Chef::Resource::Link do
context "on Linux platform" do
before(:each) do
- allow(Chef::Platform).to receive(:windows?).and_return(false)
+ allow(ChefUtils).to receive(:windows?).and_return(false)
end
context "soft links" do
diff --git a/spec/unit/provider/package/windows/exe_spec.rb b/spec/unit/provider/package/windows/exe_spec.rb
index 6e39ddc78a..2ed4c03905 100644
--- a/spec/unit/provider/package/windows/exe_spec.rb
+++ b/spec/unit/provider/package/windows/exe_spec.rb
@@ -19,7 +19,7 @@
require "spec_helper"
require "chef/provider/package/windows/exe"
-unless Chef::Platform.windows?
+unless ChefUtils.windows?
class Chef
module ReservedNames::Win32
class File
diff --git a/spec/unit/provider/package/windows_spec.rb b/spec/unit/provider/package/windows_spec.rb
index 2fafb3bd0e..ddb2448801 100644
--- a/spec/unit/provider/package/windows_spec.rb
+++ b/spec/unit/provider/package/windows_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Bryan McLellan <btm@loftninjas.org>
-# Copyright:: Copyright 2014-2017, Chef Software Inc.
+# Copyright:: Copyright 2014-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,7 +22,7 @@ require "chef/provider/package/windows/msi"
describe Chef::Provider::Package::Windows, :windows_only do
before(:each) do
- allow(Chef::Util::PathHelper).to receive(:windows?).and_return(true)
+ allow(ChefUtils).to receive(:windows?).and_return(true)
allow(Chef::FileCache).to receive(:create_cache_path).with("package/").and_return(cache_path)
end
diff --git a/spec/unit/provider/remote_file/fetcher_spec.rb b/spec/unit/provider/remote_file/fetcher_spec.rb
index b110e2c03a..254a9d36ec 100644
--- a/spec/unit/provider/remote_file/fetcher_spec.rb
+++ b/spec/unit/provider/remote_file/fetcher_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Lamont Granquist (<lamont@chef.io>)
-# Copyright:: Copyright 2013-2016, Chef Software Inc.
+# Copyright:: Copyright 2013-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -27,7 +27,7 @@ describe Chef::Provider::RemoteFile::Fetcher do
describe "when passed a network share" do
before do
expect(Chef::Provider::RemoteFile::NetworkFile).to receive(:new).and_return(fetcher_instance)
- allow(Chef::Platform).to receive(:windows?).and_return(true)
+ allow(ChefUtils).to receive(:windows?).and_return(true)
end
context "when host is a name" do
diff --git a/spec/unit/provider/remote_file/local_file_spec.rb b/spec/unit/provider/remote_file/local_file_spec.rb
index 6dad6a57f2..cfca09ad18 100644
--- a/spec/unit/provider/remote_file/local_file_spec.rb
+++ b/spec/unit/provider/remote_file/local_file_spec.rb
@@ -31,7 +31,7 @@ describe Chef::Provider::RemoteFile::LocalFile do
context "when parsing source path on windows" do
before do
- allow(Chef::Platform).to receive(:windows?).and_return(true)
+ allow(ChefUtils).to receive(:windows?).and_return(true)
end
describe "when given local unix path" do
diff --git a/spec/unit/provider/remote_file/network_file_spec.rb b/spec/unit/provider/remote_file/network_file_spec.rb
index 1c2bcc5911..5eb8c8e3e5 100644
--- a/spec/unit/provider/remote_file/network_file_spec.rb
+++ b/spec/unit/provider/remote_file/network_file_spec.rb
@@ -33,7 +33,7 @@ describe Chef::Provider::RemoteFile::NetworkFile do
let(:source_file) { double("::File", read: nil) }
before do
- allow(Chef::Platform).to receive(:windows?).and_return(true)
+ allow(ChefUtils).to receive(:windows?).and_return(true)
end
it "stages the local file to a temporary file" do
diff --git a/spec/unit/provider/script_spec.rb b/spec/unit/provider/script_spec.rb
index 08b19730a7..68d6bdb697 100644
--- a/spec/unit/provider/script_spec.rb
+++ b/spec/unit/provider/script_spec.rb
@@ -59,7 +59,7 @@ describe Chef::Provider::Script, "action_run" do
context "when configuring the script file's security" do
context "when not running on Windows" do
before do
- allow(::Chef::Platform).to receive(:windows?).and_return(false)
+ allow(ChefUtils).to receive(:windows?).and_return(false)
end
context "#set_owner_and_group" do
it "sets the owner and group for the script file" do
@@ -73,7 +73,7 @@ describe Chef::Provider::Script, "action_run" do
context "when running on Windows" do
before do
- allow(::Chef::Platform).to receive(:windows?).and_return(true)
+ allow(ChefUtils).to receive(:windows?).and_return(true)
expect(new_resource.user).to eq(nil)
stub_const("Chef::ReservedNames::Win32::API::Security::GENERIC_READ", 1)
stub_const("Chef::ReservedNames::Win32::API::Security::GENERIC_EXECUTE", 4)
diff --git a/spec/unit/provider/subversion_spec.rb b/spec/unit/provider/subversion_spec.rb
index a70b7cd48b..9f5ffacec6 100644
--- a/spec/unit/provider/subversion_spec.rb
+++ b/spec/unit/provider/subversion_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Daniel DeLeo (<dan@kallistec.com>)
-# Copyright:: Copyright 2008-2017, Chef Software Inc.
+# Copyright:: Copyright 2008-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -274,7 +274,7 @@ describe Chef::Provider::Subversion do
it "selects 'svn' as the binary by default" do
@resource.svn_binary nil
- allow(ChefConfig).to receive(:windows?) { false }
+ allow(ChefUtils).to receive(:windows?) { false }
expect(@provider).to receive(:svn_binary).and_return("svn")
expect(@provider.export_command).to eql(
"svn export --force -q -r12345 http://svn.example.org/trunk/ /my/deploy/dir"
@@ -283,7 +283,7 @@ describe Chef::Provider::Subversion do
it "selects an svn binary with an exe extension on windows" do
@resource.svn_binary nil
- allow(ChefConfig).to receive(:windows?) { true }
+ allow(ChefUtils).to receive(:windows?) { true }
expect(@provider).to receive(:svn_binary).and_return("svn.exe")
expect(@provider.export_command).to eql(
"svn.exe export --force -q -r12345 http://svn.example.org/trunk/ /my/deploy/dir"
diff --git a/spec/unit/provider/user/dscl_spec.rb b/spec/unit/provider/user/dscl_spec.rb
index e20873dc92..5ef47170c0 100644
--- a/spec/unit/provider/user/dscl_spec.rb
+++ b/spec/unit/provider/user/dscl_spec.rb
@@ -21,7 +21,7 @@ require "ostruct"
describe Chef::Provider::User::Dscl do
before do
- allow(ChefConfig).to receive(:windows?) { false }
+ allow(ChefUtils).to receive(:windows?) { false }
end
let(:shellcmdresult) { Struct.new(:stdout, :stderr, :exitstatus) }
diff --git a/spec/unit/provider_resolver_spec.rb b/spec/unit/provider_resolver_spec.rb
index 94e0d6074b..c8eb18b5b6 100644
--- a/spec/unit/provider_resolver_spec.rb
+++ b/spec/unit/provider_resolver_spec.rb
@@ -35,9 +35,8 @@ describe Chef::ProviderResolver do
# Root the filesystem under a temp directory so Chef.path_to will point at it
when_the_repository "is empty" do
before do
- allow(Chef).to receive(:path_to) { |path| File.join(path_to(""), path) }
+ allow(Chef::Resource::DnfPackage).to receive(:which).with("dnf").and_return(nil)
end
-
let(:resource_name) { :service }
let(:provider) { nil }
let(:action) { :start }
@@ -145,51 +144,36 @@ describe Chef::ProviderResolver do
describe "resolving service resource" do
def stub_service_providers(*services)
- services.each do |service|
- case service
- when :debian
- file "usr/sbin/update-rc.d", ""
- when :invokercd
- file "usr/sbin/invoke-rc.d", ""
- when :insserv
- file "sbin/insserv", ""
- when :upstart
- file "sbin/initctl", ""
- when :redhat
- file "sbin/chkconfig", ""
- when :systemd
- file "proc/1/comm", "systemd\n"
- else
- raise ArgumentError, service
- end
+ allowed = %i{debianrcd invokercd insserv upstart redhatrcd systemd}
+
+ (allowed - services).each do |api|
+ allow(Chef::Provider::Service).to receive(:"#{api}?").and_return(false)
+ end
+
+ raise ArgumentError unless (services - allowed).empty?
+
+ services.each do |api|
+ allow(Chef::Provider::Service).to receive(:"#{api}?").and_return(true)
end
end
def stub_service_configs(*configs)
- configs.each do |config|
- case config
- when :initd
- file "etc/init.d/#{service_name}", ""
- when :upstart
- file "etc/init/#{service_name}.conf", ""
- when :xinetd
- file "etc/xinetd.d/#{service_name}", ""
- when :etc_rcd
- file "etc/rc.d/#{service_name}", ""
- when :usr_local_etc_rcd
- file "usr/local/etc/rc.d/#{service_name}", ""
- when :systemd
- file "proc/1/comm", "systemd\n"
- file "etc/systemd/system/#{service_name}.service", ""
- else
- raise ArgumentError, config
- end
+ allowed = %i{initd upstart xinetd systemd etc_rcd}
+
+ (allowed - configs).each do |type|
+ allow(Chef::Provider::Service).to receive(:service_script_exist?).with(type, service_name).and_return(false)
+ end
+
+ raise ArgumentError unless (configs - allowed).empty?
+
+ configs.each do |type|
+ allow(Chef::Provider::Service).to receive(:service_script_exist?).with(type, service_name).and_return(true)
end
end
shared_examples_for "an ubuntu platform with upstart, update-rc.d and systemd" do
before do
- stub_service_providers(:debian, :invokercd, :upstart, :systemd)
+ stub_service_providers(:debianrcd, :invokercd, :upstart, :systemd)
end
it "when both the SysV init and Systemd script exists, it returns a Service::Debian provider" do
@@ -213,12 +197,12 @@ describe Chef::ProviderResolver do
end
it "when only the SysV init script exists, it returns a Service::Systemd provider" do
- stub_service_configs(:initd)
+ stub_service_configs(:initd, :systemd)
expect(resolved_provider).to eql(Chef::Provider::Service::Systemd)
end
it "when both SysV and Upstart scripts exist, it returns a Service::Systemd provider" do
- stub_service_configs(:initd, :upstart)
+ stub_service_configs(:initd, :systemd, :upstart)
expect(resolved_provider).to eql(Chef::Provider::Service::Systemd)
end
@@ -235,7 +219,7 @@ describe Chef::ProviderResolver do
shared_examples_for "an ubuntu platform with upstart and update-rc.d" do
before do
- stub_service_providers(:debian, :invokercd, :upstart)
+ stub_service_providers(:debianrcd, :invokercd, :upstart)
end
# needs to be handled by the highest priority init.d handler
@@ -362,7 +346,7 @@ describe Chef::ProviderResolver do
shared_examples_for "a debian platform using the insserv provider" do
context "with a default install" do
before do
- stub_service_providers(:debian, :invokercd, :insserv)
+ stub_service_providers(:debianrcd, :invokercd, :insserv)
end
it "uses the Service::Insserv Provider to manage sysv init scripts" do
@@ -378,7 +362,7 @@ describe Chef::ProviderResolver do
context "when the user has installed upstart" do
before do
- stub_service_providers(:debian, :invokercd, :insserv, :upstart)
+ stub_service_providers(:debianrcd, :invokercd, :insserv, :upstart)
end
it "when only the SysV init script exists, it returns an Insserv provider" do
@@ -407,8 +391,8 @@ describe Chef::ProviderResolver do
it_behaves_like "an ubuntu platform with upstart, update-rc.d and systemd"
it "when the unit-files are missing and system-ctl list-unit-files returns an error" do
- stub_service_providers(:debian, :invokercd, :upstart, :systemd)
- stub_service_configs(:initd, :upstart)
+ stub_service_providers(:debianrcd, :invokercd, :upstart, :systemd)
+ stub_service_configs(:initd, :upstart, :systemd)
mock_shellout_command("/bin/systemctl list-unit-files", exitstatus: 1)
expect(resolved_provider).to eql(Chef::Provider::Service::Systemd)
end
@@ -445,8 +429,8 @@ describe Chef::ProviderResolver do
it "always returns a Solaris provider" do
# no matter what we stub on the next two lines we should get a Solaris provider
- stub_service_providers(:debian, :invokercd, :insserv, :upstart, :redhat, :systemd)
- stub_service_configs(:initd, :upstart, :xinetd, :usr_local_etc_rcd, :systemd)
+ stub_service_providers(:debianrcd, :invokercd, :insserv, :upstart, :redhatrcd, :systemd)
+ stub_service_configs(:initd, :upstart, :xinetd, :systemd)
expect(resolved_provider).to eql(Chef::Provider::Service::Solaris)
end
end
@@ -460,8 +444,8 @@ describe Chef::ProviderResolver do
it "always returns a Windows provider" do
# no matter what we stub on the next two lines we should get a Windows provider
- stub_service_providers(:debian, :invokercd, :insserv, :upstart, :redhat, :systemd)
- stub_service_configs(:initd, :upstart, :xinetd, :usr_local_etc_rcd, :systemd)
+ stub_service_providers(:debianrcd, :invokercd, :insserv, :upstart, :redhatrcd, :systemd)
+ stub_service_configs(:initd, :upstart, :xinetd, :systemd)
expect(resolved_provider).to eql(Chef::Provider::Service::Windows)
end
end
@@ -475,8 +459,8 @@ describe Chef::ProviderResolver do
it "always returns a Macosx provider" do
# no matter what we stub on the next two lines we should get a Macosx provider
- stub_service_providers(:debian, :invokercd, :insserv, :upstart, :redhat, :systemd)
- stub_service_configs(:initd, :upstart, :xinetd, :usr_local_etc_rcd, :systemd)
+ stub_service_providers(:debianrcd, :invokercd, :insserv, :upstart, :redhatrcd, :systemd)
+ stub_service_configs(:initd, :upstart, :xinetd, :systemd)
expect(resolved_provider).to eql(Chef::Provider::Service::Macosx)
end
end
@@ -484,7 +468,6 @@ describe Chef::ProviderResolver do
on_platform "freebsd", os: "freebsd", platform_version: "10.3" do
it "returns a Freebsd provider if it finds the /usr/local/etc/rc.d initscript" do
stub_service_providers
- stub_service_configs(:usr_local_etc_rcd)
expect(resolved_provider).to eql(Chef::Provider::Service::Freebsd)
end
@@ -495,15 +478,14 @@ describe Chef::ProviderResolver do
end
it "always returns a Freebsd provider if it finds the /usr/local/etc/rc.d initscript" do
- # should only care about :usr_local_etc_rcd stub in the service configs
- stub_service_providers(:debian, :invokercd, :insserv, :upstart, :redhat, :systemd)
- stub_service_configs(:usr_local_etc_rcd, :initd, :upstart, :xinetd, :systemd)
+ stub_service_providers(:debianrcd, :invokercd, :insserv, :upstart, :redhatrcd, :systemd)
+ stub_service_configs(:initd, :upstart, :xinetd, :systemd)
expect(resolved_provider).to eql(Chef::Provider::Service::Freebsd)
end
it "always returns a Freebsd provider if it finds the /usr/local/etc/rc.d initscript" do
# should only care about :etc_rcd stub in the service configs
- stub_service_providers(:debian, :invokercd, :insserv, :upstart, :redhat, :systemd)
+ stub_service_providers(:debianrcd, :invokercd, :insserv, :upstart, :redhatrcd, :systemd)
stub_service_configs(:etc_rcd, :initd, :upstart, :xinetd, :systemd)
expect(resolved_provider).to eql(Chef::Provider::Service::Freebsd)
end
@@ -518,7 +500,6 @@ describe Chef::ProviderResolver do
on_platform "netbsd", os: "netbsd", platform_version: "7.0.1" do
it "returns a Freebsd provider if it finds the /usr/local/etc/rc.d initscript" do
stub_service_providers
- stub_service_configs(:usr_local_etc_rcd)
expect(resolved_provider).to eql(Chef::Provider::Service::Freebsd)
end
@@ -529,15 +510,14 @@ describe Chef::ProviderResolver do
end
it "always returns a Freebsd provider if it finds the /usr/local/etc/rc.d initscript" do
- # should only care about :usr_local_etc_rcd stub in the service configs
- stub_service_providers(:debian, :invokercd, :insserv, :upstart, :redhat, :systemd)
- stub_service_configs(:usr_local_etc_rcd, :initd, :upstart, :xinetd, :systemd)
+ stub_service_providers(:debianrcd, :invokercd, :insserv, :upstart, :redhatrcd, :systemd)
+ stub_service_configs(:initd, :upstart, :xinetd, :systemd)
expect(resolved_provider).to eql(Chef::Provider::Service::Freebsd)
end
it "always returns a Freebsd provider if it finds the /usr/local/etc/rc.d initscript" do
# should only care about :etc_rcd stub in the service configs
- stub_service_providers(:debian, :invokercd, :insserv, :upstart, :redhat, :systemd)
+ stub_service_providers(:debianrcd, :invokercd, :insserv, :upstart, :redhatrcd, :systemd)
stub_service_configs(:etc_rcd, :initd, :upstart, :xinetd, :systemd)
expect(resolved_provider).to eql(Chef::Provider::Service::Freebsd)
end
diff --git a/spec/unit/resource/cookbook_file_spec.rb b/spec/unit/resource/cookbook_file_spec.rb
index b35233649d..655cebaf01 100644
--- a/spec/unit/resource/cookbook_file_spec.rb
+++ b/spec/unit/resource/cookbook_file_spec.rb
@@ -53,7 +53,7 @@ describe Chef::Resource::CookbookFile do
describe "when it has a backup number, group, mode, owner, source, checksum, and cookbook on nix or path, rights, deny_rights, checksum on windows" do
before do
- if Chef::Platform.windows?
+ if ChefUtils.windows?
resource.path("C:/temp/origin/file.txt")
resource.rights(:read, "Everyone")
resource.deny_rights(:full_control, "Clumsy_Sam")
@@ -70,7 +70,7 @@ describe Chef::Resource::CookbookFile do
it "describes the state" do
state = resource.state_for_resource_reporter
- if Chef::Platform.windows?
+ if ChefUtils.windows?
puts state
expect(state[:rights]).to eq([{ permissions: :read, principals: "Everyone" }])
expect(state[:deny_rights]).to eq([{ permissions: :full_control, principals: "Clumsy_Sam" }])
@@ -83,7 +83,7 @@ describe Chef::Resource::CookbookFile do
end
it "returns the path as its identity" do
- if Chef::Platform.windows?
+ if ChefUtils.windows?
expect(resource.identity).to eq("C:/temp/origin/file.txt")
else
expect(resource.identity).to eq("/tmp/origin/file.txt")
diff --git a/spec/unit/resource/remote_file_spec.rb b/spec/unit/resource/remote_file_spec.rb
index 39d34d9a96..27b889ea9e 100644
--- a/spec/unit/resource/remote_file_spec.rb
+++ b/spec/unit/resource/remote_file_spec.rb
@@ -181,7 +181,7 @@ describe Chef::Resource::RemoteFile do
describe "when it has group, mode, owner, source, and checksum" do
before do
- if Chef::Platform.windows?
+ if ChefUtils.windows?
resource.path("C:/temp/origin/file.txt")
resource.rights(:read, "Everyone")
resource.deny_rights(:full_control, "Clumsy_Sam")
@@ -197,7 +197,7 @@ describe Chef::Resource::RemoteFile do
it "describes its state" do
state = resource.state_for_resource_reporter
- if Chef::Platform.windows?
+ if ChefUtils.windows?
puts state
expect(state[:rights]).to eq([{ permissions: :read, principals: "Everyone" }])
expect(state[:deny_rights]).to eq([{ permissions: :full_control, principals: "Clumsy_Sam" }])
@@ -210,7 +210,7 @@ describe Chef::Resource::RemoteFile do
end
it "returns the path as its identity" do
- if Chef::Platform.windows?
+ if ChefUtils.windows?
expect(resource.identity).to eq("C:/temp/origin/file.txt")
else
expect(resource.identity).to eq("/this/path/")
diff --git a/spec/unit/role_spec.rb b/spec/unit/role_spec.rb
index 13932ab3ee..8a67913d60 100644
--- a/spec/unit/role_spec.rb
+++ b/spec/unit/role_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Adam Jacob (<adam@chef.io>)
-# Copyright:: Copyright 2008-2016, Chef Software Inc.
+# Copyright:: Copyright 2008-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,7 +21,7 @@ require "chef/role"
describe Chef::Role do
before(:each) do
- allow(ChefConfig).to receive(:windows?) { false }
+ allow(ChefUtils).to receive(:windows?) { false }
@role = Chef::Role.new
@role.name("ops_master")
end
diff --git a/spec/unit/shell_spec.rb b/spec/unit/shell_spec.rb
index aa573706b1..6dba848084 100644
--- a/spec/unit/shell_spec.rb
+++ b/spec/unit/shell_spec.rb
@@ -42,7 +42,7 @@ describe Shell do
before do
Shell.irb_conf = {}
allow(Shell::ShellSession.instance).to receive(:reset!)
- allow(ChefConfig).to receive(:windows?).and_return(false)
+ allow(ChefUtils).to receive(:windows?).and_return(false)
allow(Chef::Util::PathHelper).to receive(:home).and_return("/home/foo")
end
diff --git a/spec/unit/util/selinux_spec.rb b/spec/unit/util/selinux_spec.rb
index 0d2d1aeb3f..18774aee2c 100644
--- a/spec/unit/util/selinux_spec.rb
+++ b/spec/unit/util/selinux_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Serdar Sutay (<serdar@chef.io>)
-# Copyright:: Copyright 2013-2018, Chef Software Inc.
+# Copyright:: Copyright 2013-2019, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -41,7 +41,7 @@ describe Chef::Util::Selinux do
it "each part of ENV['PATH'] should be checked" do
expected_paths = ENV["PATH"].split(File::PATH_SEPARATOR) + [ "/bin", "/usr/bin", "/sbin", "/usr/sbin" ]
- expected_paths.each do |bin_path|
+ expected_paths.uniq.each do |bin_path|
selinux_path = File.join(bin_path, "selinuxenabled")
expect(File).to receive(:executable?).with(selinux_path).and_return(false)
end
diff --git a/spec/unit/win32/error_spec.rb b/spec/unit/win32/error_spec.rb
index 316303ab4f..8980293be7 100644
--- a/spec/unit/win32/error_spec.rb
+++ b/spec/unit/win32/error_spec.rb
@@ -17,7 +17,7 @@
#
require "spec_helper"
-if Chef::Platform.windows?
+if ChefUtils.windows?
require "chef/win32/error"
require "chef/win32/api/error"
end
diff --git a/spec/unit/win32/link_spec.rb b/spec/unit/win32/link_spec.rb
index 5f749c034e..de7b165dd0 100644
--- a/spec/unit/win32/link_spec.rb
+++ b/spec/unit/win32/link_spec.rb
@@ -16,7 +16,7 @@
#
require "spec_helper"
-if Chef::Platform.windows?
+if ChefUtils.windows?
require "chef/win32/api/file"
require "chef/win32/file"
require "chef/win32/version"
diff --git a/spec/unit/win32/security_spec.rb b/spec/unit/win32/security_spec.rb
index efbb290adf..6dc330dddd 100644
--- a/spec/unit/win32/security_spec.rb
+++ b/spec/unit/win32/security_spec.rb
@@ -17,7 +17,7 @@
#
require "spec_helper"
-if Chef::Platform.windows?
+if ChefUtils.windows?
require "chef/win32/error"
require "chef/win32/security"
require "chef/win32/api/error"
diff --git a/spec/unit/windows_service_spec.rb b/spec/unit/windows_service_spec.rb
index 45af0f9d9f..d046b67c5b 100644
--- a/spec/unit/windows_service_spec.rb
+++ b/spec/unit/windows_service_spec.rb
@@ -16,7 +16,7 @@
# limitations under the License.
#
require "spec_helper"
-if Chef::Platform.windows?
+if ChefUtils.windows?
require "chef/application/windows_service"
end