diff options
115 files changed, 1467 insertions, 441 deletions
diff --git a/.expeditor/config.yml b/.expeditor/config.yml index 9bdabf7510..30f46c99f4 100644 --- a/.expeditor/config.yml +++ b/.expeditor/config.yml @@ -18,6 +18,9 @@ rubygems: docker_images: - chef +habitat_packages: + - chef-client + github: # The file where the MAJOR.MINOR.PATCH version is kept. The version in this file # is bumped automatically via the `built_in:bump_version` merge_action. @@ -56,6 +59,12 @@ merge_actions: - "Meta: Exclude From Changelog" - "Expeditor: Exclude From Changelog" - "Expeditor: Skip All" + - built_in:trigger_habitat_package_build: + ignore_labels: + - "Omnibus: Skip Build" + - "Expeditor: Skip Build" + - "Expeditor: Skip All" + only_if: built_in:bump_version - built_in:trigger_omnibus_release_build: ignore_labels: - "Omnibus: Skip Build" diff --git a/CHANGELOG.md b/CHANGELOG.md index 330696d04a..8e72ba9e25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,23 @@ <!-- usage documentation: http://expeditor-docs.es.chef.io/configuration/changelog/ --> -<!-- latest_release --> +<!-- latest_release 14.1.18 --> +## [v14.1.18](https://github.com/chef/chef/tree/v14.1.18) (2018-05-18) + +#### Merged Pull Requests +- object validation for DataHandlerBase#normalize_hash [#7264](https://github.com/chef/chef/pull/7264) ([jeremymv2](https://github.com/jeremymv2)) <!-- latest_release --> -<!-- release_rollup --> +<!-- release_rollup since=14.1.12 --> +### Changes since 14.1.12 release + +#### Merged Pull Requests +- object validation for DataHandlerBase#normalize_hash [#7264](https://github.com/chef/chef/pull/7264) ([jeremymv2](https://github.com/jeremymv2)) <!-- 14.1.18 --> +- [MSYS-817] fix for windows_task does not parse backslashes in the commad property [#7281](https://github.com/chef/chef/pull/7281) ([Vasu1105](https://github.com/Vasu1105)) <!-- 14.1.17 --> +- UID now starts at 501, uses createhomedir instead [#4903](https://github.com/chef/chef/pull/4903) ([nmcspadden](https://github.com/nmcspadden)) <!-- 14.1.16 --> +- Add default_action to the resource inspector [#7276](https://github.com/chef/chef/pull/7276) ([tas50](https://github.com/tas50)) <!-- 14.1.15 --> +- Add additional resource unit tests [#7275](https://github.com/chef/chef/pull/7275) ([tas50](https://github.com/tas50)) <!-- 14.1.14 --> +- Add additional unit tests for resource actions/properties [#7266](https://github.com/chef/chef/pull/7266) ([tas50](https://github.com/tas50)) <!-- 14.1.14 --> +- improved regex accuracy lib/chef/resource/hostname.rb [#7262](https://github.com/chef/chef/pull/7262) ([bottkv488](https://github.com/bottkv488)) <!-- 14.1.14 --> +- publish habitat packages [#7272](https://github.com/chef/chef/pull/7272) ([thommay](https://github.com/thommay)) <!-- 14.1.13 --> <!-- release_rollup --> <!-- latest_stable_release --> diff --git a/Gemfile.lock b/Gemfile.lock index 79b703084e..bf853350eb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -15,10 +15,10 @@ GIT PATH remote: . specs: - chef (14.1.12) + chef (14.1.18) addressable bundler (>= 1.10) - chef-config (= 14.1.12) + chef-config (= 14.1.18) chef-zero (>= 13.0) diff-lcs (~> 1.2, >= 1.2.4) erubis (~> 2.7) @@ -46,10 +46,10 @@ PATH specinfra (~> 2.10) syslog-logger (~> 1.6) uuidtools (~> 2.1.5) - chef (14.1.12-universal-mingw32) + chef (14.1.18-universal-mingw32) addressable bundler (>= 1.10) - chef-config (= 14.1.12) + chef-config (= 14.1.18) chef-zero (>= 13.0) diff-lcs (~> 1.2, >= 1.2.4) erubis (~> 2.7) @@ -92,7 +92,7 @@ PATH PATH remote: chef-config specs: - chef-config (14.1.12) + chef-config (14.1.18) addressable fuzzyurl mixlib-config (~> 2.0) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 4e26819de6..c43c18feed 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,5 +1,22 @@ This file holds "in progress" release notes for the current release under development and is intended for consumption by the Chef Documentation team. Please see <https://docs.chef.io/release_notes.html> for the official Chef release notes. +# Chef Client Release Notes 14.1.12: + +This release resolves a number of regressions in 14.1: + +- `git` resource: don't use `--prune-tags` as it's really new. +- `rhsm_repo` resource: now works +- `apt_repository` resource: use the `repo_name` property to name files +- `windows_task` resource: properly handle commands with arguments +- `windows_task` resource: handle creating tasks as the SYSTEM user +- `remote_directory` resource: restore the default for the `overwrite` property + +## Ohai 14.1.3 + +- Properly detect FIPS environments +- `shard` plugin: work in FIPS compliant environments +- `filesystem` plugin: Handle BSD platforms + # Chef Client Release Notes 14.1.1: ## Platform Additions @@ -1 +1 @@ -14.1.12
\ No newline at end of file +14.1.18
\ No newline at end of file diff --git a/chef-config/lib/chef-config/config.rb b/chef-config/lib/chef-config/config.rb index ef792b2db7..612033b30c 100644 --- a/chef-config/lib/chef-config/config.rb +++ b/chef-config/lib/chef-config/config.rb @@ -1087,6 +1087,9 @@ module ChefConfig # can be set to a string or array of strings for URIs to set as rubygems sources default :rubygems_url, "https://www.rubygems.org" + # globally sets the default of the clear_sources property on the gem_package and chef_gem resources + default :clear_gem_sources, false + # If installed via an omnibus installer, this gives the path to the # "embedded" directory which contains all of the software packaged with # omnibus. This is used to locate the cacert.pem file on windows. diff --git a/chef-config/lib/chef-config/version.rb b/chef-config/lib/chef-config/version.rb index ab69569572..2632db07c9 100644 --- a/chef-config/lib/chef-config/version.rb +++ b/chef-config/lib/chef-config/version.rb @@ -21,7 +21,7 @@ module ChefConfig CHEFCONFIG_ROOT = File.expand_path("../..", __FILE__) - VERSION = "14.1.12" + VERSION = "14.1.18" end # diff --git a/lib/chef/chef_fs/data_handler/data_handler_base.rb b/lib/chef/chef_fs/data_handler/data_handler_base.rb index 4b4696ce5e..c3cbb96ecc 100644 --- a/lib/chef/chef_fs/data_handler/data_handler_base.rb +++ b/lib/chef/chef_fs/data_handler/data_handler_base.rb @@ -63,11 +63,15 @@ class Chef def normalize_hash(object, defaults) # Make a normalized result in the specified order for diffing result = {} - defaults.each_pair do |key, default| - result[key] = object.has_key?(key) ? object[key] : default + defaults.each_pair do |key, value| + result[key] = object.is_a?(Hash) && object.key?(key) ? object[key] : value end - object.each_pair do |key, value| - result[key] = value if !result.has_key?(key) + if object.is_a?(Hash) + object.each_pair do |key, value| + result[key] = value unless result.key?(key) + end + else + Chef::Log.warn "Encountered invalid object during normalization. Using these defaults #{defaults}" end result end diff --git a/lib/chef/provider/user/dscl.rb b/lib/chef/provider/user/dscl.rb index 50d255db8b..79a2c73339 100644 --- a/lib/chef/provider/user/dscl.rb +++ b/lib/chef/provider/user/dscl.rb @@ -214,7 +214,7 @@ user password using shadow hash.") # # Sets the user id for the user using dscl. # If a `uid` is not specified, it finds the next available one starting - # from 200 if `system` is set, 500 otherwise. + # from 200 if `system` is set, 501 otherwise. # def dscl_set_uid # XXX: mutates the new resource @@ -229,11 +229,11 @@ user password using shadow hash.") # # Find the next available uid on the system. starting with 200 if `system` is set, - # 500 otherwise. + # 501 otherwise. # def get_free_uid(search_limit = 1000) uid = nil - base_uid = new_resource.system ? 200 : 500 + base_uid = new_resource.system ? 200 : 501 next_uid_guess = base_uid users_uids = run_dscl("list", "/Users", "uid") while next_uid_guess < search_limit + base_uid @@ -326,10 +326,7 @@ user password using shadow hash.") end def ditto_home - skel = "/System/Library/User Template/English.lproj" - raise(Chef::Exceptions::User, "can't find skel at: #{skel}") unless ::File.exist?(skel) - shell_out_compact!("ditto", skel, new_resource.home) - ::FileUtils.chown_R(new_resource.username, new_resource.gid.to_s, new_resource.home) + shell_out_compact!("/usr/sbin/createhomedir", "-c", "-u", "#{new_resource.username}") end def move_home diff --git a/lib/chef/provider/windows_task.rb b/lib/chef/provider/windows_task.rb index c9109d6996..0bb28c66c6 100644 --- a/lib/chef/provider/windows_task.rb +++ b/lib/chef/provider/windows_task.rb @@ -231,6 +231,7 @@ class Chef # seprated command arguments from :command property def set_command_and_arguments + new_resource.command = new_resource.command.gsub(/\\/, '\&\&') cmd, *args = Shellwords.split(new_resource.command) new_resource.command = cmd new_resource.command_arguments = args.join(" ") diff --git a/lib/chef/resource/gem_package.rb b/lib/chef/resource/gem_package.rb index ee1262cb47..f2e1867322 100644 --- a/lib/chef/resource/gem_package.rb +++ b/lib/chef/resource/gem_package.rb @@ -40,7 +40,7 @@ class Chef # FIXME? the array form of installing paths most likely does not work? # property :source, [ String, Array ] - property :clear_sources, [ TrueClass, FalseClass ], default: false, desired_state: false + property :clear_sources, [ TrueClass, FalseClass ], default: lazy { Chef::Config[:clear_gem_sources] }, desired_state: false # Sets a custom gem_binary to run for gem commands. property :gem_binary, String, desired_state: false diff --git a/lib/chef/resource/hostname.rb b/lib/chef/resource/hostname.rb index 243c86287b..878f502dae 100644 --- a/lib/chef/resource/hostname.rb +++ b/lib/chef/resource/hostname.rb @@ -116,7 +116,7 @@ class Chef # this must come before other methods like /etc/hostname and /etc/sysconfig/network declare_resource(:execute, "hostnamectl set-hostname #{new_resource.hostname}") do notifies :reload, "ohai[reload hostname]" - not_if { shell_out!("hostnamectl status", { :returns => [0, 1] }).stdout =~ /Static hostname:\s+#{new_resource.hostname}/ } + not_if { shell_out!("hostnamectl status", { :returns => [0, 1] }).stdout =~ /Static hostname:\s*#{new_resource.hostname}\s*$/ } end when ::File.exist?("/etc/hostname") # debian family uses /etc/hostname diff --git a/lib/chef/resource_inspector.rb b/lib/chef/resource_inspector.rb index b112cb0565..f4c745c080 100644 --- a/lib/chef/resource_inspector.rb +++ b/lib/chef/resource_inspector.rb @@ -28,6 +28,7 @@ module ResourceInspector data = {} data[:description] = resource.description # data[:deprecated] = resource.deprecated || false + data[:default_action] = resource.default_action data[:actions] = resource.allowed_actions data[:examples] = resource.examples data[:introduced] = resource.introduced diff --git a/lib/chef/version.rb b/lib/chef/version.rb index 326e4154a4..fba5724222 100644 --- a/lib/chef/version.rb +++ b/lib/chef/version.rb @@ -23,7 +23,7 @@ require "chef/version_string" class Chef CHEF_ROOT = File.expand_path("../..", __FILE__) - VERSION = Chef::VersionString.new("14.1.12") + VERSION = Chef::VersionString.new("14.1.18") end # diff --git a/spec/functional/resource/windows_task_spec.rb b/spec/functional/resource/windows_task_spec.rb index d4a2bcc14e..65a396cf56 100644 --- a/spec/functional/resource/windows_task_spec.rb +++ b/spec/functional/resource/windows_task_spec.rb @@ -68,7 +68,7 @@ describe Chef::Resource::WindowsTask, :windows_only do current_resource = call_for_load_current_resource expect(current_resource.exists).to eq(true) expect(current_resource.task.application_name).to eq("chef-client") - expect(current_resource.task.parameters).to eq("-W -L C:\\chef\\chef-ad-join.log") + expect(current_resource.task.parameters).to eq("-W -L C:\\\\chef\\\\chef-ad-join.log") end it "does not converge the resource if it is already converged" do diff --git a/spec/support/shared/unit/execute_resource.rb b/spec/support/shared/unit/execute_resource.rb index c15b02612e..c97577107e 100644 --- a/spec/support/shared/unit/execute_resource.rb +++ b/spec/support/shared/unit/execute_resource.rb @@ -22,7 +22,7 @@ require "spec_helper" shared_examples_for "an execute resource" do before(:each) do - @resource = execute_resource + @resource = resource end it "should create a new Chef::Resource::Execute" do diff --git a/spec/unit/chef_fs/data_handler/data_handler_base_spec.rb b/spec/unit/chef_fs/data_handler/data_handler_base_spec.rb new file mode 100644 index 0000000000..a5d177c878 --- /dev/null +++ b/spec/unit/chef_fs/data_handler/data_handler_base_spec.rb @@ -0,0 +1,65 @@ +# +# Author:: Jeremy Miller (<jm@chef.io>) +# Copyright:: Copyright 2014-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" +require "lib/chef/chef_fs/data_handler/data_handler_base" + +describe Chef::ChefFS::DataHandler::DataHandlerBase do + describe "#normalize_hash" do + let(:some_item) do + { "name" => "grizzly", + "gender" => "female", + "age" => 3, + "food" => "honey" + } + end + + let(:item_defaults) do + { "family" => "ursidae", + "hibernate" => true, + "food" => "berries", + "avg_lifespan_years" => 22 + } + end + + let(:normalized) do + { "name" => "grizzly", + "gender" => "female", + "family" => "ursidae", + "hibernate" => true, + "avg_lifespan_years" => 22, + "age" => 3, + "food" => "honey" + } + end + + let(:handler) { described_class.new } + + it "normalizes the Hash, filling in default values" do + expect(handler.normalize_hash(some_item, item_defaults)).to eq(normalized) + end + + it "prefers already existing values over default values" do + expect(handler.normalize_hash(some_item, item_defaults)["food"]).to eq("honey") + end + + it "handles being passed a nil value instead of Hash" do + expect(handler.normalize_hash(nil, item_defaults)).to eq(item_defaults) + end + end +end diff --git a/spec/unit/provider/user/dscl_spec.rb b/spec/unit/provider/user/dscl_spec.rb index 956c32664d..1019a9ae0f 100644 --- a/spec/unit/provider/user/dscl_spec.rb +++ b/spec/unit/provider/user/dscl_spec.rb @@ -283,15 +283,8 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" provider.dscl_set_home end - it "should raise an exception when the systems user template dir (skel) cannot be found" do - allow(::File).to receive(:exist?).and_return(false, false, false) - expect { provider.dscl_set_home }.to raise_error(Chef::Exceptions::User) - end - - it "should run ditto to copy any missing files from skel to the new home dir" do - expect(::File).to receive(:exist?).with("/System/Library/User\ Template/English.lproj").and_return(true) - expect(FileUtils).to receive(:chown_R).with("toor", "", "/Users/toor") - expect(provider).to receive(:shell_out!).with("ditto", "/System/Library/User Template/English.lproj", "/Users/toor") + it "should run createhomedir to create the user's new home folder" do + expect(provider).to receive(:shell_out!).with("/usr/sbin/createhomedir", "-c", "-u", "toor") provider.ditto_home end diff --git a/spec/unit/resource/apt_package_spec.rb b/spec/unit/resource/apt_package_spec.rb index 3b399059a6..66fe05ef33 100644 --- a/spec/unit/resource/apt_package_spec.rb +++ b/spec/unit/resource/apt_package_spec.rb @@ -31,6 +31,20 @@ describe Chef::Resource::AptPackage, "initialize" do let(:resource) { Chef::Resource::AptPackage.new("foo") } + it "sets the default action as :install" do + expect(resource.action).to eql([:install]) + end + + it "supports :install, :lock, :purge, :reconfig, :remove, :unlock, :upgrade actions" do + expect { resource.action :install }.not_to raise_error + expect { resource.action :lock }.not_to raise_error + expect { resource.action :purge }.not_to raise_error + expect { resource.action :reconfig }.not_to raise_error + expect { resource.action :remove }.not_to raise_error + expect { resource.action :unlock }.not_to raise_error + expect { resource.action :upgrade }.not_to raise_error + end + it "supports default_release" do resource.default_release("lenny-backports") expect(resource.default_release).to eql("lenny-backports") diff --git a/spec/unit/resource/apt_preference_spec.rb b/spec/unit/resource/apt_preference_spec.rb index 1d3be99f44..c7ab8d2409 100644 --- a/spec/unit/resource/apt_preference_spec.rb +++ b/spec/unit/resource/apt_preference_spec.rb @@ -22,7 +22,20 @@ describe Chef::Resource::AptPreference do let(:node) { Chef::Node.new } let(:events) { Chef::EventDispatch::Dispatcher.new } let(:run_context) { Chef::RunContext.new(node, {}, events) } - let(:resource) { Chef::Resource::AptPreference.new("libmysqlclient16", run_context) } + let(:resource) { Chef::Resource::AptPreference.new("fakey_fakerton", run_context) } + + it "the package_name property is the name_property" do + expect(resource.package_name).to eql("fakey_fakerton") + end + + it "sets the default action as :add" do + expect(resource.action).to eql([:add]) + end + + it "supports :add, :remove actions" do + expect { resource.action :add }.not_to raise_error + expect { resource.action :remove }.not_to raise_error + end it "resolves to a Noop class when on non-linux OS" do node.automatic[:os] = "windows" diff --git a/spec/unit/resource/apt_repository_spec.rb b/spec/unit/resource/apt_repository_spec.rb index bbc80a95c1..5b88d130f1 100644 --- a/spec/unit/resource/apt_repository_spec.rb +++ b/spec/unit/resource/apt_repository_spec.rb @@ -25,14 +25,23 @@ describe Chef::Resource::AptRepository do empty_events = Chef::EventDispatch::Dispatcher.new Chef::RunContext.new(node, {}, empty_events) end - let(:resource) { Chef::Resource::AptRepository.new("multiverse", run_context) } + let(:resource) { Chef::Resource::AptRepository.new("fakey_fakerton", run_context) } it "keyserver defaults to keyserver.ubuntu.com" do expect(resource.keyserver).to eql("keyserver.ubuntu.com") end - it "repo_name is the name property" do - expect(resource.repo_name).to eql("multiverse") + it "the repo_name property is the name_property" do + expect(resource.repo_name).to eql("fakey_fakerton") + end + + it "sets the default action as :add" do + expect(resource.action).to eql([:add]) + end + + it "supports :add, :remove actions" do + expect { resource.action :add }.not_to raise_error + expect { resource.action :remove }.not_to raise_error end it "distribution defaults to the distro codename" do diff --git a/spec/unit/resource/apt_update_spec.rb b/spec/unit/resource/apt_update_spec.rb index c872061140..d3a3c2d456 100644 --- a/spec/unit/resource/apt_update_spec.rb +++ b/spec/unit/resource/apt_update_spec.rb @@ -24,6 +24,15 @@ describe Chef::Resource::AptUpdate do let(:run_context) { Chef::RunContext.new(node, {}, events) } let(:resource) { Chef::Resource::AptUpdate.new("update", run_context) } + it "sets the default action as :periodic" do + expect(resource.action).to eql([:periodic]) + end + + it "supports :periodic, :update actions" do + expect { resource.action :periodic }.not_to raise_error + expect { resource.action :update }.not_to raise_error + end + it "default frequency is set to be 1 day" do expect(resource.frequency).to eql(86_400) end diff --git a/spec/unit/resource/bash_spec.rb b/spec/unit/resource/bash_spec.rb index 10482002db..6bd0f6df91 100644 --- a/spec/unit/resource/bash_spec.rb +++ b/spec/unit/resource/bash_spec.rb @@ -34,4 +34,12 @@ describe Chef::Resource::Bash do expect(resource.interpreter).to eql("bash") end + it "sets the default action as :run" do + expect(resource.action).to eql([:run]) + end + + it "supports :run action" do + expect { resource.action :run }.not_to raise_error + end + end diff --git a/spec/unit/resource/bff_package_spec.rb b/spec/unit/resource/bff_package_spec.rb new file mode 100644 index 0000000000..8862c8ecaf --- /dev/null +++ b/spec/unit/resource/bff_package_spec.rb @@ -0,0 +1,51 @@ +# +# Author:: Tim Smith (<tsmith@chef.io>) +# 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" +require "support/shared/unit/resource/static_provider_resolution" + +describe Chef::Resource::BffPackage, "initialize" do + + static_provider_resolution( + resource: Chef::Resource::BffPackage, + provider: Chef::Provider::Package::Bff, + name: :bff_package, + action: :install, + os: "linux", + platform_family: "aix" + ) + +end + +describe Chef::Resource::BffPackage, "defaults" do + let(:resource) { Chef::Resource::BffPackage.new("fakey_fakerton") } + + it "sets the default action as :install" do + expect(resource.action).to eql([:install]) + end + + it "supports :install, :lock, :purge, :reconfig, :remove, :unlock, :upgrade actions" do + expect { resource.action :install }.not_to raise_error + expect { resource.action :lock }.not_to raise_error + expect { resource.action :purge }.not_to raise_error + expect { resource.action :reconfig }.not_to raise_error + expect { resource.action :remove }.not_to raise_error + expect { resource.action :unlock }.not_to raise_error + expect { resource.action :upgrade }.not_to raise_error + end +end diff --git a/spec/unit/resource/breakpoint_spec.rb b/spec/unit/resource/breakpoint_spec.rb index ce0df676dd..8b415fa8c1 100644 --- a/spec/unit/resource/breakpoint_spec.rb +++ b/spec/unit/resource/breakpoint_spec.rb @@ -48,12 +48,12 @@ describe Chef::Resource::Breakpoint do provider.action_break end - it "allows the action :break" do - expect(resource.allowed_actions).to include(:break) + it "sets the default action as :break" do + expect(resource.action).to eql([:break]) end - it "defaults to the break action" do - expect(resource.action).to eq([:break]) + it "supports :break action" do + expect { resource.action :break }.not_to raise_error end it "names itself after the line number of the file where it's created" do diff --git a/spec/unit/resource/build_essential_spec.rb b/spec/unit/resource/build_essential_spec.rb index 5c25d3e961..0043b08a5c 100644 --- a/spec/unit/resource/build_essential_spec.rb +++ b/spec/unit/resource/build_essential_spec.rb @@ -25,10 +25,14 @@ describe Chef::Resource::BuildEssential do expect(resource.resource_name).to eql(:build_essential) end - it "has a default action of install" do + it "sets the default action as :install" do expect(resource.action).to eql([:install]) end + it "supports :install action" do + expect { resource.action :install }.not_to raise_error + end + context "when not settting a resource name" do let(:resource) { Chef::Resource::BuildEssential.new(nil) } diff --git a/spec/unit/resource/cab_package_spec.rb b/spec/unit/resource/cab_package_spec.rb index 87de446dd3..7e80abf41a 100644 --- a/spec/unit/resource/cab_package_spec.rb +++ b/spec/unit/resource/cab_package_spec.rb @@ -34,6 +34,16 @@ describe Chef::Resource::CabPackage do expect(resource.action).to eql([:install]) end + it "supports :install, :lock, :purge, :reconfig, :remove, :unlock, :upgrade actions" do + expect { resource.action :install }.not_to raise_error + expect { resource.action :lock }.not_to raise_error + expect { resource.action :purge }.not_to raise_error + expect { resource.action :reconfig }.not_to raise_error + expect { resource.action :remove }.not_to raise_error + expect { resource.action :unlock }.not_to raise_error + expect { resource.action :upgrade }.not_to raise_error + end + it "coerces name property to package_name property" do expect(resource.package_name).to eql("test_pkg") end diff --git a/spec/unit/resource/chef_gem_spec.rb b/spec/unit/resource/chef_gem_spec.rb index 0eac98c7d2..d4c94b0ac7 100644 --- a/spec/unit/resource/chef_gem_spec.rb +++ b/spec/unit/resource/chef_gem_spec.rb @@ -34,6 +34,20 @@ end describe Chef::Resource::ChefGem, "gem_binary" do let(:resource) { Chef::Resource::ChefGem.new("foo") } + it "sets the default action as :install" do + expect(resource.action).to eql([:install]) + end + + it "supports :install, :lock, :purge, :reconfig, :remove, :unlock, :upgrade actions" do + expect { resource.action :install }.not_to raise_error + expect { resource.action :lock }.not_to raise_error + expect { resource.action :purge }.not_to raise_error + expect { resource.action :reconfig }.not_to raise_error + expect { resource.action :remove }.not_to raise_error + expect { resource.action :unlock }.not_to raise_error + expect { resource.action :upgrade }.not_to raise_error + end + it "raises an exception when gem_binary is set" do expect { resource.gem_binary("/lol/cats/gem") }.to raise_error(ArgumentError) end diff --git a/spec/unit/resource/chef_handler_spec.rb b/spec/unit/resource/chef_handler_spec.rb index 7cba0c7fe3..491b29ce28 100644 --- a/spec/unit/resource/chef_handler_spec.rb +++ b/spec/unit/resource/chef_handler_spec.rb @@ -19,17 +19,22 @@ require "spec_helper" describe Chef::Resource::ChefHandler do - let(:resource) { Chef::Resource::ChefHandler.new("foo") } + let(:resource) { Chef::Resource::ChefHandler.new("fakey_fakerton") } it "has a resource name of :chef_handler" do expect(resource.resource_name).to eql(:chef_handler) end - it "has a default action of enable" do + it "the class_name property is the name_property" do + expect(resource.class_name).to eql("fakey_fakerton") + end + + it "sets the default action as :enable" do expect(resource.action).to eql([:enable]) end - it "the class_name property is the name property" do - expect(resource.class_name).to eql("foo") + it "supports :disable, :enable actions" do + expect { resource.action :disable }.not_to raise_error + expect { resource.action :enable }.not_to raise_error end end diff --git a/spec/unit/resource/chocolatey_package_spec.rb b/spec/unit/resource/chocolatey_package_spec.rb index 452373b571..6dce2c0e69 100644 --- a/spec/unit/resource/chocolatey_package_spec.rb +++ b/spec/unit/resource/chocolatey_package_spec.rb @@ -26,10 +26,24 @@ describe Chef::Resource::ChocolateyPackage do expect(resource).to be_a_kind_of(Chef::Resource::Package) end - it "has a resource name of :python" do + it "has a resource name of :chocolatey_package" do expect(resource.resource_name).to eql(:chocolatey_package) end + it "sets the default action as :install" do + expect(resource.action).to eql([:install]) + end + + it "supports :install, :lock, :purge, :reconfig, :remove, :unlock, :upgrade actions" do + expect { resource.action :install }.not_to raise_error + expect { resource.action :lock }.not_to raise_error + expect { resource.action :purge }.not_to raise_error + expect { resource.action :reconfig }.not_to raise_error + expect { resource.action :remove }.not_to raise_error + expect { resource.action :unlock }.not_to raise_error + expect { resource.action :upgrade }.not_to raise_error + end + it "coerces its name to a package_name array" do expect(resource.package_name).to eql(["fakey_fakerton"]) end diff --git a/spec/unit/resource/cookbook_file_spec.rb b/spec/unit/resource/cookbook_file_spec.rb index c6fdab3a1f..734fc152c1 100644 --- a/spec/unit/resource/cookbook_file_spec.rb +++ b/spec/unit/resource/cookbook_file_spec.rb @@ -22,12 +22,23 @@ require "spec_helper" describe Chef::Resource::CookbookFile do let(:resource) { Chef::Resource::CookbookFile.new("/foo/bar/sourcecode_tarball.tgz") } - it "uses the basepath of the resourc ename for the source property" do + it "sets the default action as :create" do + expect(resource.action).to eql([:create]) + end + + it "supports :create, :create_if_missing, :delete, :touch actions" do + expect { resource.action :create }.not_to raise_error + expect { resource.action :create_if_missing }.not_to raise_error + expect { resource.action :delete }.not_to raise_error + expect { resource.action :touch }.not_to raise_error + end + + it "uses the basepath of the resource name for the source property" do expect(resource.source).to eq("sourcecode_tarball.tgz") end it "source property accepts Strings" do - resource.name("config_file.conf") + resource.source("config_file.conf") expect(resource.source).to eq("config_file.conf") end diff --git a/spec/unit/resource/cron_spec.rb b/spec/unit/resource/cron_spec.rb index 91e0b05908..11a9e9d524 100644 --- a/spec/unit/resource/cron_spec.rb +++ b/spec/unit/resource/cron_spec.rb @@ -22,18 +22,13 @@ require "spec_helper" describe Chef::Resource::Cron do let(:resource) { Chef::Resource::Cron.new("cronify") } - it "has a name property" do - expect(resource.name).to eql("cronify") - end - - it "has a default action of [:create]" do + it "sets the default action as :create" do expect(resource.action).to eql([:create]) end - it "accepts create or delete for action" do + it "supports :create, :delete actions" do expect { resource.action :create }.not_to raise_error expect { resource.action :delete }.not_to raise_error - expect { resource.action :lolcat }.to raise_error(ArgumentError) end it "allows you to set a command" do diff --git a/spec/unit/resource/csh_spec.rb b/spec/unit/resource/csh_spec.rb index 3391bf84cf..cdb6ecec2a 100644 --- a/spec/unit/resource/csh_spec.rb +++ b/spec/unit/resource/csh_spec.rb @@ -30,6 +30,14 @@ describe Chef::Resource::Csh do expect(resource.resource_name).to eql(:csh) end + it "sets the default action as :run" do + expect(resource.action).to eql([:run]) + end + + it "supports :run action" do + expect { resource.action :run }.not_to raise_error + end + it "has an interpreter of csh" do expect(resource.interpreter).to eql("csh") end diff --git a/spec/unit/resource/directory_spec.rb b/spec/unit/resource/directory_spec.rb index 778e54ccb6..3dd68211db 100644 --- a/spec/unit/resource/directory_spec.rb +++ b/spec/unit/resource/directory_spec.rb @@ -22,22 +22,17 @@ require "spec_helper" describe Chef::Resource::Directory do let(:resource) { Chef::Resource::Directory.new("fakey_fakerton") } - it "has a name property" do - expect(resource.name).to eql("fakey_fakerton") + it "the path property is the name_property" do + expect(resource.path).to eql("fakey_fakerton") end - it "has a default action of 'create'" do + it "sets the default action as :create" do expect(resource.action).to eql([:create]) end - it "accepts create or delete for action" do + it "supports :create, :delete actions" do expect { resource.action :create }.not_to raise_error expect { resource.action :delete }.not_to raise_error - expect { resource.action :blues }.to raise_error(ArgumentError) - end - - it "uses the object name as the path by default" do - expect(resource.path).to eql("fakey_fakerton") end it "accepts a string as the path" do diff --git a/spec/unit/resource/dmg_package_spec.rb b/spec/unit/resource/dmg_package_spec.rb index d1d8a71188..d01262fa2d 100644 --- a/spec/unit/resource/dmg_package_spec.rb +++ b/spec/unit/resource/dmg_package_spec.rb @@ -19,17 +19,21 @@ require "spec_helper" describe Chef::Resource::DmgPackage do - let(:resource) { Chef::Resource::DmgPackage.new("myapp") } + let(:resource) { Chef::Resource::DmgPackage.new("fakey_fakerton") } it "has a resource name of :dmg_package" do expect(resource.resource_name).to eql(:dmg_package) end - it "has a default action of install" do + it "the app property is the name_property" do + expect(resource.app).to eql("fakey_fakerton") + end + + it "sets the default action as :install" do expect(resource.action).to eql([:install]) end - it "the app property is the name property" do - expect(resource.app).to eql("myapp") + it "supports :install action" do + expect { resource.action :install }.not_to raise_error end end diff --git a/spec/unit/resource/dnf_package_spec.rb b/spec/unit/resource/dnf_package_spec.rb index 21979b05c3..1b90fd3a0d 100644 --- a/spec/unit/resource/dnf_package_spec.rb +++ b/spec/unit/resource/dnf_package_spec.rb @@ -31,13 +31,28 @@ describe Chef::Resource::DnfPackage, "initialize" do end -describe Chef::Resource::DnfPackage, "arch" do +describe Chef::Resource::DnfPackage, "defaults" do let(:resource) { Chef::Resource::DnfPackage.new("foo") } it "sets the arch variable to whatever is passed in" do resource.arch("i386") expect(resource.arch).to eql(["i386"]) end + + it "sets the default action as :install" do + expect(resource.action).to eql([:install]) + end + + it "supports :flush_cache, :install, :lock, :purge, :reconfig, :remove, :unlock, :upgrade actions" do + expect { resource.action :flush_cache }.not_to raise_error + expect { resource.action :install }.not_to raise_error + expect { resource.action :lock }.not_to raise_error + expect { resource.action :purge }.not_to raise_error + expect { resource.action :reconfig }.not_to raise_error + expect { resource.action :remove }.not_to raise_error + expect { resource.action :unlock }.not_to raise_error + expect { resource.action :upgrade }.not_to raise_error + end end describe Chef::Resource::DnfPackage, "flush_cache" do diff --git a/spec/unit/resource/dpkg_package_spec.rb b/spec/unit/resource/dpkg_package_spec.rb index 66ad86b861..ff32d7e413 100644 --- a/spec/unit/resource/dpkg_package_spec.rb +++ b/spec/unit/resource/dpkg_package_spec.rb @@ -29,4 +29,22 @@ describe Chef::Resource::DpkgPackage, "initialize" do os: "linux" ) + describe Chef::Resource::DpkgPackage, "defaults" do + let(:resource) { Chef::Resource::DpkgPackage.new("fakey_fakerton") } + + it "sets the default action as :install" do + expect(resource.action).to eql([:install]) + end + + it "supports :install, :lock, :purge, :reconfig, :remove, :unlock, :upgrade actions" do + expect { resource.action :install }.not_to raise_error + expect { resource.action :lock }.not_to raise_error + expect { resource.action :purge }.not_to raise_error + expect { resource.action :reconfig }.not_to raise_error + expect { resource.action :remove }.not_to raise_error + expect { resource.action :unlock }.not_to raise_error + expect { resource.action :upgrade }.not_to raise_error + end + end + end diff --git a/spec/unit/resource/dsc_resource_spec.rb b/spec/unit/resource/dsc_resource_spec.rb index b687811392..22c42aa441 100644 --- a/spec/unit/resource/dsc_resource_spec.rb +++ b/spec/unit/resource/dsc_resource_spec.rb @@ -40,31 +40,31 @@ describe Chef::Resource::DscResource do expect(dsc_test_resource.action).to eq([:run]) end - it "has an ed_actions attribute with only the `:run` and `:nothing` attributes" do + it "has an ed_actions property with only the `:run` and `:nothing` properties" do expect(dsc_test_resource.allowed_actions.to_set).to eq([:run, :nothing].to_set) end - it "allows the resource attribute to be set" do + it "allows the resource property to be set" do dsc_test_resource.resource(dsc_test_resource_name) expect(dsc_test_resource.resource).to eq(dsc_test_resource_name) end - it "allows the module_name attribute to be set" do + it "allows the module_name property to be set" do dsc_test_resource.module_name(dsc_test_resource_name) expect(dsc_test_resource.module_name).to eq(dsc_test_resource_name) end - it "allows the module_version attribute to be set" do + it "allows the module_version property to be set" do dsc_test_resource.module_version(dsc_test_resource_module_version) expect(dsc_test_resource.module_version).to eq(dsc_test_resource_module_version) end - it "allows the reboot_action attribute to be set" do + it "allows the reboot_action property to be set" do dsc_test_resource.reboot_action(dsc_test_reboot_action) expect(dsc_test_resource.reboot_action).to eq(dsc_test_reboot_action) end - it "allows the timeout attribute to be set" do + it "allows the timeout property to be set" do dsc_test_resource.timeout(dsc_test_timeout) expect(dsc_test_resource.timeout).to eq(dsc_test_timeout) end diff --git a/spec/unit/resource/dsc_script_spec.rb b/spec/unit/resource/dsc_script_spec.rb index f0c81e43b5..d5ebcaca5c 100644 --- a/spec/unit/resource/dsc_script_spec.rb +++ b/spec/unit/resource/dsc_script_spec.rb @@ -19,7 +19,7 @@ require "spec_helper" describe Chef::Resource::DscScript do - let(:dsc_test_resource_name) { "DSCTest" } + let(:resource_name) { "DSCTest" } context "when Powershell supports Dsc" do let(:dsc_test_run_context) do @@ -28,8 +28,8 @@ describe Chef::Resource::DscScript do empty_events = Chef::EventDispatch::Dispatcher.new Chef::RunContext.new(node, {}, empty_events) end - let(:dsc_test_resource) do - Chef::Resource::DscScript.new(dsc_test_resource_name, dsc_test_run_context) + let(:resource) do + Chef::Resource::DscScript.new(resource_name, dsc_test_run_context) end let(:configuration_code) { 'echo "This is supposed to create a configuration document."' } let(:configuration_path) { "c:/myconfigs/formatc.ps1" } @@ -37,41 +37,41 @@ describe Chef::Resource::DscScript do let(:configuration_data) { '@{AllNodes = @( @{ NodeName = "localhost"; PSDscAllowPlainTextPassword = $true })}' } let(:configuration_data_script) { "c:/myconfigs/data/safedata.psd1" } - it "has a default action of `:run`" do - expect(dsc_test_resource.action).to eq([:run]) + it "sets the default action as :run" do + expect(resource.action).to eql([:run]) end - it "has an allowed_actions attribute with only the `:run` and `:nothing` attributes" do - expect(dsc_test_resource.allowed_actions.to_set).to eq([:run, :nothing].to_set) + it "supports :run action" do + expect { resource.action :run }.not_to raise_error end it "allows the code attribute to be set" do - dsc_test_resource.code(configuration_code) - expect(dsc_test_resource.code).to eq(configuration_code) + resource.code(configuration_code) + expect(resource.code).to eq(configuration_code) end it "allows the command attribute to be set" do - dsc_test_resource.command(configuration_path) - expect(dsc_test_resource.command).to eq(configuration_path) + resource.command(configuration_path) + expect(resource.command).to eq(configuration_path) end it "allows the configuration_name attribute to be set" do - dsc_test_resource.configuration_name(configuration_name) - expect(dsc_test_resource.configuration_name).to eq(configuration_name) + resource.configuration_name(configuration_name) + expect(resource.configuration_name).to eq(configuration_name) end it "allows the configuration_data attribute to be set" do - dsc_test_resource.configuration_data(configuration_data) - expect(dsc_test_resource.configuration_data).to eq(configuration_data) + resource.configuration_data(configuration_data) + expect(resource.configuration_data).to eq(configuration_data) end it "allows the configuration_data_script attribute to be set" do - dsc_test_resource.configuration_data_script(configuration_data_script) - expect(dsc_test_resource.configuration_data_script).to eq(configuration_data_script) + resource.configuration_data_script(configuration_data_script) + expect(resource.configuration_data_script).to eq(configuration_data_script) end it "has the ps_credential helper method" do - expect(dsc_test_resource).to respond_to(:ps_credential) + expect(resource).to respond_to(:ps_credential) end context "when calling imports" do @@ -80,55 +80,55 @@ describe Chef::Resource::DscScript do let(:dsc_resources) { %w{ResourceA ResourceB} } it "allows an arbitrary number of resources to be set for a module to be set" do - dsc_test_resource.imports module_name, *dsc_resources - module_imports = dsc_test_resource.imports[module_name] + resource.imports module_name, *dsc_resources + module_imports = resource.imports[module_name] expect(module_imports).to eq(dsc_resources) end it "adds * to the imports when no resources are set for a moudle" do - dsc_test_resource.imports module_name - module_imports = dsc_test_resource.imports[module_name] + resource.imports module_name + module_imports = resource.imports[module_name] expect(module_imports).to eq(["*"]) end it "allows an arbitrary number of modules" do - dsc_test_resource.imports module_name - dsc_test_resource.imports module_name_b - expect(dsc_test_resource.imports).to have_key(module_name) - expect(dsc_test_resource.imports).to have_key(module_name_b) + resource.imports module_name + resource.imports module_name_b + expect(resource.imports).to have_key(module_name) + expect(resource.imports).to have_key(module_name_b) end it "allows resources to be added for a module" do - dsc_test_resource.imports module_name, dsc_resources[0] - dsc_test_resource.imports module_name, dsc_resources[1] - module_imports = dsc_test_resource.imports[module_name] + resource.imports module_name, dsc_resources[0] + resource.imports module_name, dsc_resources[1] + module_imports = resource.imports[module_name] expect(module_imports).to eq(dsc_resources) end end it "raises an ArgumentError exception if an attempt is made to set the code attribute when the command attribute is already set" do - dsc_test_resource.command(configuration_path) - expect { dsc_test_resource.code(configuration_code) }.to raise_error(ArgumentError) + resource.command(configuration_path) + expect { resource.code(configuration_code) }.to raise_error(ArgumentError) end it "raises an ArgumentError exception if an attempt is made to set the command attribute when the code attribute is already set" do - dsc_test_resource.code(configuration_code) - expect { dsc_test_resource.command(configuration_path) }.to raise_error(ArgumentError) + resource.code(configuration_code) + expect { resource.command(configuration_path) }.to raise_error(ArgumentError) end it "raises an ArgumentError exception if an attempt is made to set the configuration_name attribute when the code attribute is already set" do - dsc_test_resource.code(configuration_code) - expect { dsc_test_resource.configuration_name(configuration_name) }.to raise_error(ArgumentError) + resource.code(configuration_code) + expect { resource.configuration_name(configuration_name) }.to raise_error(ArgumentError) end it "raises an ArgumentError exception if an attempt is made to set the configuration_data attribute when the configuration_data_script attribute is already set" do - dsc_test_resource.configuration_data_script(configuration_data_script) - expect { dsc_test_resource.configuration_data(configuration_data) }.to raise_error(ArgumentError) + resource.configuration_data_script(configuration_data_script) + expect { resource.configuration_data(configuration_data) }.to raise_error(ArgumentError) end it "raises an ArgumentError exception if an attempt is made to set the configuration_data_script attribute when the configuration_data attribute is already set" do - dsc_test_resource.configuration_data(configuration_data) - expect { dsc_test_resource.configuration_data_script(configuration_data_script) }.to raise_error(ArgumentError) + resource.configuration_data(configuration_data) + expect { resource.configuration_data_script(configuration_data_script) }.to raise_error(ArgumentError) end end end diff --git a/spec/unit/resource/execute_spec.rb b/spec/unit/resource/execute_spec.rb index c99e87b351..947f6c608e 100644 --- a/spec/unit/resource/execute_spec.rb +++ b/spec/unit/resource/execute_spec.rb @@ -21,15 +21,23 @@ require "spec_helper" describe Chef::Resource::Execute do let(:resource_instance_name) { "some command" } - let(:execute_resource) { Chef::Resource::Execute.new(resource_instance_name) } + let(:resource) { Chef::Resource::Execute.new(resource_instance_name) } it_behaves_like "an execute resource" + it "sets the default action as :run" do + expect(resource.action).to eql([:run]) + end + + it "supports :run action" do + expect { resource.action :run }.not_to raise_error + end + it "default guard interpreter is :execute interpreter" do - expect(execute_resource.guard_interpreter).to be(:execute) + expect(resource.guard_interpreter).to be(:execute) end it "defaults to not being a guard interpreter" do - expect(execute_resource.is_guard_interpreter).to eq(false) + expect(resource.is_guard_interpreter).to eq(false) end describe "#qualify_user" do @@ -40,7 +48,7 @@ describe Chef::Resource::Execute do let(:username) { "user@domain" } it "correctly parses the user and domain" do - identity = execute_resource.qualify_user(username, password, domain) + identity = resource.qualify_user(username, password, domain) expect(identity[:domain]).to eq("domain") expect(identity[:user]).to eq("user") end @@ -50,7 +58,7 @@ describe Chef::Resource::Execute do let(:username) { "domain\\user" } it "correctly parses the user and domain" do - identity = execute_resource.qualify_user(username, password, domain) + identity = resource.qualify_user(username, password, domain) expect(identity[:domain]).to eq("domain") expect(identity[:user]).to eq("user") end @@ -60,14 +68,14 @@ describe Chef::Resource::Execute do shared_examples_for "it received valid credentials" do describe "the validation method" do it "does not raise an error" do - expect { execute_resource.validate_identity_platform(username, password, domain) }.not_to raise_error + expect { resource.validate_identity_platform(username, password, domain) }.not_to raise_error end end describe "the name qualification method" do it "correctly translates the user and domain" do identity = nil - expect { identity = execute_resource.qualify_user(username, password, domain) }.not_to raise_error + expect { identity = resource.qualify_user(username, password, domain) }.not_to raise_error expect(identity[:domain]).to eq(domain) expect(identity[:user]).to eq(username) end @@ -77,7 +85,7 @@ describe Chef::Resource::Execute do shared_examples_for "it received invalid credentials" do describe "the validation method" do it "raises an error" do - expect { execute_resource.validate_identity_platform(username, password, domain, elevated) }.to raise_error(ArgumentError) + expect { resource.validate_identity_platform(username, password, domain, elevated) }.to raise_error(ArgumentError) end end end @@ -85,7 +93,7 @@ describe Chef::Resource::Execute do shared_examples_for "it received invalid username and domain" do describe "the validation method" do it "raises an error" do - expect { execute_resource.qualify_user(username, password, domain) }.to raise_error(ArgumentError) + expect { resource.qualify_user(username, password, domain) }.to raise_error(ArgumentError) end end end @@ -93,7 +101,7 @@ describe Chef::Resource::Execute do shared_examples_for "it received credentials that are not valid on the platform" do describe "the validation method" do it "raises an error" do - expect { execute_resource.validate_identity_platform(username, password, domain) }.to raise_error(Chef::Exceptions::UnsupportedPlatform) + expect { resource.validate_identity_platform(username, password, domain) }.to raise_error(Chef::Exceptions::UnsupportedPlatform) end end end @@ -101,7 +109,7 @@ describe Chef::Resource::Execute do shared_examples_for "a consumer of the Execute resource" do context "when running on Windows" do before do - allow(execute_resource).to receive(:node).and_return({ :platform_family => "windows" }) + allow(resource).to receive(:node).and_return({ :platform_family => "windows" }) end context "when no user, domain, or password is specified" do @@ -203,7 +211,7 @@ describe Chef::Resource::Execute do context "when not running on Windows" do before do - allow(execute_resource).to receive(:node).and_return({ :platform_family => "ubuntu" }) + allow(resource).to receive(:node).and_return({ :platform_family => "ubuntu" }) end context "when no user, domain, or password is specified" do diff --git a/spec/unit/resource/file_spec.rb b/spec/unit/resource/file_spec.rb index f2dea066ad..7e9b96616a 100644 --- a/spec/unit/resource/file_spec.rb +++ b/spec/unit/resource/file_spec.rb @@ -22,14 +22,21 @@ describe Chef::Resource::File do let(:resource) { Chef::Resource::File.new("fakey_fakerton") } - it "has a name property" do - expect(resource.name).to eql("fakey_fakerton") + it "the path property is the name_property" do + expect(resource.path).to eql("fakey_fakerton") end - it "has a default action of 'create'" do + it "sets the default action as :create" do expect(resource.action).to eql([:create]) end + it "supports :create, :create_if_missing, :delete, :touch actions" do + expect { resource.action :create }.not_to raise_error + expect { resource.action :create_if_missing }.not_to raise_error + expect { resource.action :delete }.not_to raise_error + expect { resource.action :touch }.not_to raise_error + end + it "has a default content of nil" do expect(resource.content).to be_nil end @@ -57,13 +64,6 @@ describe Chef::Resource::File do expect { resource.checksum "monkey!" }.to raise_error(ArgumentError) end - it "accepts create, delete or touch for action" do - expect { resource.action :create }.not_to raise_error - expect { resource.action :delete }.not_to raise_error - expect { resource.action :touch }.not_to raise_error - expect { resource.action :blues }.to raise_error(ArgumentError) - end - it "accepts a block, symbol, or string for verify" do expect { resource.verify {} }.not_to raise_error expect { resource.verify "" }.not_to raise_error diff --git a/spec/unit/resource/freebsd_package_spec.rb b/spec/unit/resource/freebsd_package_spec.rb index 4a223eb507..b609284895 100644 --- a/spec/unit/resource/freebsd_package_spec.rb +++ b/spec/unit/resource/freebsd_package_spec.rb @@ -42,6 +42,22 @@ describe Chef::Resource::FreebsdPackage do end end + describe "Actions" do + it "sets the default action as :install" do + expect(resource.action).to eql([:install]) + end + + it "supports :install, :lock, :purge, :reconfig, :remove, :unlock, :upgrade actions" do + expect { resource.action :install }.not_to raise_error + expect { resource.action :lock }.not_to raise_error + expect { resource.action :purge }.not_to raise_error + expect { resource.action :reconfig }.not_to raise_error + expect { resource.action :remove }.not_to raise_error + expect { resource.action :unlock }.not_to raise_error + expect { resource.action :upgrade }.not_to raise_error + end + end + describe "Assigning provider after creation" do describe "if ports specified as source" do it "is Freebsd::Port" do diff --git a/spec/unit/resource/gem_package_spec.rb b/spec/unit/resource/gem_package_spec.rb index bee7ba9de4..aba6ab1032 100644 --- a/spec/unit/resource/gem_package_spec.rb +++ b/spec/unit/resource/gem_package_spec.rb @@ -33,8 +33,35 @@ end describe Chef::Resource::GemPackage, "gem_binary" do let(:resource) { Chef::Resource::GemPackage.new("foo") } + it "sets the default action as :install" do + expect(resource.action).to eql([:install]) + end + + it "supports :install, :lock, :purge, :reconfig, :remove, :unlock, :upgrade actions" do + expect { resource.action :install }.not_to raise_error + expect { resource.action :lock }.not_to raise_error + expect { resource.action :purge }.not_to raise_error + expect { resource.action :reconfig }.not_to raise_error + expect { resource.action :remove }.not_to raise_error + expect { resource.action :unlock }.not_to raise_error + expect { resource.action :upgrade }.not_to raise_error + end + it "sets the gem_binary variable to whatever is passed in" do resource.gem_binary("/opt/local/bin/gem") expect(resource.gem_binary).to eql("/opt/local/bin/gem") end end + +describe Chef::Resource::GemPackage, "clear_gem_sources" do + let(:resource) { Chef::Resource::GemPackage.new("foo") } + + it "is false by default" do + expect(resource.clear_sources).to be false + end + + it "sets the default of clear_sources to the config value" do + Chef::Config[:clear_gem_sources] = true + expect(resource.clear_sources).to be true + end +end diff --git a/spec/unit/resource/git_spec.rb b/spec/unit/resource/git_spec.rb index 1883595617..660cfcf5ae 100644 --- a/spec/unit/resource/git_spec.rb +++ b/spec/unit/resource/git_spec.rb @@ -17,7 +17,6 @@ # require "spec_helper" -require "support/shared/unit/resource/static_provider_resolution" describe Chef::Resource::Git do @@ -28,7 +27,7 @@ describe Chef::Resource::Git do action: :sync ) - let(:resource) { Chef::Resource::Git.new("my awesome webapp") } + let(:resource) { Chef::Resource::Git.new("fakey_fakerton") } it "is a subclass of Chef::Resource::Scm" do expect(resource).to be_a_kind_of(Chef::Resource::Scm) @@ -44,4 +43,20 @@ describe Chef::Resource::Git do expect(resource.revision).to eql("v1.0 tag") end + it "the destination property is the name_property" do + expect(resource.destination).to eql("fakey_fakerton") + end + + it "sets the default action as :sync" do + expect(resource.action).to eql([:sync]) + end + + it "supports :checkout, :diff, :export, :log, :sync actions" do + expect { resource.action :checkout }.not_to raise_error + expect { resource.action :diff }.not_to raise_error + expect { resource.action :export }.not_to raise_error + expect { resource.action :log }.not_to raise_error + expect { resource.action :sync }.not_to raise_error + end + end diff --git a/spec/unit/resource/group_spec.rb b/spec/unit/resource/group_spec.rb index e850361beb..638d8718c7 100644 --- a/spec/unit/resource/group_spec.rb +++ b/spec/unit/resource/group_spec.rb @@ -20,14 +20,25 @@ require "spec_helper" describe Chef::Resource::Group, "initialize" do - let(:resource) { Chef::Resource::Group.new("admin") } + let(:resource) { Chef::Resource::Group.new("fakey_fakerton") } it "sets the resource_name to :group" do expect(resource.resource_name).to eql(:group) end - it "sets the group_name equal to the argument to initialize" do - expect(resource.group_name).to eql("admin") + it "the group_name property is the name_property" do + expect(resource.group_name).to eql("fakey_fakerton") + end + + it "sets the default action as :create" do + expect(resource.action).to eql([:create]) + end + + it "supports :create, :manage, :modify, :remove actions" do + expect { resource.action :create }.not_to raise_error + expect { resource.action :manage }.not_to raise_error + expect { resource.action :modify }.not_to raise_error + expect { resource.action :remove }.not_to raise_error end it "defaults gid to nil" do @@ -42,16 +53,6 @@ describe Chef::Resource::Group, "initialize" do expect(resource.users).to eql([]) end - it "sets action to :create" do - expect(resource.action).to eql([:create]) - end - - %w{create remove modify manage}.each do |action| - it "allows action #{action}" do - expect(resource.allowed_actions.detect { |a| a == action.to_sym }).to eql(action.to_sym) - end - end - it "accepts domain groups (@ or \ separator) on non-windows" do expect { resource.group_name "domain\@group" }.not_to raise_error expect(resource.group_name).to eq("domain\@group") @@ -63,7 +64,7 @@ describe Chef::Resource::Group, "initialize" do end describe Chef::Resource::Group, "group_name" do - let(:resource) { Chef::Resource::Group.new("admin") } + let(:resource) { Chef::Resource::Group.new("fakey_fakerton") } it "allows a string" do resource.group_name "pirates" @@ -76,7 +77,7 @@ describe Chef::Resource::Group, "group_name" do end describe Chef::Resource::Group, "gid" do - let(:resource) { Chef::Resource::Group.new("admin") } + let(:resource) { Chef::Resource::Group.new("fakey_fakerton") } it "allows an integer" do resource.gid 100 @@ -89,7 +90,7 @@ describe Chef::Resource::Group, "gid" do end describe Chef::Resource::Group, "members" do - let(:resource) { Chef::Resource::Group.new("admin") } + let(:resource) { Chef::Resource::Group.new("fakey_fakerton") } [ :users, :members].each do |method| it "(#{method}) allows and convert a string" do @@ -114,7 +115,7 @@ describe Chef::Resource::Group, "members" do end describe Chef::Resource::Group, "append" do - let(:resource) { Chef::Resource::Group.new("admin") } + let(:resource) { Chef::Resource::Group.new("fakey_fakerton") } it "defaults to false" do expect(resource.append).to eql(false) diff --git a/spec/unit/resource/homebrew_cask_spec.rb b/spec/unit/resource/homebrew_cask_spec.rb index 9b04a0328d..a52a552cd9 100644 --- a/spec/unit/resource/homebrew_cask_spec.rb +++ b/spec/unit/resource/homebrew_cask_spec.rb @@ -19,17 +19,22 @@ require "spec_helper" describe Chef::Resource::HomebrewCask do - let(:resource) { Chef::Resource::HomebrewCask.new("myapp") } + let(:resource) { Chef::Resource::HomebrewCask.new("fakey_fakerton") } it "has a resource name of :homebrew_cask" do expect(resource.resource_name).to eql(:homebrew_cask) end - it "has a default action of install" do + it "the cask_name property is the name_property" do + expect(resource.cask_name).to eql("fakey_fakerton") + end + + it "sets the default action as :install" do expect(resource.action).to eql([:install]) end - it "the cask_name property is the name property" do - expect(resource.cask_name).to eql("myapp") + it "supports :install, :remove actions" do + expect { resource.action :install }.not_to raise_error + expect { resource.action :remove }.not_to raise_error end end diff --git a/spec/unit/resource/homebrew_package_spec.rb b/spec/unit/resource/homebrew_package_spec.rb index c3383a5abc..4c73021a1c 100644 --- a/spec/unit/resource/homebrew_package_spec.rb +++ b/spec/unit/resource/homebrew_package_spec.rb @@ -34,6 +34,20 @@ describe Chef::Resource::HomebrewPackage, "initialize" do expect(resource).to be_a_kind_of(Chef::Resource::Package) end + it "sets the default action as :install" do + expect(resource.action).to eql([:install]) + end + + it "supports :install, :lock, :purge, :reconfig, :remove, :unlock, :upgrade actions" do + expect { resource.action :install }.not_to raise_error + expect { resource.action :lock }.not_to raise_error + expect { resource.action :purge }.not_to raise_error + expect { resource.action :reconfig }.not_to raise_error + expect { resource.action :remove }.not_to raise_error + expect { resource.action :unlock }.not_to raise_error + expect { resource.action :upgrade }.not_to raise_error + end + shared_examples "home_brew user set and returned" do it "returns the configured homebrew_user" do resource.homebrew_user user diff --git a/spec/unit/resource/homebrew_tap_spec.rb b/spec/unit/resource/homebrew_tap_spec.rb index 2b93c11c28..0b20b70bdc 100644 --- a/spec/unit/resource/homebrew_tap_spec.rb +++ b/spec/unit/resource/homebrew_tap_spec.rb @@ -25,12 +25,17 @@ describe Chef::Resource::HomebrewTap do expect(resource.resource_name).to eql(:homebrew_tap) end - it "has a default action of tap" do + it "the tap_name property is the name_property" do + expect(resource.tap_name).to eql("user/mytap") + end + + it "sets the default action as :tap" do expect(resource.action).to eql([:tap]) end - it "the tap_name property is the name property" do - expect(resource.tap_name).to eql("user/mytap") + it "supports :tap, :untap actions" do + expect { resource.action :tap }.not_to raise_error + expect { resource.action :untap }.not_to raise_error end it "fails if tap_name isn't in the USER/TAP format" do diff --git a/spec/unit/resource/hostname_spec.rb b/spec/unit/resource/hostname_spec.rb index 33f944dbc9..f0b01d0eb6 100644 --- a/spec/unit/resource/hostname_spec.rb +++ b/spec/unit/resource/hostname_spec.rb @@ -19,16 +19,24 @@ require "spec_helper" describe Chef::Resource::Hostname do - let(:resource) { Chef::Resource::Hostname.new("foo") } + let(:resource) { Chef::Resource::Hostname.new("fakey_fakerton") } it "has a resource name of :hostname" do expect(resource.resource_name).to eql(:hostname) end - it "has a default action of set" do + it "the hostname property is the name_property" do + expect(resource.hostname).to eql("fakey_fakerton") + end + + it "sets the default action as :set" do expect(resource.action).to eql([:set]) end + it "supports :set action" do + expect { resource.action :set }.not_to raise_error + end + it "runs at compile_time by default" do expect(resource.compile_time).to eql(true) end @@ -36,8 +44,4 @@ describe Chef::Resource::Hostname do it "reboots windows nodes by default" do expect(resource.windows_reboot).to eql(true) end - - it "the hostname property is the name property" do - expect(resource.hostname).to eql("foo") - end end diff --git a/spec/unit/resource/http_request_spec.rb b/spec/unit/resource/http_request_spec.rb index 92c84962d7..98cbbd724f 100644 --- a/spec/unit/resource/http_request_spec.rb +++ b/spec/unit/resource/http_request_spec.rb @@ -22,6 +22,20 @@ require "spec_helper" describe Chef::Resource::HttpRequest do let(:resource) { Chef::Resource::HttpRequest.new("fakey_fakerton") } + it "sets the default action as :get" do + expect(resource.action).to eql([:get]) + end + + it "supports :delete, :get, :head, :options, :patch, :post, :put actions" do + expect { resource.action :delete }.not_to raise_error + expect { resource.action :get }.not_to raise_error + expect { resource.action :head }.not_to raise_error + expect { resource.action :options }.not_to raise_error + expect { resource.action :patch }.not_to raise_error + expect { resource.action :post }.not_to raise_error + expect { resource.action :put }.not_to raise_error + end + it "sets url to a string" do resource.url "http://slashdot.org" expect(resource.url).to eql("http://slashdot.org") diff --git a/spec/unit/resource/ips_package_spec.rb b/spec/unit/resource/ips_package_spec.rb index b19f6bdf58..9ec27e914f 100644 --- a/spec/unit/resource/ips_package_spec.rb +++ b/spec/unit/resource/ips_package_spec.rb @@ -17,10 +17,8 @@ # require "spec_helper" -require "support/shared/unit/resource/static_provider_resolution" - -describe Chef::Resource::IpsPackage, "initialize" do +describe Chef::Resource::IpsPackage do static_provider_resolution( resource: Chef::Resource::IpsPackage, provider: Chef::Provider::Package::Ips, @@ -39,4 +37,18 @@ describe Chef::Resource::IpsPackage, "initialize" do resource.accept_license(true) expect(resource.accept_license).to eql(true) end + + it "sets the default action as :install" do + expect(resource.action).to eql([:install]) + end + + it "supports :install, :lock, :purge, :reconfig, :remove, :unlock, :upgrade actions" do + expect { resource.action :install }.not_to raise_error + expect { resource.action :lock }.not_to raise_error + expect { resource.action :purge }.not_to raise_error + expect { resource.action :reconfig }.not_to raise_error + expect { resource.action :remove }.not_to raise_error + expect { resource.action :unlock }.not_to raise_error + expect { resource.action :upgrade }.not_to raise_error + end end diff --git a/spec/unit/resource/ksh_spec.rb b/spec/unit/resource/ksh_spec.rb index 7b651abacc..30b16b8354 100644 --- a/spec/unit/resource/ksh_spec.rb +++ b/spec/unit/resource/ksh_spec.rb @@ -30,6 +30,14 @@ describe Chef::Resource::Ksh do expect(resource.resource_name).to eql(:ksh) end + it "sets the default action as :run" do + expect(resource.action).to eql([:run]) + end + + it "supports :run action" do + expect { resource.action :run }.not_to raise_error + end + it "has an interpreter of ksh" do expect(resource.interpreter).to eql("ksh") end diff --git a/spec/unit/resource/launchd_spec.rb b/spec/unit/resource/launchd_spec.rb index 1fcfc25e3b..bf3fd39952 100644 --- a/spec/unit/resource/launchd_spec.rb +++ b/spec/unit/resource/launchd_spec.rb @@ -15,20 +15,26 @@ require "spec_helper" describe Chef::Resource::Launchd do - let(:resource) { Chef::Resource::Launchd.new("io.chef.chef-client" ) } + let(:resource) { Chef::Resource::Launchd.new("fakey_fakerton" ) } it "has a resource name of Launchd" do expect(resource.resource_name).to eql(:launchd) end - it "has a default action of create" do + it "the label property is the name_property" do + expect(resource.label).to eql("fakey_fakerton") + end + + it "sets the default action as :create" do expect(resource.action).to eql([:create]) end - it "accepts enable, disable, create, and delete as actions" do - expect { resource.action :enable }.not_to raise_error - expect { resource.action :disable }.not_to raise_error + it "supports :create, :create_if_missing, :delete, :disable, :enable, :restart actions" do expect { resource.action :create }.not_to raise_error + expect { resource.action :create_if_missing }.not_to raise_error expect { resource.action :delete }.not_to raise_error + expect { resource.action :disable }.not_to raise_error + expect { resource.action :enable }.not_to raise_error + expect { resource.action :restart }.not_to raise_error end end diff --git a/spec/unit/resource/link_spec.rb b/spec/unit/resource/link_spec.rb index 4f4f8c7c9f..05a39835d8 100644 --- a/spec/unit/resource/link_spec.rb +++ b/spec/unit/resource/link_spec.rb @@ -26,22 +26,17 @@ describe Chef::Resource::Link do expect_any_instance_of(Chef::Resource::Link).to receive(:verify_links_supported!).and_return(true) end - it "has a name property" do - expect(resource.name).to eql("fakey_fakerton") + it "the target_file property is the name_property" do + expect(resource.target_file).to eql("fakey_fakerton") end - it "has a default action of 'create'" do + it "sets the default action as :create" do expect(resource.action).to eql([:create]) end - { :create => false, :delete => false, :blues => true }.each do |action, bad_value| - it "should #{bad_value ? 'not' : ''} accept #{action}" do - if bad_value - expect { resource.action action }.to raise_error(ArgumentError) - else - expect { resource.action action }.not_to raise_error - end - end + it "supports :create, :delete actions" do + expect { resource.action :create }.not_to raise_error + expect { resource.action :delete }.not_to raise_error end it "uses the object name as the target_file by default" do diff --git a/spec/unit/resource/log_spec.rb b/spec/unit/resource/log_spec.rb index 9646b23b53..1e053113c6 100644 --- a/spec/unit/resource/log_spec.rb +++ b/spec/unit/resource/log_spec.rb @@ -24,20 +24,20 @@ describe Chef::Resource::Log do let(:log_str) { "this is my string to log" } let(:resource) { Chef::Resource::Log.new(log_str) } - it "supports the :write actions" do - expect(resource.allowed_actions).to include(:write) - end - it "has a name of log" do expect(resource.resource_name).to eq(:log) end - it "allows you to set a log string" do - expect(resource.name).to eq(log_str) + it "the message property is the name_property" do + expect(resource.message).to eql("this is my string to log") + end + + it "sets the default action as :write" do + expect(resource.action).to eql([:write]) end - it "sets the message to the first argument to new" do - expect(resource.message).to eq(log_str) + it "supports :write action" do + expect { resource.action :write }.not_to raise_error end it "accepts a string for the log message" do diff --git a/spec/unit/resource/macos_user_defaults_spec.rb b/spec/unit/resource/macos_user_defaults_spec.rb index 8787cd0b9a..0ce0517bdb 100644 --- a/spec/unit/resource/macos_user_defaults_spec.rb +++ b/spec/unit/resource/macos_user_defaults_spec.rb @@ -25,7 +25,11 @@ describe Chef::Resource::MacosUserDefaults do expect(resource.resource_name).to eql(:macos_userdefaults) end - it "has a default action of install" do + it "sets the default action as :write" do expect(resource.action).to eql([:write]) end + + it "supports :write action" do + expect { resource.action :write }.not_to raise_error + end end diff --git a/spec/unit/resource/macports_package_spec.rb b/spec/unit/resource/macports_package_spec.rb index 62346def2d..dfb30d16a7 100644 --- a/spec/unit/resource/macports_package_spec.rb +++ b/spec/unit/resource/macports_package_spec.rb @@ -30,3 +30,22 @@ describe Chef::Resource::MacportsPackage, "initialize" do ) end + +describe Chef::Resource::MacportsPackage, "defaults" do + let(:resource) { Chef::Resource::MacportsPackage.new("foo") } + + it "sets the default action as :install" do + expect(resource.action).to eql([:install]) + end + + it "supports :install, :lock, :purge, :reconfig, :remove, :unlock, :upgrade actions" do + expect { resource.action :install }.not_to raise_error + expect { resource.action :lock }.not_to raise_error + expect { resource.action :purge }.not_to raise_error + expect { resource.action :reconfig }.not_to raise_error + expect { resource.action :remove }.not_to raise_error + expect { resource.action :unlock }.not_to raise_error + expect { resource.action :upgrade }.not_to raise_error + end + +end diff --git a/spec/unit/resource/mdadm_spec.rb b/spec/unit/resource/mdadm_spec.rb index 6d595dc0f8..d2e3c37de8 100644 --- a/spec/unit/resource/mdadm_spec.rb +++ b/spec/unit/resource/mdadm_spec.rb @@ -27,13 +27,17 @@ describe Chef::Resource::Mdadm do expect(resource.resource_name).to eql(:mdadm) end - it "has a default action of create" do + it "the raid_device property is the name_property" do + expect(resource.raid_device).to eql("fakey_fakerton") + end + + it "sets the default action as :create" do expect(resource.action).to eql([:create]) end - it "accepts create, assemble, stop as actions" do - expect { resource.action :create }.not_to raise_error + it "supports :assemble, :create, :stop actions" do expect { resource.action :assemble }.not_to raise_error + expect { resource.action :create }.not_to raise_error expect { resource.action :stop }.not_to raise_error end diff --git a/spec/unit/resource/mount_spec.rb b/spec/unit/resource/mount_spec.rb index 2fdad43f3f..fd81901f45 100644 --- a/spec/unit/resource/mount_spec.rb +++ b/spec/unit/resource/mount_spec.rb @@ -20,29 +20,26 @@ require "spec_helper" describe Chef::Resource::Mount do - let(:resource) { Chef::Resource::Mount.new("filesystem") } + let(:resource) { Chef::Resource::Mount.new("fakey_fakerton") } - it "has a name property" do - expect(resource.name).to eql("filesystem") + it "the mount_point property is the name_property" do + expect(resource.mount_point).to eql("fakey_fakerton") end - it "sets mount_point to the name" do - expect(resource.mount_point).to eql("filesystem") - end - - it "has a default action of mount" do + it "sets the default action as :mount" do expect(resource.action).to eql([:mount]) end - it "accepts mount, umount, unmount and remount as actions" do + it "supports :disable, :enable, :mount, :remount, :umount, :unmount actions" do + expect { resource.action :disable }.not_to raise_error + expect { resource.action :enable }.not_to raise_error expect { resource.action :mount }.not_to raise_error + expect { resource.action :remount }.not_to raise_error expect { resource.action :umount }.not_to raise_error expect { resource.action :unmount }.not_to raise_error - expect { resource.action :remount }.not_to raise_error - expect { resource.action :brooklyn }.to raise_error(ArgumentError) end - it "allows you to set the device attribute" do + it "allows you to set the device property" do resource.device "/dev/sdb3" expect(resource.device).to eql("/dev/sdb3") end @@ -51,12 +48,12 @@ describe Chef::Resource::Mount do expect(resource.fsck_device).to eql("-") end - it "allows you to set the fsck_device attribute" do + it "allows you to set the fsck_device property" do resource.fsck_device "/dev/rdsk/sdb3" expect(resource.fsck_device).to eql("/dev/rdsk/sdb3") end - it "allows you to set the fstype attribute" do + it "allows you to set the fstype property" do resource.fstype "nfs" expect(resource.fstype).to eql("nfs") end @@ -65,17 +62,17 @@ describe Chef::Resource::Mount do expect(resource.fstype).to eql("auto") end - it "allows you to set the dump attribute" do + it "allows you to set the dump property" do resource.dump 1 expect(resource.dump).to eql(1) end - it "allows you to set the pass attribute" do + it "allows you to set the pass property" do resource.pass 1 expect(resource.pass).to eql(1) end - it "sets the options attribute to defaults" do + it "sets the options property to defaults" do expect(resource.options).to eql(["defaults"]) end @@ -84,7 +81,7 @@ describe Chef::Resource::Mount do expect(resource.options).to be_a_kind_of(Array) end - it "allows options attribute as an array" do + it "allows options property as an array" do resource.options %w{ro nosuid} expect(resource.options).to be_a_kind_of(Array) end diff --git a/spec/unit/resource/msu_package_spec.rb b/spec/unit/resource/msu_package_spec.rb index bc2529df9c..843c2ca49d 100644 --- a/spec/unit/resource/msu_package_spec.rb +++ b/spec/unit/resource/msu_package_spec.rb @@ -33,6 +33,16 @@ describe Chef::Resource::MsuPackage do expect(resource.action).to eql([:install]) end + it "supports :install, :lock, :purge, :reconfig, :remove, :unlock, :upgrade actions" do + expect { resource.action :install }.not_to raise_error + expect { resource.action :lock }.not_to raise_error + expect { resource.action :purge }.not_to raise_error + expect { resource.action :reconfig }.not_to raise_error + expect { resource.action :remove }.not_to raise_error + expect { resource.action :unlock }.not_to raise_error + expect { resource.action :upgrade }.not_to raise_error + end + it "coerces name property to package_name property" do expect(resource.package_name).to eql("test_pkg") end diff --git a/spec/unit/resource/ohai_hint_spec.rb b/spec/unit/resource/ohai_hint_spec.rb index 1a4f6637fa..87cfe5e721 100644 --- a/spec/unit/resource/ohai_hint_spec.rb +++ b/spec/unit/resource/ohai_hint_spec.rb @@ -19,25 +19,26 @@ require "spec_helper" describe Chef::Resource::OhaiHint do - let(:resource) { Chef::Resource::OhaiHint.new("foo") } + let(:resource) { Chef::Resource::OhaiHint.new("fakey_fakerton") } it "has a resource name of :ohai_hint" do expect(resource.resource_name).to eql(:ohai_hint) end - it "has a default action of create" do + it "the hint_name property is the name_property" do + expect(resource.hint_name).to eql("fakey_fakerton") + end + + it "sets the default action as :create" do expect(resource.action).to eql([:create]) end - it "supports the :nothing, :create and :delete actions" do - expect(resource.allowed_actions).to include(:nothing, :create, :delete) + it "supports :create, :delete actions" do + expect { resource.action :create }.not_to raise_error + expect { resource.action :delete }.not_to raise_error end it "runs at compile_time by default" do expect(resource.compile_time).to eql(true) end - - it "the hint_name property is the name property" do - expect(resource.hint_name).to eql("foo") - end end diff --git a/spec/unit/resource/ohai_spec.rb b/spec/unit/resource/ohai_spec.rb index eb569aa3b7..a18929da15 100644 --- a/spec/unit/resource/ohai_spec.rb +++ b/spec/unit/resource/ohai_spec.rb @@ -20,17 +20,25 @@ require "spec_helper" describe Chef::Resource::Ohai do - let(:resource) { Chef::Resource::Ohai.new("ohai_reload") } + let(:resource) { Chef::Resource::Ohai.new("fakey_fakerton") } it "has a resource name of :ohai" do expect(resource.resource_name).to eql(:ohai) end - it "has a default action of reload" do + it "the ohai_name property is the name_property" do + expect(resource.ohai_name).to eql("fakey_fakerton") + end + + it "sets the default action as :reload" do expect(resource.action).to eql([:reload]) end - it "allows you to set the plugin attribute" do + it "supports :reload action" do + expect { resource.action :reload }.not_to raise_error + end + + it "allows you to set the plugin property" do resource.plugin "passwd" expect(resource.plugin).to eql("passwd") end diff --git a/spec/unit/resource/openbsd_package_spec.rb b/spec/unit/resource/openbsd_package_spec.rb index 17dc9f09ff..935cc11b40 100644 --- a/spec/unit/resource/openbsd_package_spec.rb +++ b/spec/unit/resource/openbsd_package_spec.rb @@ -36,6 +36,20 @@ describe Chef::Resource::OpenbsdPackage do expect(resource.resource_name).to eql(:openbsd_package) end + it "sets the default action as :install" do + expect(resource.action).to eql([:install]) + end + + it "supports :install, :lock, :purge, :reconfig, :remove, :unlock, :upgrade actions" do + expect { resource.action :install }.not_to raise_error + expect { resource.action :lock }.not_to raise_error + expect { resource.action :purge }.not_to raise_error + expect { resource.action :reconfig }.not_to raise_error + expect { resource.action :remove }.not_to raise_error + expect { resource.action :unlock }.not_to raise_error + expect { resource.action :upgrade }.not_to raise_error + end + it "does not set the provider" do expect(resource.provider).to be_nil end diff --git a/spec/unit/resource/openssl_dhparam.rb b/spec/unit/resource/openssl_dhparam.rb index d1021d4f7e..10c5399c33 100644 --- a/spec/unit/resource/openssl_dhparam.rb +++ b/spec/unit/resource/openssl_dhparam.rb @@ -19,16 +19,24 @@ require "spec_helper" describe Chef::Resource::OpensslDhparam do - let(:resource) { Chef::Resource::OpensslDhparam.new("dhparam") } + let(:resource) { Chef::Resource::OpensslDhparam.new("fakey_fakerton") } it "has a resource name of :openssl_dhparam" do expect(resource.resource_name).to eql(:openssl_dhparam) end - it "has a default action of create" do + it "the path property is the name_property" do + expect(resource.path).to eql("fakey_fakerton") + end + + it "sets the default action as :create" do expect(resource.action).to eql([:create]) end + it "supports :create action" do + expect { resource.action :create }.not_to raise_error + end + it "has a default mode of '0640'" do expect(resource.mode).to eql("0640") end @@ -45,7 +53,4 @@ describe Chef::Resource::OpensslDhparam do expect { resource.key_length 1234 }.to raise_error(ArgumentError) end - it "the path property is the name property" do - expect(resource.path).to eql("dhparam") - end end diff --git a/spec/unit/resource/openssl_rsa_private_key_spec.rb b/spec/unit/resource/openssl_rsa_private_key_spec.rb index 67bebf17fe..ceccfbcb25 100644 --- a/spec/unit/resource/openssl_rsa_private_key_spec.rb +++ b/spec/unit/resource/openssl_rsa_private_key_spec.rb @@ -19,16 +19,24 @@ require "spec_helper" describe Chef::Resource::OpensslRsaPrivateKey do - let(:resource) { Chef::Resource::OpensslRsaPrivateKey.new("key") } + let(:resource) { Chef::Resource::OpensslRsaPrivateKey.new("fakey_fakerton") } it "has a resource name of :openssl_rsa_private_key" do expect(resource.resource_name).to eql(:openssl_rsa_private_key) end - it "has a default action of create" do + it "the path property is the name_property" do + expect(resource.path).to eql("fakey_fakerton") + end + + it "sets the default action as :create" do expect(resource.action).to eql([:create]) end + it "supports :create action" do + expect { resource.action :create }.not_to raise_error + end + it "has a default mode of '0600'" do expect(resource.mode).to eql("0600") end @@ -53,7 +61,4 @@ describe Chef::Resource::OpensslRsaPrivateKey do expect(resource.force).to eql(false) end - it "the path property is the name property" do - expect(resource.path).to eql("key") - end end diff --git a/spec/unit/resource/openssl_rsa_public_key_spec.rb b/spec/unit/resource/openssl_rsa_public_key_spec.rb index d624e10338..5c63ce5df2 100644 --- a/spec/unit/resource/openssl_rsa_public_key_spec.rb +++ b/spec/unit/resource/openssl_rsa_public_key_spec.rb @@ -25,15 +25,19 @@ describe Chef::Resource::OpensslRsaPublicKey do expect(resource.resource_name).to eql(:openssl_rsa_public_key) end - it "has a default action of create" do + it "the path property is the name_property" do + expect(resource.path).to eql("key") + end + + it "sets the default action as :create" do expect(resource.action).to eql([:create]) end - it "has a default mode of '0640'" do - expect(resource.mode).to eql("0640") + it "supports :create action" do + expect { resource.action :create }.not_to raise_error end - it "the path property is the name property" do - expect(resource.path).to eql("key") + it "has a default mode of '0640'" do + expect(resource.mode).to eql("0640") end end diff --git a/spec/unit/resource/osx_profile_spec.rb b/spec/unit/resource/osx_profile_spec.rb index 291b205466..3a0b144183 100644 --- a/spec/unit/resource/osx_profile_spec.rb +++ b/spec/unit/resource/osx_profile_spec.rb @@ -21,19 +21,22 @@ require "spec_helper" describe Chef::Resource::OsxProfile do let(:resource) do Chef::Resource::OsxProfile.new( - "Test Profile Resource", - run_context) + "fakey_fakerton") end it "has a resource name of profile" do expect(resource.resource_name).to eql(:osx_profile) end - it "has a default action of install" do + it "the profile_name property is the name_property" do + expect(resource.profile_name).to eql("fakey_fakerton") + end + + it "sets the default action as :install" do expect(resource.action).to eql([:install]) end - it "accepts install and remove as actions" do + it "supports :install, :remove actions" do expect { resource.action :install }.not_to raise_error expect { resource.action :remove }.not_to raise_error end diff --git a/spec/unit/resource/package_spec.rb b/spec/unit/resource/package_spec.rb index 38d0bfce96..79a714edfc 100644 --- a/spec/unit/resource/package_spec.rb +++ b/spec/unit/resource/package_spec.rb @@ -26,6 +26,20 @@ describe Chef::Resource::Package do expect(resource.package_name).to eql("emacs") end + it "sets the default action as :install" do + expect(resource.action).to eql([:install]) + end + + it "supports :install, :lock, :purge, :reconfig, :remove, :unlock, :upgrade actions" do + expect { resource.action :install }.not_to raise_error + expect { resource.action :lock }.not_to raise_error + expect { resource.action :purge }.not_to raise_error + expect { resource.action :reconfig }.not_to raise_error + expect { resource.action :remove }.not_to raise_error + expect { resource.action :unlock }.not_to raise_error + expect { resource.action :upgrade }.not_to raise_error + end + it "accepts a string for the package name" do resource.package_name "something" expect(resource.package_name).to eql("something") diff --git a/spec/unit/resource/pacman_package_spec.rb b/spec/unit/resource/pacman_package_spec.rb index b9d2ea21f6..ecc224508f 100644 --- a/spec/unit/resource/pacman_package_spec.rb +++ b/spec/unit/resource/pacman_package_spec.rb @@ -1,6 +1,7 @@ # # Author:: Jan Zimmek (<jan.zimmek@web.de>) # Copyright:: Copyright 2010-2016, Jan Zimmek +# Copyright:: 2018, Chef Software, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,10 +18,8 @@ # require "spec_helper" -require "support/shared/unit/resource/static_provider_resolution" - -describe Chef::Resource::PacmanPackage, "initialize" do +describe Chef::Resource::PacmanPackage do static_provider_resolution( resource: Chef::Resource::PacmanPackage, provider: Chef::Provider::Package::Pacman, @@ -29,4 +28,19 @@ describe Chef::Resource::PacmanPackage, "initialize" do os: "linux" ) + let(:resource) { Chef::Resource::PacmanPackage.new("fakey_fakerton") } + + it "sets the default action as :install" do + expect(resource.action).to eql([:install]) + end + + it "supports :install, :lock, :purge, :reconfig, :remove, :unlock, :upgrade actions" do + expect { resource.action :install }.not_to raise_error + expect { resource.action :lock }.not_to raise_error + expect { resource.action :purge }.not_to raise_error + expect { resource.action :reconfig }.not_to raise_error + expect { resource.action :remove }.not_to raise_error + expect { resource.action :unlock }.not_to raise_error + expect { resource.action :upgrade }.not_to raise_error + end end diff --git a/spec/unit/resource/paludis_package_spec.rb b/spec/unit/resource/paludis_package_spec.rb new file mode 100644 index 0000000000..2ee3039b13 --- /dev/null +++ b/spec/unit/resource/paludis_package_spec.rb @@ -0,0 +1,36 @@ +# +# 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::PaludisPackage do + let(:resource) { Chef::Resource::PaludisPackage.new("fakey_fakerton") } + + it "sets the default action as :install" do + expect(resource.action).to eql([:install]) + end + + it "supports :install, :lock, :purge, :reconfig, :remove, :unlock, :upgrade actions" do + expect { resource.action :install }.not_to raise_error + expect { resource.action :lock }.not_to raise_error + expect { resource.action :purge }.not_to raise_error + expect { resource.action :reconfig }.not_to raise_error + expect { resource.action :remove }.not_to raise_error + expect { resource.action :unlock }.not_to raise_error + expect { resource.action :upgrade }.not_to raise_error + end +end diff --git a/spec/unit/resource/perl_spec.rb b/spec/unit/resource/perl_spec.rb index f8e11c465c..ccc99d7b73 100644 --- a/spec/unit/resource/perl_spec.rb +++ b/spec/unit/resource/perl_spec.rb @@ -33,4 +33,12 @@ describe Chef::Resource::Perl do it "has an interpreter of perl" do expect(resource.interpreter).to eql("perl") end + + it "sets the default action as :run" do + expect(resource.action).to eql([:run]) + end + + it "supports :run action" do + expect { resource.action :run }.not_to raise_error + end end diff --git a/spec/unit/resource/portage_package_spec.rb b/spec/unit/resource/portage_package_spec.rb index a37cfd6e41..7030a11d87 100644 --- a/spec/unit/resource/portage_package_spec.rb +++ b/spec/unit/resource/portage_package_spec.rb @@ -29,4 +29,18 @@ describe Chef::Resource::PortagePackage, "initialize" do it "sets the resource_name to :portage_package" do expect(resource.resource_name).to eql(:portage_package) end + + it "sets the default action as :install" do + expect(resource.action).to eql([:install]) + end + + it "supports :install, :lock, :purge, :reconfig, :remove, :unlock, :upgrade actions" do + expect { resource.action :install }.not_to raise_error + expect { resource.action :lock }.not_to raise_error + expect { resource.action :purge }.not_to raise_error + expect { resource.action :reconfig }.not_to raise_error + expect { resource.action :remove }.not_to raise_error + expect { resource.action :unlock }.not_to raise_error + expect { resource.action :upgrade }.not_to raise_error + end end diff --git a/spec/unit/resource/powershell_package_spec.rb b/spec/unit/resource/powershell_package_spec.rb index a448d58d5a..cc50abefb1 100644 --- a/spec/unit/resource/powershell_package_spec.rb +++ b/spec/unit/resource/powershell_package_spec.rb @@ -31,6 +31,20 @@ describe Chef::Resource::PowershellPackage do expect(resource.resource_name).to eql(:powershell_package) end + it "sets the default action as :install" do + expect(resource.action).to eql([:install]) + end + + it "supports :install, :lock, :purge, :reconfig, :remove, :unlock, :upgrade actions" do + expect { resource.action :install }.not_to raise_error + expect { resource.action :lock }.not_to raise_error + expect { resource.action :purge }.not_to raise_error + expect { resource.action :reconfig }.not_to raise_error + expect { resource.action :remove }.not_to raise_error + expect { resource.action :unlock }.not_to raise_error + expect { resource.action :upgrade }.not_to raise_error + end + it "coerces its name to a package_name array" do expect(resource.package_name).to eql(["test_package"]) end diff --git a/spec/unit/resource/python_spec.rb b/spec/unit/resource/python_spec.rb index 5a4dc8eca8..c773fd2394 100644 --- a/spec/unit/resource/python_spec.rb +++ b/spec/unit/resource/python_spec.rb @@ -29,4 +29,12 @@ describe Chef::Resource::Python do it "has an interpreter of python" do expect(resource.interpreter).to eql("python") end + + it "sets the default action as :run" do + expect(resource.action).to eql([:run]) + end + + it "supports :run action" do + expect { resource.action :run }.not_to raise_error + end end diff --git a/spec/unit/resource/reboot_spec.rb b/spec/unit/resource/reboot_spec.rb index adcfb9e6a4..991ceec984 100644 --- a/spec/unit/resource/reboot_spec.rb +++ b/spec/unit/resource/reboot_spec.rb @@ -21,12 +21,14 @@ describe Chef::Resource::Reboot do let(:resource) { Chef::Resource::Reboot.new("reboot me!") } - it "has a default action of :nothing" do + it "sets the default action as :nothing" do expect(resource.action).to eql([:nothing]) end - it "supports the :nothing, :request_reboot, :reboot_now, and :cancel actions" do - expect(resource.allowed_actions).to include(:nothing, :request_reboot, :reboot_now, :cancel) + it "supports :cancel, :reboot_now, :request_reboot actions" do + expect { resource.action :cancel }.not_to raise_error + expect { resource.action :reboot_now }.not_to raise_error + expect { resource.action :request_reboot }.not_to raise_error end it "has a resource_name of :reboot" do diff --git a/spec/unit/resource/registry_key_spec.rb b/spec/unit/resource/registry_key_spec.rb index 1f32a00210..c7e95c37be 100644 --- a/spec/unit/resource/registry_key_spec.rb +++ b/spec/unit/resource/registry_key_spec.rb @@ -25,10 +25,21 @@ describe Chef::Resource::RegistryKey, "initialize" do expect(resource.resource_name).to eql(:registry_key) end - it "sets the key property to the resource name" do + it "the key property is the name_property" do expect(resource.key).to eql('HKCU\Software\Raxicoricofallapatorius') end + it "sets the default action as :create" do + expect(resource.action).to eql([:create]) + end + + it "supports :create, :create_if_missing, :delete, :delete_key actions" do + expect { resource.action :create }.not_to raise_error + expect { resource.action :create_if_missing }.not_to raise_error + expect { resource.action :delete }.not_to raise_error + expect { resource.action :delete_key }.not_to raise_error + end + it "defaults recursive to false" do expect(resource.recursive).to eql(false) end diff --git a/spec/unit/resource/remote_directory_spec.rb b/spec/unit/resource/remote_directory_spec.rb index afa16678fc..f010ebdf96 100644 --- a/spec/unit/resource/remote_directory_spec.rb +++ b/spec/unit/resource/remote_directory_spec.rb @@ -22,10 +22,20 @@ describe Chef::Resource::RemoteDirectory do let(:resource) { Chef::Resource::RemoteDirectory.new("/etc/dunk") } - it "path is the name property" do + it "the path property is the name_property" do expect(resource.path).to eql("/etc/dunk") end + it "sets the default action as :create" do + expect(resource.action).to eql([:create]) + end + + it "supports :create, :create_if_missing, :delete actions" do + expect { resource.action :create }.not_to raise_error + expect { resource.action :create_if_missing }.not_to raise_error + expect { resource.action :delete }.not_to raise_error + end + it "accepts a string for the remote directory source" do resource.source "foo" expect(resource.source).to eql("foo") diff --git a/spec/unit/resource/remote_file_spec.rb b/spec/unit/resource/remote_file_spec.rb index 691c55219c..581b2dbf6e 100644 --- a/spec/unit/resource/remote_file_spec.rb +++ b/spec/unit/resource/remote_file_spec.rb @@ -23,6 +23,25 @@ describe Chef::Resource::RemoteFile do let(:resource) { Chef::Resource::RemoteFile.new("fakey_fakerton") } + describe "name_property" do + it "the path property is the name_property" do + expect(resource.path).to eql("fakey_fakerton") + end + end + + describe "Actions" do + it "sets the default action as :create" do + expect(resource.action).to eql([:create]) + end + + it "supports :create, :create_if_missing, :delete, :touch actions" do + expect { resource.action :create }.not_to raise_error + expect { resource.action :create_if_missing }.not_to raise_error + expect { resource.action :delete }.not_to raise_error + expect { resource.action :touch }.not_to raise_error + end + end + describe "initialize" do it "is a subclass of Chef::Resource::File" do expect(resource).to be_a_kind_of(Chef::Resource::File) diff --git a/spec/unit/resource/rhsm_errata_level_spec.rb b/spec/unit/resource/rhsm_errata_level_spec.rb index 3284107e75..8d0de18f98 100644 --- a/spec/unit/resource/rhsm_errata_level_spec.rb +++ b/spec/unit/resource/rhsm_errata_level_spec.rb @@ -25,12 +25,16 @@ describe Chef::Resource::RhsmErrataLevel do expect(resource.resource_name).to eql(:rhsm_errata_level) end - it "has a default action of install" do + it "the errata_level property is the name_property" do + expect(resource.errata_level).to eql("moderate") + end + + it "sets the default action as :install" do expect(resource.action).to eql([:install]) end - it "the errata_level property is the name property" do - expect(resource.errata_level).to eql("moderate") + it "supports :install action" do + expect { resource.action :install }.not_to raise_error end it "coerces the errata_level to be lowercase" do diff --git a/spec/unit/resource/rhsm_errata_spec.rb b/spec/unit/resource/rhsm_errata_spec.rb index 8da7269ca8..4d708bff5d 100644 --- a/spec/unit/resource/rhsm_errata_spec.rb +++ b/spec/unit/resource/rhsm_errata_spec.rb @@ -19,17 +19,21 @@ require "spec_helper" describe Chef::Resource::RhsmErrata do - let(:resource) { Chef::Resource::RhsmErrata.new("foo") } + let(:resource) { Chef::Resource::RhsmErrata.new("fakey_fakerton") } it "has a resource name of :rhsm_errata" do expect(resource.resource_name).to eql(:rhsm_errata) end - it "has a default action of install" do + it "the errata_id property is the name_property" do + expect(resource.errata_id).to eql("fakey_fakerton") + end + + it "sets the default action as :install" do expect(resource.action).to eql([:install]) end - it "the errata_id property is the name property" do - expect(resource.errata_id).to eql("foo") + it "supports :install action" do + expect { resource.action :install }.not_to raise_error end end diff --git a/spec/unit/resource/rhsm_register_spec.rb b/spec/unit/resource/rhsm_register_spec.rb index 2e360b5708..3c39bba131 100644 --- a/spec/unit/resource/rhsm_register_spec.rb +++ b/spec/unit/resource/rhsm_register_spec.rb @@ -26,10 +26,15 @@ describe Chef::Resource::RhsmRegister do expect(resource.resource_name).to eql(:rhsm_register) end - it "has a default action of register" do + it "sets the default action as :register" do expect(resource.action).to eql([:register]) end + it "supports :register, :unregister actions" do + expect { resource.action :register }.not_to raise_error + expect { resource.action :unregister }.not_to raise_error + end + it "coerces activation_key to an array" do resource.activation_key "foo" expect(resource.activation_key).to eql(["foo"]) diff --git a/spec/unit/resource/rhsm_repo_spec.rb b/spec/unit/resource/rhsm_repo_spec.rb index 97606a03c8..36eb235798 100644 --- a/spec/unit/resource/rhsm_repo_spec.rb +++ b/spec/unit/resource/rhsm_repo_spec.rb @@ -19,19 +19,24 @@ require "spec_helper" describe Chef::Resource::RhsmRepo do - let(:resource) { Chef::Resource::RhsmRepo.new("foo") } + let(:resource) { Chef::Resource::RhsmRepo.new("fakey_fakerton") } let(:provider) { resource.provider_for_action(:enable) } it "has a resource name of :rhsm_repo" do expect(resource.resource_name).to eql(:rhsm_repo) end - it "has a default action of enable" do + it "the repo_name property is the name_property" do + expect(resource.repo_name).to eql("fakey_fakerton") + end + + it "sets the default action as :enable" do expect(resource.action).to eql([:enable]) end - it "the repo_name property is the name property" do - expect(resource.repo_name).to eql("foo") + it "supports :disable, :enable actions" do + expect { resource.action :disable }.not_to raise_error + expect { resource.action :enable }.not_to raise_error end describe "#repo_enabled?" do diff --git a/spec/unit/resource/rhsm_subscription_spec.rb b/spec/unit/resource/rhsm_subscription_spec.rb index 0160624f39..6de65a427f 100644 --- a/spec/unit/resource/rhsm_subscription_spec.rb +++ b/spec/unit/resource/rhsm_subscription_spec.rb @@ -18,19 +18,24 @@ require "spec_helper" describe Chef::Resource::RhsmSubscription do - let(:resource) { Chef::Resource::RhsmSubscription.new("foo") } + let(:resource) { Chef::Resource::RhsmSubscription.new("fakey_fakerton") } let(:provider) { resource.provider_for_action(:attach) } it "has a resource name of :rhsm_subscription" do expect(resource.resource_name).to eql(:rhsm_subscription) end - it "has a default action of attach" do + it "the pool_id property is the name_property" do + expect(resource.pool_id).to eql("fakey_fakerton") + end + + it "sets the default action as :attach" do expect(resource.action).to eql([:attach]) end - it "the pool_id property is the name property" do - expect(resource.pool_id).to eql("foo") + it "supports :attach, :remove actions" do + expect { resource.action :attach }.not_to raise_error + expect { resource.action :remove }.not_to raise_error end describe "#subscription_attached?" do diff --git a/spec/unit/resource/route_spec.rb b/spec/unit/resource/route_spec.rb index 899012b9dc..d4248755b5 100644 --- a/spec/unit/resource/route_spec.rb +++ b/spec/unit/resource/route_spec.rb @@ -23,22 +23,17 @@ describe Chef::Resource::Route do let(:resource) { Chef::Resource::Route.new("10.0.0.10") } - it "has a name property" do - expect(resource.name).to eql("10.0.0.10") + it "the target property is the name_property" do + expect(resource.target).to eql("10.0.0.10") end - it "has a default action of 'add'" do + it "sets the default action as :add" do expect(resource.action).to eql([:add]) end - it "accepts add or delete for action" do + it "supports :add, :delete actions" do expect { resource.action :add }.not_to raise_error expect { resource.action :delete }.not_to raise_error - expect { resource.action :lolcat }.to raise_error(ArgumentError) - end - - it "uses the object name as the target by default" do - expect(resource.target).to eql("10.0.0.10") end it "allows you to specify the netmask" do diff --git a/spec/unit/resource/rpm_package_spec.rb b/spec/unit/resource/rpm_package_spec.rb index 0104e10dae..eeeddd9bee 100644 --- a/spec/unit/resource/rpm_package_spec.rb +++ b/spec/unit/resource/rpm_package_spec.rb @@ -40,6 +40,20 @@ describe Chef::Resource::RpmPackage, "allow_downgrade" do expect(resource).to be_a_kind_of(Chef::Resource::Package) end + it "sets the default action as :install" do + expect(resource.action).to eql([:install]) + end + + it "supports :install, :lock, :purge, :reconfig, :remove, :unlock, :upgrade actions" do + expect { resource.action :install }.not_to raise_error + expect { resource.action :lock }.not_to raise_error + expect { resource.action :purge }.not_to raise_error + expect { resource.action :reconfig }.not_to raise_error + expect { resource.action :remove }.not_to raise_error + expect { resource.action :unlock }.not_to raise_error + expect { resource.action :upgrade }.not_to raise_error + end + it "allows you to specify whether allow_downgrade is true or false" do expect { resource.allow_downgrade true }.not_to raise_error expect { resource.allow_downgrade false }.not_to raise_error diff --git a/spec/unit/resource/ruby_block_spec.rb b/spec/unit/resource/ruby_block_spec.rb index fd0da32123..fb5a8815c7 100644 --- a/spec/unit/resource/ruby_block_spec.rb +++ b/spec/unit/resource/ruby_block_spec.rb @@ -23,12 +23,21 @@ describe Chef::Resource::RubyBlock do let(:resource) { Chef::Resource::RubyBlock.new("fakey_fakerton") } - it "has a default action of 'run'" do + it "has a resource name of :ruby_block" do + expect(resource.resource_name).to eql(:ruby_block) + end + + it "the block_name property is the name_property" do + expect(resource.block_name).to eql("fakey_fakerton") + end + + it "sets the default action as :run" do expect(resource.action).to eql([:run]) end - it "has a resource name of :ruby_block" do - expect(resource.resource_name).to eql(:ruby_block) + it "supports :create, :run actions" do + expect { resource.action :create }.not_to raise_error + expect { resource.action :run }.not_to raise_error end it "accepts a ruby block/proc/.. for the 'block' parameter" do @@ -37,11 +46,6 @@ describe Chef::Resource::RubyBlock do end.call).to eql("foo") end - it "allows the action to be 'create'" do - resource.action :create - expect(resource.action).to eq([:create]) - end - describe "when it has been initialized with block code" do before do resource.block_name("puts 'harrrr'") diff --git a/spec/unit/resource/ruby_spec.rb b/spec/unit/resource/ruby_spec.rb index 4327917295..88ebc3404e 100644 --- a/spec/unit/resource/ruby_spec.rb +++ b/spec/unit/resource/ruby_spec.rb @@ -25,6 +25,14 @@ describe Chef::Resource::Ruby do expect(resource.resource_name).to eql(:ruby) end + it "sets the default action as :run" do + expect(resource.action).to eql([:run]) + end + + it "supports :run action" do + expect { resource.action :run }.not_to raise_error + end + it "has an interpreter of ruby" do expect(resource.interpreter).to eql("ruby") end diff --git a/spec/unit/resource/scm_spec.rb b/spec/unit/resource/scm_spec.rb index 33c2f17498..be529a3832 100644 --- a/spec/unit/resource/scm_spec.rb +++ b/spec/unit/resource/scm_spec.rb @@ -20,14 +20,22 @@ require "spec_helper" describe Chef::Resource::Scm do - let(:resource) { Chef::Resource::Scm.new("my awesome app") } - - it "supports :checkout, :export, :sync, :diff, and :log actions" do - expect(resource.allowed_actions).to include(:checkout) - expect(resource.allowed_actions).to include(:export) - expect(resource.allowed_actions).to include(:sync) - expect(resource.allowed_actions).to include(:diff) - expect(resource.allowed_actions).to include(:log) + let(:resource) { Chef::Resource::Scm.new("fakey_fakerton") } + + it "the destination property is the name_property" do + expect(resource.destination).to eql("fakey_fakerton") + end + + it "sets the default action as :sync" do + expect(resource.action).to eql([:sync]) + end + + it "supports :checkout, :diff, :export, :log, :sync actions" do + expect { resource.action :checkout }.not_to raise_error + expect { resource.action :diff }.not_to raise_error + expect { resource.action :export }.not_to raise_error + expect { resource.action :log }.not_to raise_error + expect { resource.action :sync }.not_to raise_error end it "takes the destination path as a string" do diff --git a/spec/unit/resource/script_spec.rb b/spec/unit/resource/script_spec.rb index 554d99710e..3306ddb666 100644 --- a/spec/unit/resource/script_spec.rb +++ b/spec/unit/resource/script_spec.rb @@ -24,6 +24,14 @@ describe Chef::Resource::Script do let(:script_resource) { Chef::Resource::Script.new(resource_instance_name) } let(:resource_name) { :script } + it "sets the default action as :run" do + expect(script_resource.action).to eql([:run]) + end + + it "supports :run action" do + expect { script_resource.action :run }.not_to raise_error + end + it "accepts a string for the interpreter" do script_resource.interpreter "naaaaNaNaNaaNaaNaaNaa" expect(script_resource.interpreter).to eql("naaaaNaNaNaaNaaNaaNaa") diff --git a/spec/unit/resource/service_spec.rb b/spec/unit/resource/service_spec.rb index 335ad76fc8..fc82c19b79 100644 --- a/spec/unit/resource/service_spec.rb +++ b/spec/unit/resource/service_spec.rb @@ -30,6 +30,21 @@ describe Chef::Resource::Service do expect(resource.service_name).to eql("chef") end + it "sets the default action as :nothing" do + expect(resource.action).to eql([:nothing]) + end + + it "supports :disable, :enable, :mask, :reload, :restart, :start, :stop, :unmask actions" do + expect { resource.action :disable }.not_to raise_error + expect { resource.action :enable }.not_to raise_error + expect { resource.action :mask }.not_to raise_error + expect { resource.action :reload }.not_to raise_error + expect { resource.action :restart }.not_to raise_error + expect { resource.action :start }.not_to raise_error + expect { resource.action :stop }.not_to raise_error + expect { resource.action :unmask }.not_to raise_error + end + it "sets the pattern to be the service name by default" do expect(resource.pattern).to eql("chef") end diff --git a/spec/unit/resource/smartos_package_spec.rb b/spec/unit/resource/smartos_package_spec.rb index a0bd5853f5..d64b8c0170 100644 --- a/spec/unit/resource/smartos_package_spec.rb +++ b/spec/unit/resource/smartos_package_spec.rb @@ -1,6 +1,7 @@ # # Author:: Thomas Bishop (<bishop.thomas@gmail.com>) # Copyright:: Copyright 2010-2016, Thomas Bishop +# Copyright:: Copyright 2018, Chef Software, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,9 +18,8 @@ # require "spec_helper" -require "support/shared/unit/resource/static_provider_resolution" -describe Chef::Resource::SmartosPackage, "initialize" do +describe Chef::Resource::SmartosPackage do static_provider_resolution( resource: Chef::Resource::SmartosPackage, @@ -30,9 +30,23 @@ describe Chef::Resource::SmartosPackage, "initialize" do platform_family: "smartos" ) - let(:resource) { Chef::Resource::SmartosPackage.new("foo") } + let(:resource) { Chef::Resource::SmartosPackage.new("fakey_fakerton") } it "sets the package_name to the name provided" do - expect(resource.package_name).to eql("foo") + expect(resource.package_name).to eql("fakey_fakerton") + end + + it "sets the default action as :install" do + expect(resource.action).to eql([:install]) + end + + it "supports :install, :lock, :purge, :reconfig, :remove, :unlock, :upgrade actions" do + expect { resource.action :install }.not_to raise_error + expect { resource.action :lock }.not_to raise_error + expect { resource.action :purge }.not_to raise_error + expect { resource.action :reconfig }.not_to raise_error + expect { resource.action :remove }.not_to raise_error + expect { resource.action :unlock }.not_to raise_error + expect { resource.action :upgrade }.not_to raise_error end end diff --git a/spec/unit/resource/solaris_package_spec.rb b/spec/unit/resource/solaris_package_spec.rb index dda8240af8..3502b6b6b8 100644 --- a/spec/unit/resource/solaris_package_spec.rb +++ b/spec/unit/resource/solaris_package_spec.rb @@ -37,4 +37,18 @@ describe Chef::Resource::SolarisPackage, "initialize" do it "sets the package_name to the name provided" do expect(resource.package_name).to eql("foo") end + + it "sets the default action as :install" do + expect(resource.action).to eql([:install]) + end + + it "supports :install, :lock, :purge, :reconfig, :remove, :unlock, :upgrade actions" do + expect { resource.action :install }.not_to raise_error + expect { resource.action :lock }.not_to raise_error + expect { resource.action :purge }.not_to raise_error + expect { resource.action :reconfig }.not_to raise_error + expect { resource.action :remove }.not_to raise_error + expect { resource.action :unlock }.not_to raise_error + expect { resource.action :upgrade }.not_to raise_error + end end diff --git a/spec/unit/resource/subversion_spec.rb b/spec/unit/resource/subversion_spec.rb index dd6526e3dc..b29c880b91 100644 --- a/spec/unit/resource/subversion_spec.rb +++ b/spec/unit/resource/subversion_spec.rb @@ -17,10 +17,8 @@ # require "spec_helper" -require "support/shared/unit/resource/static_provider_resolution" describe Chef::Resource::Subversion do - static_provider_resolution( resource: Chef::Resource::Subversion, provider: Chef::Provider::Subversion, @@ -28,19 +26,27 @@ describe Chef::Resource::Subversion do action: :install ) - let(:resource) { Chef::Resource::Subversion.new("ohai, svn project!") } + let(:resource) { Chef::Resource::Subversion.new("fakey_fakerton") } it "is a subclass of Resource::Scm" do - expect(resource).to be_an_instance_of(Chef::Resource::Subversion) expect(resource).to be_a_kind_of(Chef::Resource::Scm) end - it "set destination property to the name_property" do - expect(resource.destination).to eq("ohai, svn project!") + it "the destination property is the name_property" do + expect(resource.destination).to eql("fakey_fakerton") + end + + it "sets the default action as :sync" do + expect(resource.action).to eql([:sync]) end - it "allows the force_export action" do - expect(resource.allowed_actions).to include(:force_export) + it "supports :checkout, :diff, :export, :force_export, :log, :sync actions" do + expect { resource.action :checkout }.not_to raise_error + expect { resource.action :diff }.not_to raise_error + expect { resource.action :export }.not_to raise_error + expect { resource.action :force_export }.not_to raise_error + expect { resource.action :log }.not_to raise_error + expect { resource.action :sync }.not_to raise_error end it "sets svn info arguments to --no-auth-cache by default" do diff --git a/spec/unit/resource/sudo_spec.rb b/spec/unit/resource/sudo_spec.rb index 8f5103597c..adad4a30f8 100644 --- a/spec/unit/resource/sudo_spec.rb +++ b/spec/unit/resource/sudo_spec.rb @@ -22,18 +22,25 @@ describe Chef::Resource::Sudo do let(:node) { Chef::Node.new } let(:events) { Chef::EventDispatch::Dispatcher.new } let(:run_context) { Chef::RunContext.new(node, {}, events) } - let(:resource) { Chef::Resource::Sudo.new("someone", run_context) } + let(:resource) { Chef::Resource::Sudo.new("fakey_fakerton", run_context) } it "has a resource name of :sudo" do expect(resource.resource_name).to eql(:sudo) end - it "has a default action of create" do + it "the filename property is the name_property" do + expect(resource.filename).to eql("fakey_fakerton") + end + + it "sets the default action as :create" do expect(resource.action).to eql([:create]) end - it "the filename property is the name property" do - expect(resource.filename).to eql("someone") + it "supports :create, :delete, :install, :remove actions" do + expect { resource.action :create }.not_to raise_error + expect { resource.action :delete }.not_to raise_error + expect { resource.action :install }.not_to raise_error + expect { resource.action :remove }.not_to raise_error end it "coerces filename property values . & ~ to __" do diff --git a/spec/unit/resource/swap_file_spec.rb b/spec/unit/resource/swap_file_spec.rb index 905e12646a..9ebd50fa9a 100644 --- a/spec/unit/resource/swap_file_spec.rb +++ b/spec/unit/resource/swap_file_spec.rb @@ -18,23 +18,22 @@ require "spec_helper" describe Chef::Resource::SwapFile do - let(:resource) { Chef::Resource::SwapFile.new("swapfile") } + let(:resource) { Chef::Resource::SwapFile.new("fakey_fakerton") } 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") + it "the path property is the name_property" do + expect(resource.path).to eql("fakey_fakerton") end it "sets the default action as :create" do expect(resource.action).to eql([:create]) end - it "supports :create and :remove actions" do + it "supports :create, :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 index 934db9b9e2..ba4b23f098 100644 --- a/spec/unit/resource/sysctl_spec.rb +++ b/spec/unit/resource/sysctl_spec.rb @@ -18,18 +18,23 @@ require "spec_helper" describe Chef::Resource::Sysctl do - let(:resource) { Chef::Resource::Sysctl.new("something.something") } + let(:resource) { Chef::Resource::Sysctl.new("fakey_fakerton") } it "sets resource name as :sysctl" do expect(resource.resource_name).to eql(:sysctl) end + it "the key property is the name_property" do + expect(resource.key).to eql("fakey_fakerton") + 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") + it "supports :apply, :remove actions" do + expect { resource.action :apply }.not_to raise_error + expect { resource.action :remove }.not_to raise_error end it "coerces Arrays in the value property to space delimited Strings" do @@ -46,11 +51,4 @@ describe Chef::Resource::Sysctl 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/systemd_unit_spec.rb b/spec/unit/resource/systemd_unit_spec.rb index 9d156402a1..fa30255885 100644 --- a/spec/unit/resource/systemd_unit_spec.rb +++ b/spec/unit/resource/systemd_unit_spec.rb @@ -35,29 +35,31 @@ describe Chef::Resource::SystemdUnit do } end - it "has a name property" do - expect(resource.name).to eql("sysstat-collect.timer") + it "the unit_name property is the name_property" do + expect(resource.unit_name).to eql("sysstat-collect.timer") end - it "has a default action of nothing" do + it "sets the default action as :nothing" do expect(resource.action).to eql([:nothing]) end - it "supports appropriate unit actions" do + it "supports :create, :delete, :disable, :enable, :mask, :preset, :reenable, :reload, :reload_or_restart, :reload_or_try_restart, :restart, :revert, :start, :stop, :try_restart, :unmask actions" do expect { resource.action :create }.not_to raise_error expect { resource.action :delete }.not_to raise_error - expect { resource.action :preset }.not_to raise_error - expect { resource.action :revert }.not_to raise_error - expect { resource.action :enable }.not_to raise_error expect { resource.action :disable }.not_to raise_error - expect { resource.action :reenable }.not_to raise_error + expect { resource.action :enable }.not_to raise_error expect { resource.action :mask }.not_to raise_error - expect { resource.action :unmask }.not_to raise_error + expect { resource.action :preset }.not_to raise_error + expect { resource.action :reenable }.not_to raise_error + expect { resource.action :reload }.not_to raise_error + expect { resource.action :reload_or_restart }.not_to raise_error + expect { resource.action :reload_or_try_restart }.not_to raise_error + expect { resource.action :restart }.not_to raise_error + expect { resource.action :revert }.not_to raise_error expect { resource.action :start }.not_to raise_error expect { resource.action :stop }.not_to raise_error - expect { resource.action :restart }.not_to raise_error - expect { resource.action :reload }.not_to raise_error - expect { resource.action :wrong }.to raise_error(ArgumentError) + expect { resource.action :try_restart }.not_to raise_error + expect { resource.action :unmask }.not_to raise_error end it "accepts boolean state properties" do diff --git a/spec/unit/resource/template_spec.rb b/spec/unit/resource/template_spec.rb index 14e48900d3..06469f2f9c 100644 --- a/spec/unit/resource/template_spec.rb +++ b/spec/unit/resource/template_spec.rb @@ -27,6 +27,25 @@ describe Chef::Resource::Template do end end + describe "name" do + it "the path property is the name_property" do + expect(resource.path).to eql("fakey_fakerton") + end + end + + describe "Actions" do + it "sets the default action as :create" do + expect(resource.action).to eql([:create]) + end + + it "supports :create, :create_if_missing, :delete, :touch actions" do + expect { resource.action :create }.not_to raise_error + expect { resource.action :create_if_missing }.not_to raise_error + expect { resource.action :delete }.not_to raise_error + expect { resource.action :touch }.not_to raise_error + end + end + describe "source" do it "accepts a string for the template source" do resource.source "something" diff --git a/spec/unit/resource/windows_ad_join.rb b/spec/unit/resource/windows_ad_join.rb index 7fd02c2021..6c0466e3f8 100644 --- a/spec/unit/resource/windows_ad_join.rb +++ b/spec/unit/resource/windows_ad_join.rb @@ -24,18 +24,22 @@ describe Chef::Resource::WindowsAdJoin do expect(resource.resource_name).to eql(:windows_ad_join) end - it "sets the domain_name as its name" do + it "the domain_name property is the name_property" 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 "supports :join action" do + expect { resource.action :join }.not_to raise_error + end + + it "only accepts FQDNs for the domain_name property" do + expect { resource.domain_name "example" }.to raise_error(ArgumentError) + 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 diff --git a/spec/unit/resource/windows_auto_run_spec.rb b/spec/unit/resource/windows_auto_run_spec.rb index c92bbb2f98..6cdf927831 100644 --- a/spec/unit/resource/windows_auto_run_spec.rb +++ b/spec/unit/resource/windows_auto_run_spec.rb @@ -18,31 +18,31 @@ require "spec_helper" describe Chef::Resource::WindowsAutorun do - let(:resource) { Chef::Resource::WindowsAutorun.new("some_path") } + let(:resource) { Chef::Resource::WindowsAutorun.new("fakey_fakerton") } it "sets resource name as :windows_auto_run" do expect(resource.resource_name).to eql(:windows_auto_run) end + it "the program_name property is the name_property" do + expect(resource.program_name).to eql("fakey_fakerton") + end + it "sets the default action as :create" do expect(resource.action).to eql([:create]) end - it "sets the program_name property as its name" do - expect(resource.program_name).to eql("some_path") + it "supports :create, :remove actions" do + expect { resource.action :create }.not_to raise_error + expect { resource.action :remove }.not_to raise_error end + it "supports :machine and :user in the root property" do expect { resource.root :user }.not_to raise_error expect { resource.root :machine }.not_to raise_error expect { resource.root "user" }.to raise_error(ArgumentError) 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 - it "coerces forward slashes to backslashes for the path" do resource.path "C:/something.exe" expect(resource.path).to eql('C:\\something.exe') diff --git a/spec/unit/resource/windows_env_spec.rb b/spec/unit/resource/windows_env_spec.rb index 776e4f7cd5..06b5af630a 100644 --- a/spec/unit/resource/windows_env_spec.rb +++ b/spec/unit/resource/windows_env_spec.rb @@ -21,33 +21,25 @@ require "spec_helper" describe Chef::Resource::WindowsEnv do - let(:resource) { Chef::Resource::WindowsEnv.new("FOO") } + let(:resource) { Chef::Resource::WindowsEnv.new("fakey_fakerton") } it "creates a new Chef::Resource::WindowsEnv" do expect(resource).to be_a_kind_of(Chef::Resource) expect(resource).to be_a_kind_of(Chef::Resource::WindowsEnv) end - it "has a name" do - expect(resource.name).to eql("FOO") + it "the key_name property is the name_property" do + expect(resource.key_name).to eql("fakey_fakerton") end - it "has a default action of 'create'" do + it "sets the default action as :create" do expect(resource.action).to eql([:create]) end - { :create => false, :delete => false, :modify => false, :flibber => true }.each do |action, bad_value| - it "should #{bad_value ? 'not' : ''} accept #{action}" do - if bad_value - expect { resource.action action }.to raise_error(ArgumentError) - else - expect { resource.action action }.not_to raise_error - end - end - end - - it "uses the object name as the key_name by default" do - expect(resource.key_name).to eql("FOO") + it "supports :create, :delete, :modify actions" do + expect { resource.action :create }.not_to raise_error + expect { resource.action :delete }.not_to raise_error + expect { resource.action :modify }.not_to raise_error end it "accepts a string as the env value via 'value'" do diff --git a/spec/unit/resource/windows_feature.rb b/spec/unit/resource/windows_feature.rb index c8b8587ed8..f01bc3b864 100644 --- a/spec/unit/resource/windows_feature.rb +++ b/spec/unit/resource/windows_feature.rb @@ -18,24 +18,43 @@ require "spec_helper" describe Chef::Resource::WindowsFeature do - let(:resource) { Chef::Resource::WindowsFeature.new("SNMP") } + let(:resource) { Chef::Resource::WindowsFeature.new("fakey_fakerton") } it "sets resource name as :windows_feature" do expect(resource.resource_name).to eql(:windows_feature) end - it "sets the default action as :install" do - expect(resource.action).to eql([:install]) + it "the feature_name property is the name_property" do + expect(resource.feature_name).to eql("fakey_fakerton") end - it "sets the feature_name property as its name" do - expect(resource.feature_name).to eql("SNMP") + it "sets the default action as :install" do + expect(resource.action).to eql([:install]) end - it "supports :install, :remove, and :delete actions" do + it "supports :delete, :install, :remove actions" do + expect { resource.action :delete }.not_to raise_error expect { resource.action :install }.not_to raise_error expect { resource.action :remove }.not_to raise_error - expect { resource.action :delete }.not_to raise_error - expect { resource.action :update }.to raise_error(ArgumentError) end + + it "all property defaults to false" do + expect(resource.all).to eql(false) + end + + it "management_tools property defaults to false" do + expect(resource.management_tools).to eql(false) + end + + it "timeout property defaults to 600" do + expect(resource.timeout).to eql(600) + end + + it "install_method accepts :windows_feature_dism, :windows_feature_powershell, and :windows_feature_servermanagercmd" do + expect { resource.install_method :windows_feature_dism }.not_to raise_error + expect { resource.install_method :windows_feature_powershell }.not_to raise_error + expect { resource.install_method :windows_feature_servermanagercmd }.not_to raise_error + expect { resource.install_method "windows_feature_servermanagercmd" }.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 4f973f7e82..4627387ddb 100644 --- a/spec/unit/resource/windows_feature_dism.rb +++ b/spec/unit/resource/windows_feature_dism.rb @@ -18,7 +18,10 @@ require "spec_helper" describe Chef::Resource::WindowsFeatureDism do - let(:resource) { Chef::Resource::WindowsFeatureDism.new(%w{SNMP DHCP}) } + let(:node) { Chef::Node.new } + let(:events) { Chef::EventDispatch::Dispatcher.new } + let(:run_context) { Chef::RunContext.new(node, {}, events) } + let(:resource) { Chef::Resource::WindowsFeatureDism.new(%w{SNMP DHCP}, run_context) } it "sets resource name as :windows_feature_dism" do expect(resource.resource_name).to eql(:windows_feature_dism) @@ -28,24 +31,42 @@ describe Chef::Resource::WindowsFeatureDism do expect(resource.action).to eql([:install]) end - it "sets the feature_name property as its name property" do + it "the feature_name property is the name_property" do + node.automatic[:platform_version] = "6.2" expect(resource.feature_name).to eql(%w{snmp dhcp}) end - it "coerces comma separated lists of features to a lowercase array" do + it "sets the default action as :install" do + expect(resource.action).to eql([:install]) + end + + it "supports :delete, :install, :remove actions" do + expect { resource.action :delete }.not_to raise_error + expect { resource.action :install }.not_to raise_error + expect { resource.action :remove }.not_to raise_error + end + + it "coerces comma separated lists of features to a lowercase array on 2012+" do + node.automatic[:platform_version] = "6.2" resource.feature_name "SNMP, DHCP" expect(resource.feature_name).to eql(%w{snmp dhcp}) end - it "coerces a single feature as a String to a lowercase array" do + it "coerces a single feature as a String to a lowercase array on 2012+" do + node.automatic[:platform_version] = "6.2" resource.feature_name "SNMP" expect(resource.feature_name).to eql(["snmp"]) end - it "supports :install, :remove, and :delete actions" do - expect { resource.action :install }.not_to raise_error - expect { resource.action :remove }.not_to raise_error - expect { resource.action :delete }.not_to raise_error - expect { resource.action :update }.to raise_error(ArgumentError) + it "coerces comma separated lists of features to an array, but preserves case on < 2012" do + node.automatic[:platform_version] = "6.1" + resource.feature_name "SNMP, DHCP" + expect(resource.feature_name).to eql(%w{SNMP DHCP}) + end + + it "coerces a single feature as a String to an array, but preserves case on < 2012" do + node.automatic[:platform_version] = "6.1" + resource.feature_name "SNMP" + expect(resource.feature_name).to eql(["SNMP"]) end end diff --git a/spec/unit/resource/windows_feature_powershell.rb b/spec/unit/resource/windows_feature_powershell.rb index 5ea226575c..a9b6f5f88f 100644 --- a/spec/unit/resource/windows_feature_powershell.rb +++ b/spec/unit/resource/windows_feature_powershell.rb @@ -28,7 +28,13 @@ describe Chef::Resource::WindowsFeaturePowershell do expect(resource.action).to eql([:install]) end - it "sets the feature_name property as its name property" do + it "supports :delete, :install, :remove actions" do + expect { resource.action :delete }.not_to raise_error + expect { resource.action :install }.not_to raise_error + expect { resource.action :remove }.not_to raise_error + end + + it "sets the feature_name property as its name_property" do expect(resource.feature_name).to eql(%w{SNMP DHCP}) end @@ -42,10 +48,4 @@ describe Chef::Resource::WindowsFeaturePowershell do expect(resource.feature_name).to eql(["SNMP"]) end - it "supports :install, :remove, and :delete actions" do - expect { resource.action :install }.not_to raise_error - expect { resource.action :remove }.not_to raise_error - expect { resource.action :delete }.not_to raise_error - expect { resource.action :update }.to raise_error(ArgumentError) - end end diff --git a/spec/unit/resource/windows_font_spec.rb b/spec/unit/resource/windows_font_spec.rb index a98e3f4a40..cd1050ea19 100644 --- a/spec/unit/resource/windows_font_spec.rb +++ b/spec/unit/resource/windows_font_spec.rb @@ -18,14 +18,14 @@ require "spec_helper" describe Chef::Resource::WindowsFont do - let(:resource) { Chef::Resource::WindowsFont.new("some_font") } + let(:resource) { Chef::Resource::WindowsFont.new("fakey_fakerton") } it "sets resource name as :windows_font" do expect(resource.resource_name).to eql(:windows_font) end - it "sets the font_name as its name" do - expect(resource.font_name).to eql("some_font") + it "the font_name property is the name_property" do + expect(resource.font_name).to eql("fakey_fakerton") end it "sets the default action as :install" do @@ -34,7 +34,6 @@ describe Chef::Resource::WindowsFont do it "supports :install action" do expect { resource.action :install }.not_to raise_error - expect { resource.action :remove }.to raise_error(ArgumentError) end it "coerces backslashes in the source property to forward slashes" do diff --git a/spec/unit/resource/windows_package_spec.rb b/spec/unit/resource/windows_package_spec.rb index bb4052f8e3..5a2cfcf99f 100644 --- a/spec/unit/resource/windows_package_spec.rb +++ b/spec/unit/resource/windows_package_spec.rb @@ -37,8 +37,18 @@ describe Chef::Resource::WindowsPackage, "initialize" do expect(resource).to be_a_kind_of(Chef::Resource::Package) end - it "sets the resource_name to :windows_package" do - expect(resource.resource_name).to eql(:windows_package) + it "sets the default action as :install" do + expect(resource.action).to eql([:install]) + end + + it "supports :install, :lock, :purge, :reconfig, :remove, :unlock, :upgrade actions" do + expect { resource.action :install }.not_to raise_error + expect { resource.action :lock }.not_to raise_error + expect { resource.action :purge }.not_to raise_error + expect { resource.action :reconfig }.not_to raise_error + expect { resource.action :remove }.not_to raise_error + expect { resource.action :unlock }.not_to raise_error + expect { resource.action :upgrade }.not_to raise_error end it "supports setting installer_type as a symbol" do diff --git a/spec/unit/resource/windows_pagefile_spec.rb b/spec/unit/resource/windows_pagefile_spec.rb index dd6353eccb..fff3cf3274 100644 --- a/spec/unit/resource/windows_pagefile_spec.rb +++ b/spec/unit/resource/windows_pagefile_spec.rb @@ -24,22 +24,26 @@ describe Chef::Resource::WindowsPagefile do expect(resource.resource_name).to eql(:windows_pagefile) end - it "sets the path as its name" do + it "the path property is the name_property" do expect(resource.path).to eql("C:\\pagefile.sys") end + it "sets the default action as :set" do + expect(resource.action).to eql([:set]) + end + + it "supports :delete, :set actions" do + expect { resource.action :delete }.not_to raise_error + expect { resource.action :set }.not_to raise_error + end + 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 - expect(resource.action).to eql([:set]) + it "automatic_managed property defaults to false" do + expect(resource.automatic_managed).to eql(false) end - it "supports :set and :delete actions" do - expect { resource.action :set }.not_to raise_error - expect { resource.action :delete }.not_to raise_error - expect { resource.action :create }.to raise_error(ArgumentError) - end end diff --git a/spec/unit/resource/windows_path_spec.rb b/spec/unit/resource/windows_path_spec.rb index 8f29a11e4e..423d10aa61 100644 --- a/spec/unit/resource/windows_path_spec.rb +++ b/spec/unit/resource/windows_path_spec.rb @@ -19,23 +19,22 @@ require "spec_helper" describe Chef::Resource::WindowsPath do - let(:resource) { Chef::Resource::WindowsPath.new("some_path") } + let(:resource) { Chef::Resource::WindowsPath.new("fakey_fakerton") } it "sets resource name as :windows_path" do expect(resource.resource_name).to eql(:windows_path) end - it "sets the path as its name" do - expect(resource.path).to eql("some_path") + it "the path property is the name_property" do + expect(resource.path).to eql("fakey_fakerton") end it "sets the default action as :add" do expect(resource.action).to eql([:add]) end - it "supports :add and :remove actions" do + it "supports :add, :remove actions" do expect { resource.action :add }.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/windows_printer_port_spec.rb b/spec/unit/resource/windows_printer_port_spec.rb index 6b29c2610a..a0267f81e2 100644 --- a/spec/unit/resource/windows_printer_port_spec.rb +++ b/spec/unit/resource/windows_printer_port_spec.rb @@ -24,7 +24,7 @@ describe Chef::Resource::WindowsPrinterPort do expect(resource.resource_name).to eql(:windows_printer_port) end - it "sets the ipv4_address as its name" do + it "the ipv4_address property is the name_property" do expect(resource.ipv4_address).to eql("63.192.209.236") end @@ -32,10 +32,27 @@ describe Chef::Resource::WindowsPrinterPort do expect(resource.action).to eql([:create]) end - it "supports :create and :delete actions" do + it "supports :create, :delete actions" do expect { resource.action :create }.not_to raise_error expect { resource.action :delete }.not_to raise_error - expect { resource.action :remove }.to raise_error(ArgumentError) + end + + it "port_number property defaults to 9100" do + expect(resource.port_number).to eql(9100) + end + + it "snmp_enabled property defaults to false" do + expect(resource.snmp_enabled).to eql(false) + end + + it "port_protocol property defaults to 1" do + expect(resource.port_protocol).to eql(1) + end + + it "raises an error if port_protocol isn't in 1 or 2" do + expect { resource.port_protocol 1 }.not_to raise_error + expect { resource.port_protocol 2 }.not_to raise_error + expect { resource.port_protocol 3 }.to raise_error(ArgumentError) end it "raises an error if ipv4_address isn't in X.X.X.X format" do diff --git a/spec/unit/resource/windows_printer_spec.rb b/spec/unit/resource/windows_printer_spec.rb index 5c773005ea..107bde6296 100644 --- a/spec/unit/resource/windows_printer_spec.rb +++ b/spec/unit/resource/windows_printer_spec.rb @@ -18,24 +18,31 @@ require "spec_helper" describe Chef::Resource::WindowsPrinter do - let(:resource) { Chef::Resource::WindowsPrinter.new("some_printer") } + let(:resource) { Chef::Resource::WindowsPrinter.new("fakey_fakerton") } it "sets resource name as :windows_printer" do expect(resource.resource_name).to eql(:windows_printer) end - it "sets the device_id as its name" do - expect(resource.device_id).to eql("some_printer") + it "the device_id property is the name_property" do + expect(resource.device_id).to eql("fakey_fakerton") end it "sets the default action as :create" do expect(resource.action).to eql([:create]) end - it "supports :create and :delete actions" do + it "supports :create, :delete actions" do expect { resource.action :create }.not_to raise_error expect { resource.action :delete }.not_to raise_error - expect { resource.action :remove }.to raise_error(ArgumentError) + end + + it "default property defaults to false" do + expect(resource.default).to eql(false) + end + + it "shared property defaults to false" do + expect(resource.shared).to eql(false) end it "raises an error if ipv4_address isn't in X.X.X.X format" do diff --git a/spec/unit/resource/windows_service_spec.rb b/spec/unit/resource/windows_service_spec.rb index f5de5b6965..29f5821a15 100644 --- a/spec/unit/resource/windows_service_spec.rb +++ b/spec/unit/resource/windows_service_spec.rb @@ -27,12 +27,35 @@ describe Chef::Resource::WindowsService, "initialize" do action: :start ) - let(:resource) { Chef::Resource::WindowsService.new("BITS") } + let(:resource) { Chef::Resource::WindowsService.new("fakey_fakerton") } it "sets the resource_name to :windows_service" do expect(resource.resource_name).to eql(:windows_service) end + it "the service_name property is the name_property" do + expect(resource.service_name).to eql("fakey_fakerton") + end + + it "sets the default action as :nothing" do + expect(resource.action).to eql([:nothing]) + end + + it "supports :configure, :configure_startup, :create, :delete, :disable, :enable, :mask, :reload, :restart, :start, :stop, :unmask actions" do + expect { resource.action :configure }.not_to raise_error + expect { resource.action :configure_startup }.not_to raise_error + expect { resource.action :create }.not_to raise_error + expect { resource.action :delete }.not_to raise_error + expect { resource.action :disable }.not_to raise_error + expect { resource.action :enable }.not_to raise_error + expect { resource.action :mask }.not_to raise_error + expect { resource.action :reload }.not_to raise_error + expect { resource.action :restart }.not_to raise_error + expect { resource.action :start }.not_to raise_error + expect { resource.action :stop }.not_to raise_error + expect { resource.action :unmask }.not_to raise_error + end + it "supports setting startup_type" do resource.startup_type(:manual) expect(resource.startup_type).to eql(:manual) diff --git a/spec/unit/resource/windows_shortcut_spec.rb b/spec/unit/resource/windows_shortcut_spec.rb index 0b5e2325b9..cb32ab91bb 100644 --- a/spec/unit/resource/windows_shortcut_spec.rb +++ b/spec/unit/resource/windows_shortcut_spec.rb @@ -18,22 +18,21 @@ require "spec_helper" describe Chef::Resource::WindowsShortcut do - let(:resource) { Chef::Resource::WindowsShortcut.new("some_path") } + let(:resource) { Chef::Resource::WindowsShortcut.new("fakey_fakerton") } it "sets resource name as :windows_shortcut" do expect(resource.resource_name).to eql(:windows_shortcut) end - it "sets the shortcut_name property as its name" do - expect(resource.shortcut_name).to eql("some_path") + it "the shortcut_name property is the name_property" do + expect(resource.shortcut_name).to eql("fakey_fakerton") end it "sets the default action as :create" do expect(resource.action).to eql([:create]) end - it "supports :create action only" do + it "supports :create action" do expect { resource.action :create }.not_to raise_error - expect { resource.action :delete }.to raise_error(ArgumentError) end end diff --git a/spec/unit/resource/yum_repository_spec.rb b/spec/unit/resource/yum_repository_spec.rb index 353ff7ce23..13301dca69 100644 --- a/spec/unit/resource/yum_repository_spec.rb +++ b/spec/unit/resource/yum_repository_spec.rb @@ -22,20 +22,56 @@ describe Chef::Resource::YumRepository do let(:node) { Chef::Node.new } let(:events) { Chef::EventDispatch::Dispatcher.new } let(:run_context) { Chef::RunContext.new(node, {}, events) } - let(:resource) { Chef::Resource::YumRepository.new("multiverse", run_context) } + let(:resource) { Chef::Resource::YumRepository.new("fakey_fakerton", run_context) } it "has a resource_name of :yum_repository" do expect(resource.resource_name).to eq(:yum_repository) end it "the repositoryid property is the name_property" do - expect(resource.repositoryid).to eq("multiverse") + expect(resource.repositoryid).to eql("fakey_fakerton") + end + + it "sets the default action as :create" do + expect(resource.action).to eql([:create]) + end + + it "supports :add, :create, :delete, :makecache, :remove actions" do + expect { resource.action :add }.not_to raise_error + expect { resource.action :create }.not_to raise_error + expect { resource.action :delete }.not_to raise_error + expect { resource.action :makecache }.not_to raise_error + expect { resource.action :remove }.not_to raise_error end it "fails if the user provides a repositoryid with a forward slash" do expect { resource.repositoryid "foo/bar" }.to raise_error(ArgumentError) end + it "clean_headers property defaults to false" do + expect(resource.clean_headers).to eql(false) + end + + it "clean_metadata property defaults to true" do + expect(resource.clean_metadata).to eql(true) + end + + it "description property defaults to 'Yum Repository'" do + expect(resource.description).to eql("Yum Repository") + end + + it "enabled property defaults to true" do + expect(resource.enabled).to eql(true) + end + + it "make_cache property defaults to true" do + expect(resource.make_cache).to eql(true) + end + + it "mode property defaults to '0644'" do + expect(resource.mode).to eql("0644") + end + it "the timeout property expects numeric Strings" do expect { resource.timeout "123" }.not_to raise_error(ArgumentError) expect { resource.timeout "123foo" }.to raise_error(ArgumentError) @@ -86,6 +122,16 @@ describe Chef::Resource::YumRepository do expect { resource.mirrorlist_expire "never" }.to raise_error(ArgumentError) end + it "accepts the legacy 'url' property" do + resource.url "foo" + expect(resource.baseurl).to eql("foo") + end + + it "accepts the legacy 'keyurl' property" do + resource.keyurl "foo" + expect(resource.gpgkey).to eql("foo") + end + context "on linux", :linux_only do it "resolves to a Noop class when yum is not found" do expect(Chef::Provider::YumRepository).to receive(:which).with("yum").and_return(false) diff --git a/spec/unit/resource/zypper_package_spec.rb b/spec/unit/resource/zypper_package_spec.rb new file mode 100644 index 0000000000..fff2fd2a59 --- /dev/null +++ b/spec/unit/resource/zypper_package_spec.rb @@ -0,0 +1,51 @@ +# +# Author:: Tim Smith (<tsmith@chef.io>) +# 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" +require "support/shared/unit/resource/static_provider_resolution" + +describe Chef::Resource::ZypperPackage, "initialize" do + + static_provider_resolution( + resource: Chef::Resource::ZypperPackage, + provider: Chef::Provider::Package::Zypper, + name: :zypper_package, + action: :install, + os: "linux", + platform_family: "suse" + ) + +end + +describe Chef::Resource::ZypperPackage, "defaults" do + let(:resource) { Chef::Resource::ZypperPackage.new("fakey_fakerton") } + + it "sets the default action as :install" do + expect(resource.action).to eql([:install]) + end + + it "supports :install, :lock, :purge, :reconfig, :remove, :unlock, :upgrade actions" do + expect { resource.action :install }.not_to raise_error + expect { resource.action :lock }.not_to raise_error + expect { resource.action :purge }.not_to raise_error + expect { resource.action :reconfig }.not_to raise_error + expect { resource.action :remove }.not_to raise_error + expect { resource.action :unlock }.not_to raise_error + expect { resource.action :upgrade }.not_to raise_error + end +end diff --git a/spec/unit/resource/zypper_repository_spec.rb b/spec/unit/resource/zypper_repository_spec.rb index 8f93aecd8e..a6a523a33f 100644 --- a/spec/unit/resource/zypper_repository_spec.rb +++ b/spec/unit/resource/zypper_repository_spec.rb @@ -22,30 +22,75 @@ describe Chef::Resource::ZypperRepository do let(:node) { Chef::Node.new } let(:events) { Chef::EventDispatch::Dispatcher.new } let(:run_context) { Chef::RunContext.new(node, {}, events) } - let(:resource) { Chef::Resource::ZypperRepository.new("repo-source", run_context) } + let(:resource) { Chef::Resource::ZypperRepository.new("fakey_fakerton", run_context) } it "has a resource_name of :zypper_repository" do expect(resource.resource_name).to eq(:zypper_repository) end - it "repo_name is the name_property" do - expect(resource.repo_name).to eql("repo-source") + it "the repo_name property is the name_property" do + expect(resource.repo_name).to eql("fakey_fakerton") end - it "fails if the user provides a repo_name with a forward slash" do - expect { resource.repo_name "foo/bar" }.to raise_error(ArgumentError) - end - - it "has a default action of create" do + it "sets the default action as :create" do expect(resource.action).to eql([:create]) end - it "supports all valid actions" do + it "supports :add, :create, :refresh, :remove actions" do expect { resource.action :add }.not_to raise_error - expect { resource.action :remove }.not_to raise_error expect { resource.action :create }.not_to raise_error expect { resource.action :refresh }.not_to raise_error - expect { resource.action :delete }.to raise_error(ArgumentError) + expect { resource.action :remove }.not_to raise_error + end + + it "fails if the user provides a repo_name with a forward slash" do + expect { resource.repo_name "foo/bar" }.to raise_error(ArgumentError) + end + + it "type property defaults to 'NONE'" do + expect(resource.type).to eql("NONE") + end + + it "enabled property defaults to true" do + expect(resource.enabled).to eql(true) + end + + it "autorefresh property defaults to true" do + expect(resource.autorefresh).to eql(true) + end + + it "gpgcheck property defaults to true" do + expect(resource.gpgcheck).to eql(true) + end + + it "keeppackages property defaults to false" do + expect(resource.keeppackages).to eql(false) + end + + it "priority property defaults to 99" do + expect(resource.priority).to eql(99) + end + + it "mode property defaults to '0644'" do + expect(resource.mode).to eql("0644") + end + + it "refresh_cache property defaults to true" do + expect(resource.refresh_cache).to eql(true) + end + + it "gpgautoimportkeys property defaults to true" do + expect(resource.gpgautoimportkeys).to eql(true) + end + + it "accepts the legacy 'key' property" do + resource.key "foo" + expect(resource.gpgkey).to eql("foo") + end + + it "accepts the legacy 'uri' property" do + resource.uri "foo" + expect(resource.baseurl).to eql("foo") end context "on linux", :linux_only do |