summaryrefslogtreecommitdiff
path: root/spec/unit
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit')
-rw-r--r--spec/unit/application/client_spec.rb1
-rw-r--r--spec/unit/application_spec.rb1
-rw-r--r--spec/unit/chef_fs/data_handler/data_handler_base_spec.rb65
-rw-r--r--spec/unit/formatters/base_spec.rb39
-rw-r--r--spec/unit/node_spec.rb6
-rw-r--r--spec/unit/provider/git_spec.rb8
-rw-r--r--spec/unit/provider/mount/mount_spec.rb3
-rw-r--r--spec/unit/provider/package/apt_spec.rb2
-rw-r--r--spec/unit/provider/package/powershell_spec.rb38
-rw-r--r--spec/unit/provider/package/zypper_spec.rb67
-rw-r--r--spec/unit/provider/powershell_script_spec.rb2
-rw-r--r--spec/unit/provider/service/debian_service_spec.rb202
-rw-r--r--spec/unit/provider/user/dscl_spec.rb11
-rw-r--r--spec/unit/provider/windows_task_spec.rb868
-rw-r--r--spec/unit/resource/apt_package_spec.rb14
-rw-r--r--spec/unit/resource/apt_preference_spec.rb15
-rw-r--r--spec/unit/resource/apt_repository_spec.rb15
-rw-r--r--spec/unit/resource/apt_update_spec.rb9
-rw-r--r--spec/unit/resource/bash_spec.rb8
-rw-r--r--spec/unit/resource/bff_package_spec.rb51
-rw-r--r--spec/unit/resource/breakpoint_spec.rb8
-rw-r--r--spec/unit/resource/build_essential_spec.rb14
-rw-r--r--spec/unit/resource/cab_package_spec.rb10
-rw-r--r--spec/unit/resource/chef_gem_spec.rb14
-rw-r--r--spec/unit/resource/chef_handler_spec.rb13
-rw-r--r--spec/unit/resource/chocolatey_package_spec.rb16
-rw-r--r--spec/unit/resource/cookbook_file_spec.rb15
-rw-r--r--spec/unit/resource/cron_spec.rb9
-rw-r--r--spec/unit/resource/csh_spec.rb8
-rw-r--r--spec/unit/resource/directory_spec.rb13
-rw-r--r--spec/unit/resource/dmg_package_spec.rb12
-rw-r--r--spec/unit/resource/dnf_package_spec.rb17
-rw-r--r--spec/unit/resource/dpkg_package_spec.rb18
-rw-r--r--spec/unit/resource/dsc_resource_spec.rb12
-rw-r--r--spec/unit/resource/dsc_script_spec.rb78
-rw-r--r--spec/unit/resource/execute_spec.rb32
-rw-r--r--spec/unit/resource/file_spec.rb20
-rw-r--r--spec/unit/resource/freebsd_package_spec.rb16
-rw-r--r--spec/unit/resource/gem_package_spec.rb14
-rw-r--r--spec/unit/resource/git_spec.rb19
-rw-r--r--spec/unit/resource/group_spec.rb35
-rw-r--r--spec/unit/resource/homebrew_cask_spec.rb13
-rw-r--r--spec/unit/resource/homebrew_package_spec.rb14
-rw-r--r--spec/unit/resource/homebrew_tap_spec.rb11
-rw-r--r--spec/unit/resource/hostname_spec.rb16
-rw-r--r--spec/unit/resource/http_request_spec.rb14
-rw-r--r--spec/unit/resource/ips_package_spec.rb18
-rw-r--r--spec/unit/resource/ksh_spec.rb8
-rw-r--r--spec/unit/resource/launchd_spec.rb16
-rw-r--r--spec/unit/resource/link_spec.rb17
-rw-r--r--spec/unit/resource/log_spec.rb16
-rw-r--r--spec/unit/resource/macos_user_defaults_spec.rb6
-rw-r--r--spec/unit/resource/macports_package_spec.rb19
-rw-r--r--spec/unit/resource/mdadm_spec.rb10
-rw-r--r--spec/unit/resource/mount_spec.rb33
-rw-r--r--spec/unit/resource/msu_package_spec.rb10
-rw-r--r--spec/unit/resource/ohai_hint_spec.rb17
-rw-r--r--spec/unit/resource/ohai_spec.rb14
-rw-r--r--spec/unit/resource/openbsd_package_spec.rb14
-rw-r--r--spec/unit/resource/openssl_dhparam.rb15
-rw-r--r--spec/unit/resource/openssl_rsa_private_key_spec.rb15
-rw-r--r--spec/unit/resource/openssl_rsa_public_key_spec.rb14
-rw-r--r--spec/unit/resource/osx_profile_spec.rb11
-rw-r--r--spec/unit/resource/package_spec.rb14
-rw-r--r--spec/unit/resource/pacman_package_spec.rb20
-rw-r--r--spec/unit/resource/paludis_package_spec.rb36
-rw-r--r--spec/unit/resource/perl_spec.rb8
-rw-r--r--spec/unit/resource/portage_package_spec.rb14
-rw-r--r--spec/unit/resource/powershell_package_spec.rb14
-rw-r--r--spec/unit/resource/python_spec.rb8
-rw-r--r--spec/unit/resource/reboot_spec.rb8
-rw-r--r--spec/unit/resource/registry_key_spec.rb15
-rw-r--r--spec/unit/resource/remote_directory_spec.rb21
-rw-r--r--spec/unit/resource/remote_file_spec.rb19
-rw-r--r--spec/unit/resource/rhsm_errata_level_spec.rb10
-rw-r--r--spec/unit/resource/rhsm_errata_spec.rb12
-rw-r--r--spec/unit/resource/rhsm_register_spec.rb7
-rw-r--r--spec/unit/resource/rhsm_repo_spec.rb13
-rw-r--r--spec/unit/resource/rhsm_subscription_spec.rb13
-rw-r--r--spec/unit/resource/route_spec.rb13
-rw-r--r--spec/unit/resource/rpm_package_spec.rb14
-rw-r--r--spec/unit/resource/ruby_block_spec.rb20
-rw-r--r--spec/unit/resource/ruby_spec.rb8
-rw-r--r--spec/unit/resource/scm_spec.rb24
-rw-r--r--spec/unit/resource/script_spec.rb8
-rw-r--r--spec/unit/resource/service_spec.rb15
-rw-r--r--spec/unit/resource/smartos_package_spec.rb22
-rw-r--r--spec/unit/resource/solaris_package_spec.rb14
-rw-r--r--spec/unit/resource/subversion_spec.rb22
-rw-r--r--spec/unit/resource/sudo_spec.rb15
-rw-r--r--spec/unit/resource/swap_file_spec.rb9
-rw-r--r--spec/unit/resource/sysctl_spec.rb18
-rw-r--r--spec/unit/resource/systemd_unit_spec.rb26
-rw-r--r--spec/unit/resource/template_spec.rb19
-rw-r--r--spec/unit/resource/windows_ad_join.rb14
-rw-r--r--spec/unit/resource/windows_auto_run_spec.rb18
-rw-r--r--spec/unit/resource/windows_env_spec.rb24
-rw-r--r--spec/unit/resource/windows_feature.rb35
-rw-r--r--spec/unit/resource/windows_feature_dism.rb39
-rw-r--r--spec/unit/resource/windows_feature_powershell.rb14
-rw-r--r--spec/unit/resource/windows_font_spec.rb7
-rw-r--r--spec/unit/resource/windows_package_spec.rb14
-rw-r--r--spec/unit/resource/windows_pagefile_spec.rb20
-rw-r--r--spec/unit/resource/windows_path_spec.rb9
-rw-r--r--spec/unit/resource/windows_printer_port_spec.rb23
-rw-r--r--spec/unit/resource/windows_printer_spec.rb17
-rw-r--r--spec/unit/resource/windows_service_spec.rb25
-rw-r--r--spec/unit/resource/windows_shortcut_spec.rb9
-rw-r--r--spec/unit/resource/windows_task_spec.rb88
-rw-r--r--spec/unit/resource/yum_repository_spec.rb50
-rw-r--r--spec/unit/resource/zypper_package_spec.rb51
-rw-r--r--spec/unit/resource/zypper_repository_spec.rb67
-rw-r--r--spec/unit/resource_spec.rb10
113 files changed, 1924 insertions, 1228 deletions
diff --git a/spec/unit/application/client_spec.rb b/spec/unit/application/client_spec.rb
index 0cd3cb3995..de6972b625 100644
--- a/spec/unit/application/client_spec.rb
+++ b/spec/unit/application/client_spec.rb
@@ -447,6 +447,7 @@ describe Chef::Application::Client, "configure_chef" do
before do
@original_argv = ARGV.dup
ARGV.clear
+ allow(::File).to receive(:read).and_call_original
allow(::File).to receive(:read).with(Chef::Config.platform_specific_path("/etc/chef/client.rb")).and_return("")
app.configure_chef
end
diff --git a/spec/unit/application_spec.rb b/spec/unit/application_spec.rb
index 273f605905..76be387c22 100644
--- a/spec/unit/application_spec.rb
+++ b/spec/unit/application_spec.rb
@@ -101,6 +101,7 @@ describe Chef::Application do
@app = Chef::Application.new
allow(@app).to receive(:parse_options).and_return(true)
+ allow(::File).to receive(:read).with("/proc/sys/crypto/fips_enabled").and_call_original
expect(Chef::Config).to receive(:export_proxies).and_return(true)
end
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/formatters/base_spec.rb b/spec/unit/formatters/base_spec.rb
index 30c7757e5a..19182554f9 100644
--- a/spec/unit/formatters/base_spec.rb
+++ b/spec/unit/formatters/base_spec.rb
@@ -23,6 +23,14 @@ describe Chef::Formatters::Base do
let(:out) { StringIO.new }
let(:err) { StringIO.new }
let(:formatter) { Chef::Formatters::Base.new(out, err) }
+ let(:exception) do
+ # An exception with a real backtrace.
+ begin
+ raise EOFError
+ rescue EOFError => exc
+ end
+ exc
+ end
it "starts with an indentation of zero" do
expect(formatter.output.indent).to eql(0)
@@ -45,27 +53,48 @@ describe Chef::Formatters::Base do
end
it "humanizes EOFError exceptions for #registration_failed" do
- formatter.registration_failed("foo.example.com", EOFError.new, double("Chef::Config"))
+ formatter.registration_failed("foo.example.com", exception, double("Chef::Config"))
expect(out.string).to match(/Received an EOF on transport socket/)
end
it "humanizes EOFError exceptions for #node_load_failed" do
- formatter.node_load_failed("foo.example.com", EOFError.new, double("Chef::Config"))
+ formatter.node_load_failed("foo.example.com", exception, double("Chef::Config"))
expect(out.string).to match(/Received an EOF on transport socket/)
end
it "humanizes EOFError exceptions for #run_list_expand_failed" do
- formatter.run_list_expand_failed(double("Chef::Node"), EOFError.new)
+ formatter.run_list_expand_failed(double("Chef::Node"), exception)
expect(out.string).to match(/Received an EOF on transport socket/)
end
it "humanizes EOFError exceptions for #cookbook_resolution_failed" do
- formatter.run_list_expand_failed(double("Expanded Run List"), EOFError.new)
+ formatter.run_list_expand_failed(double("Expanded Run List"), exception)
expect(out.string).to match(/Received an EOF on transport socket/)
end
it "humanizes EOFError exceptions for #cookbook_sync_failed" do
- formatter.cookbook_sync_failed("foo.example.com", EOFError.new)
+ formatter.cookbook_sync_failed("foo.example.com", exception)
expect(out.string).to match(/Received an EOF on transport socket/)
end
+
+ it "outputs error information for failed resources with ignore_failure true" do
+ resource = Chef::Resource::RubyBlock.new("test")
+ resource.ignore_failure(true)
+ formatter.resource_failed(resource, :run, exception)
+ expect(out.string).to match(/Error executing action `run` on resource 'ruby_block\[test\]'/)
+ end
+
+ it "does not output error information for failed resources with ignore_failure :quiet" do
+ resource = Chef::Resource::RubyBlock.new("test")
+ resource.ignore_failure(:quiet)
+ formatter.resource_failed(resource, :run, exception)
+ expect(out.string).to eq("")
+ end
+
+ it "does not output error information for failed resources with ignore_failure 'quiet'" do
+ resource = Chef::Resource::RubyBlock.new("test")
+ resource.ignore_failure("quiet")
+ formatter.resource_failed(resource, :run, exception)
+ expect(out.string).to eq("")
+ end
end
diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb
index c9f3d7d1d2..3a43a155d5 100644
--- a/spec/unit/node_spec.rb
+++ b/spec/unit/node_spec.rb
@@ -1160,16 +1160,16 @@ describe Chef::Node do
describe "roles" do
it "should allow you to query whether or not it has a recipe applied with role?" do
- node.run_list << "role[sunrise]"
+ node.automatic["roles"] = %w{sunrise}
expect(node.role?("sunrise")).to eql(true)
expect(node.role?("not at home")).to eql(false)
end
it "should allow you to set roles with arguments" do
- node.run_list << "role[one]"
- node.run_list << "role[two]"
+ node.automatic["roles"] = %w{one two}
expect(node.role?("one")).to eql(true)
expect(node.role?("two")).to eql(true)
+ expect(node.role?("three")).to eql(false)
end
end
diff --git a/spec/unit/provider/git_spec.rb b/spec/unit/provider/git_spec.rb
index cacee0baaa..b8a26a3543 100644
--- a/spec/unit/provider/git_spec.rb
+++ b/spec/unit/provider/git_spec.rb
@@ -425,7 +425,7 @@ SHAS
it "runs a sync command with default options" do
expect(@provider).to receive(:setup_remote_tracking_branches).with(@resource.remote, @resource.repository)
- expected_cmd1 = "git fetch origin"
+ expected_cmd1 = "git fetch --prune origin"
expect(@provider).to receive(:shell_out!).with(expected_cmd1, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]")
expected_cmd2 = "git fetch origin --tags"
expect(@provider).to receive(:shell_out!).with(expected_cmd2, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]")
@@ -440,7 +440,7 @@ SHAS
@resource.group("thisis")
expect(@provider).to receive(:setup_remote_tracking_branches).with(@resource.remote, @resource.repository)
- expected_cmd1 = "git fetch origin"
+ expected_cmd1 = "git fetch --prune origin"
expect(@provider).to receive(:shell_out!).with(expected_cmd1, :cwd => "/my/deploy/dir",
:user => "whois", :group => "thisis",
:log_tag => "git[web2.0 app]",
@@ -461,7 +461,7 @@ SHAS
it "configures remote tracking branches when remote is ``origin''" do
@resource.remote "origin"
expect(@provider).to receive(:setup_remote_tracking_branches).with(@resource.remote, @resource.repository)
- fetch_command1 = "git fetch origin"
+ fetch_command1 = "git fetch --prune origin"
expect(@provider).to receive(:shell_out!).with(fetch_command1, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]")
fetch_command2 = "git fetch origin --tags"
expect(@provider).to receive(:shell_out!).with(fetch_command2, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]")
@@ -473,7 +473,7 @@ SHAS
it "configures remote tracking branches when remote is not ``origin''" do
@resource.remote "opscode"
expect(@provider).to receive(:setup_remote_tracking_branches).with(@resource.remote, @resource.repository)
- fetch_command1 = "git fetch opscode"
+ fetch_command1 = "git fetch --prune opscode"
expect(@provider).to receive(:shell_out!).with(fetch_command1, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]")
fetch_command2 = "git fetch opscode --tags"
expect(@provider).to receive(:shell_out!).with(fetch_command2, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]")
diff --git a/spec/unit/provider/mount/mount_spec.rb b/spec/unit/provider/mount/mount_spec.rb
index cd663b9684..af7916e5bd 100644
--- a/spec/unit/provider/mount/mount_spec.rb
+++ b/spec/unit/provider/mount/mount_spec.rb
@@ -495,7 +495,8 @@ describe Chef::Provider::Mount::Mount do
# the fstab might contain the mount with the device as a device but the resource has a label.
# we should not create two mount lines, but update the existing one
- context "when the device is described differently" do
+ # not supported on solaris because it can't cope with a UUID device type
+ context "when the device is described differently", :not_supported_on_solaris do
it "should update the existing line" do
@current_resource.enabled(true)
status = double(:stdout => "/dev/sdz1\n", :exitstatus => 1)
diff --git a/spec/unit/provider/package/apt_spec.rb b/spec/unit/provider/package/apt_spec.rb
index 78c517b9a0..0700f69eb4 100644
--- a/spec/unit/provider/package/apt_spec.rb
+++ b/spec/unit/provider/package/apt_spec.rb
@@ -422,7 +422,6 @@ mpg123 1.12.1-0ubuntu1
)
expect(logger).to receive(:trace).with("#{@provider.new_resource} is already locked")
- @provider.new_resource.package_name = ["irssi"]
@provider.action_lock
end
end
@@ -444,7 +443,6 @@ mpg123 1.12.1-0ubuntu1
)
expect(logger).to receive(:trace).with("#{@provider.new_resource} is already unlocked")
- @provider.new_resource.package_name = ["irssi"]
@provider.action_unlock
end
end
diff --git a/spec/unit/provider/package/powershell_spec.rb b/spec/unit/provider/package/powershell_spec.rb
index 9bebfa9194..534b7b6b13 100644
--- a/spec/unit/provider/package/powershell_spec.rb
+++ b/spec/unit/provider/package/powershell_spec.rb
@@ -192,88 +192,88 @@ describe Chef::Provider::Package::Powershell do
end
- describe "#build_powershell_command" do
+ describe "#build_powershell_package_command" do
it "can build a valid command from a single string" do
- expect(provider.build_powershell_command("Get-Package posh-git")).to eql(generated_command)
+ expect(provider.build_powershell_package_command("Get-Package posh-git")).to eql(generated_command)
end
it "can build a valid command from an array" do
- expect(provider.build_powershell_command(["Get-Package", "posh-git"])).to eql(generated_command)
+ expect(provider.build_powershell_package_command(["Get-Package", "posh-git"])).to eql(generated_command)
end
context "when source is nil" do
it "build get commands correctly" do
- expect(provider.build_powershell_command("Get-Package xNetworking")).to eql(generated_get_cmdlet)
+ expect(provider.build_powershell_package_command("Get-Package xNetworking")).to eql(generated_get_cmdlet)
end
it "build get commands correctly when a version is passed" do
- expect(provider.build_powershell_command("Get-Package xNetworking", "1.0.0.0")).to eql(generated_get_cmdlet_with_version)
+ expect(provider.build_powershell_package_command("Get-Package xNetworking", "1.0.0.0")).to eql(generated_get_cmdlet_with_version)
end
it "builds find commands correctly" do
- expect(provider.build_powershell_command("Find-Package xNetworking")).to eql(generated_find_cmdlet)
+ expect(provider.build_powershell_package_command("Find-Package xNetworking")).to eql(generated_find_cmdlet)
end
it "builds find commands correctly when a version is passed" do
- expect(provider.build_powershell_command("Find-Package xNetworking", "1.0.0.0")).to eql(generated_find_cmdlet_with_version)
+ expect(provider.build_powershell_package_command("Find-Package xNetworking", "1.0.0.0")).to eql(generated_find_cmdlet_with_version)
end
it "build install commands correctly" do
- expect(provider.build_powershell_command("Install-Package xNetworking")).to eql(generated_install_cmdlet)
+ expect(provider.build_powershell_package_command("Install-Package xNetworking")).to eql(generated_install_cmdlet)
end
it "build install commands correctly when a version is passed" do
- expect(provider.build_powershell_command("Install-Package xNetworking", "1.0.0.0")).to eql(generated_install_cmdlet_with_version)
+ expect(provider.build_powershell_package_command("Install-Package xNetworking", "1.0.0.0")).to eql(generated_install_cmdlet_with_version)
end
it "build install commands correctly" do
- expect(provider.build_powershell_command("Uninstall-Package xNetworking")).to eql(generated_uninstall_cmdlet)
+ expect(provider.build_powershell_package_command("Uninstall-Package xNetworking")).to eql(generated_uninstall_cmdlet)
end
it "build install commands correctly when a version is passed" do
- expect(provider.build_powershell_command("Uninstall-Package xNetworking", "1.0.0.0")).to eql(generated_uninstall_cmdlet_with_version)
+ expect(provider.build_powershell_package_command("Uninstall-Package xNetworking", "1.0.0.0")).to eql(generated_uninstall_cmdlet_with_version)
end
end
context "when source is set" do
it "build get commands correctly" do
new_resource.source("MyGallery")
- expect(provider.build_powershell_command("Get-Package xNetworking")).to eql(generated_get_cmdlet)
+ expect(provider.build_powershell_package_command("Get-Package xNetworking")).to eql(generated_get_cmdlet)
end
it "build get commands correctly when a version is passed" do
new_resource.source("MyGallery")
- expect(provider.build_powershell_command("Get-Package xNetworking", "1.0.0.0")).to eql(generated_get_cmdlet_with_version)
+ expect(provider.build_powershell_package_command("Get-Package xNetworking", "1.0.0.0")).to eql(generated_get_cmdlet_with_version)
end
it "builds find commands correctly" do
new_resource.source("MyGallery")
- expect(provider.build_powershell_command("Find-Package xNetworking")).to eql(generated_find_cmdlet_with_source)
+ expect(provider.build_powershell_package_command("Find-Package xNetworking")).to eql(generated_find_cmdlet_with_source)
end
it "builds find commands correctly when a version is passed" do
new_resource.source("MyGallery")
- expect(provider.build_powershell_command("Find-Package xNetworking", "1.0.0.0")).to eql(generated_find_cmdlet_with_source_and_version)
+ expect(provider.build_powershell_package_command("Find-Package xNetworking", "1.0.0.0")).to eql(generated_find_cmdlet_with_source_and_version)
end
it "build install commands correctly" do
new_resource.source("MyGallery")
- expect(provider.build_powershell_command("Install-Package xNetworking")).to eql(generated_install_cmdlet_with_source)
+ expect(provider.build_powershell_package_command("Install-Package xNetworking")).to eql(generated_install_cmdlet_with_source)
end
it "build install commands correctly when a version is passed" do
new_resource.source("MyGallery")
- expect(provider.build_powershell_command("Install-Package xNetworking", "1.0.0.0")).to eql(generated_install_cmdlet_with_source_and_version)
+ expect(provider.build_powershell_package_command("Install-Package xNetworking", "1.0.0.0")).to eql(generated_install_cmdlet_with_source_and_version)
end
it "build install commands correctly" do
new_resource.source("MyGallery")
- expect(provider.build_powershell_command("Uninstall-Package xNetworking")).to eql(generated_uninstall_cmdlet)
+ expect(provider.build_powershell_package_command("Uninstall-Package xNetworking")).to eql(generated_uninstall_cmdlet)
end
it "build install commands correctly when a version is passed" do
new_resource.source("MyGallery")
- expect(provider.build_powershell_command("Uninstall-Package xNetworking", "1.0.0.0")).to eql(generated_uninstall_cmdlet_with_version)
+ expect(provider.build_powershell_package_command("Uninstall-Package xNetworking", "1.0.0.0")).to eql(generated_uninstall_cmdlet_with_version)
end
end
end
diff --git a/spec/unit/provider/package/zypper_spec.rb b/spec/unit/provider/package/zypper_spec.rb
index 3f172dc370..819278a795 100644
--- a/spec/unit/provider/package/zypper_spec.rb
+++ b/spec/unit/provider/package/zypper_spec.rb
@@ -267,6 +267,40 @@ describe Chef::Provider::Package::Zypper do
end
end
+ describe "action_lock" do
+ it "should lock if the package is not already locked" do
+ prov = provider
+ allow(prov).to receive(:shell_out_compact_timeout!).with(
+ "zypper", "--non-interactive", "info", new_resource.package_name
+ ).and_return(status)
+ allow(prov).to receive(:shell_out_compact_timeout!).with(
+ "zypper", "locks"
+ ).and_return(instance_double(
+ Mixlib::ShellOut, stdout: "1 | somethingelse | package | (any)"
+ ))
+ expect(prov).to receive(:lock_package).with(["cups"], [nil])
+
+ prov.load_current_resource
+ prov.action_lock
+ end
+
+ it "should not lock if the package is already locked" do
+ prov = provider
+ allow(prov).to receive(:shell_out_compact_timeout!).with(
+ "zypper", "--non-interactive", "info", new_resource.package_name
+ ).and_return(status)
+ allow(prov).to receive(:shell_out_compact_timeout!).with(
+ "zypper", "locks"
+ ).and_return(instance_double(
+ Mixlib::ShellOut, stdout: "1 | cups | package | (any)"
+ ))
+ expect(prov).to_not receive(:lock_package)
+
+ prov.load_current_resource
+ prov.action_lock
+ end
+ end
+
describe "lock_package" do
it "should run zypper addlock with the package name" do
shell_out_expectation!(
@@ -290,6 +324,39 @@ describe Chef::Provider::Package::Zypper do
end
end
+ describe "action_unlock" do
+ it "should unlock if the package is not already unlocked" do
+ prov = provider
+ allow(prov).to receive(:shell_out_compact_timeout!).with(
+ "zypper", "--non-interactive", "info", new_resource.package_name
+ ).and_return(status)
+ allow(prov).to receive(:shell_out_compact_timeout!).with(
+ "zypper", "locks"
+ ).and_return(instance_double(
+ Mixlib::ShellOut, stdout: "1 | cups | package | (any)"
+ ))
+ expect(prov).to receive(:unlock_package).with(["cups"], [nil])
+
+ prov.load_current_resource
+ provider.action_unlock
+ end
+ it "should not unlock if the package is already unlocked" do
+ prov = provider
+ allow(prov).to receive(:shell_out_compact_timeout!).with(
+ "zypper", "--non-interactive", "info", new_resource.package_name
+ ).and_return(status)
+ allow(prov).to receive(:shell_out_compact_timeout!).with(
+ "zypper", "locks"
+ ).and_return(instance_double(
+ Mixlib::ShellOut, stdout: "1 | somethingelse | package | (any)"
+ ))
+ expect(prov).to_not receive(:unlock_package)
+
+ prov.load_current_resource
+ provider.action_unlock
+ end
+ end
+
describe "unlock_package" do
it "should run zypper removelock with the package name" do
shell_out_expectation!(
diff --git a/spec/unit/provider/powershell_script_spec.rb b/spec/unit/provider/powershell_script_spec.rb
index d7a1620530..f4663861c6 100644
--- a/spec/unit/provider/powershell_script_spec.rb
+++ b/spec/unit/provider/powershell_script_spec.rb
@@ -84,7 +84,7 @@ describe Chef::Provider::PowershellScript, "action_run" do
provider_flags.find do |value|
execution_policy_index += 1
- execution_policy_specified = value.casecmp("-ExecutionPolicy".downcase).zero?
+ execution_policy_specified = value.casecmp("-ExecutionPolicy".downcase) == 0
end
execution_policy = execution_policy_specified ? provider_flags[execution_policy_index] : nil
diff --git a/spec/unit/provider/service/debian_service_spec.rb b/spec/unit/provider/service/debian_service_spec.rb
index d944192755..25e7c9acc2 100644
--- a/spec/unit/provider/service/debian_service_spec.rb
+++ b/spec/unit/provider/service/debian_service_spec.rb
@@ -32,6 +32,17 @@ describe Chef::Provider::Service::Debian do
@provider.current_resource = @current_resource
@pid, @stdin, @stdout, @stderr = nil, nil, nil, nil
+ allow(File).to receive(:exist?).with("/etc/init.d/chef").and_return true
+ end
+
+ let(:init_lines) do
+ [
+ "### BEGIN INIT INFO",
+ "# Required-Start: hostname $local_fs",
+ "# Default-Start: 2 3 4 5",
+ "# Default-Stop: 0 1 6",
+ "### END INIT INFO",
+ ]
end
describe "load_current_resource" do
@@ -47,22 +58,14 @@ describe Chef::Provider::Service::Debian do
context "when update-rc.d shows init linked to rc*.d/" do
before do
allow(@provider).to receive(:assert_update_rcd_available)
+ allow(File).to receive(:readlines).with("/etc/init.d/chef").and_return(init_lines)
- result = <<-UPDATE_RC_D_SUCCESS
- Removing any system startup links for /etc/init.d/chef ...
- /etc/rc0.d/K20chef
- /etc/rc1.d/K20chef
- /etc/rc2.d/S20chef
- /etc/rc3.d/S20chef
- /etc/rc4.d/S20chef
- /etc/rc5.d/S20chef
- /etc/rc6.d/K20chef
- UPDATE_RC_D_SUCCESS
-
- @stdout = result
- @stderr = ""
- @status = double("Status", :exitstatus => 0, :stdout => @stdout, :stderr => @stderr)
- allow(@provider).to receive(:shell_out!).and_return(@status)
+ [0, 1, 6].each do |stop|
+ allow(Dir).to receive(:glob).with("/etc/rc#{stop}.d/[SK][0-9][0-9]chef").and_return(["/etc/rc#{stop}.d/K20chef"])
+ end
+ [2, 3, 4, 5].each do |start|
+ allow(Dir).to receive(:glob).with("/etc/rc#{start}.d/[SK][0-9][0-9]chef").and_return(["/etc/rc#{start}.d/S20chef"])
+ end
end
it "says the service is enabled" do
@@ -74,14 +77,34 @@ describe Chef::Provider::Service::Debian do
expect(@provider.load_current_resource).to equal(@current_resource)
expect(@current_resource.enabled).to be_truthy
end
+
+ it "stores the start/stop priorities of the service" do
+ @provider.load_current_resource
+ expect(@provider.current_resource.priority).to eq(
+ {
+ "2" => [:start, "20"],
+ "3" => [:start, "20"],
+ "4" => [:start, "20"],
+ "5" => [:start, "20"],
+ "0" => [:stop, "20"],
+ "1" => [:stop, "20"],
+ "6" => [:stop, "20"]
+ })
+ end
end
context "when update-rc.d shows init isn't linked to rc*.d/" do
before do
allow(@provider).to receive(:assert_update_rcd_available)
- @stdout = " Removing any system startup links for /etc/init.d/chef ..."
- @status = double("Status", :exitstatus => 0, :stdout => @stdout, stderr: "")
- allow(@provider).to receive(:shell_out!).and_return(@status)
+
+ allow(File).to receive(:readlines).with("/etc/init.d/chef").and_return(init_lines)
+
+ [0, 1, 6].each do |stop|
+ allow(Dir).to receive(:glob).with("/etc/rc#{stop}.d/[SK][0-9][0-9]chef").and_return([])
+ end
+ [2, 3, 4, 5].each do |start|
+ allow(Dir).to receive(:glob).with("/etc/rc#{start}.d/[SK][0-9][0-9]chef").and_return([])
+ end
end
it "says the service is disabled" do
@@ -95,149 +118,6 @@ describe Chef::Provider::Service::Debian do
end
end
- context "when update-rc.d fails" do
- before do
- @status = double("Status", exitstatus: -1, stdout: "", stderr: "")
- allow(@provider).to receive(:shell_out!).and_return(@status)
- end
-
- it "raises an error" do
- @provider.load_current_resource
- @provider.define_resource_requirements
- expect do
- @provider.process_resource_requirements
- end.to raise_error(Chef::Exceptions::Service)
- end
- end
-
- { "Debian/Lenny and older" => {
- "linked" => {
- "stdout" => <<-STDOUT,
- Removing any system startup links for /etc/init.d/chef ...
- /etc/rc0.d/K20chef
- /etc/rc1.d/K20chef
- /etc/rc2.d/S20chef
- /etc/rc3.d/S20chef
- /etc/rc4.d/S20chef
- /etc/rc5.d/S20chef
- /etc/rc6.d/K20chef
- STDOUT
- "stderr" => "",
- "priorities" => {
- "0" => [:stop, "20"],
- "1" => [:stop, "20"],
- "2" => [:start, "20"],
- "3" => [:start, "20"],
- "4" => [:start, "20"],
- "5" => [:start, "20"],
- "6" => [:stop, "20"],
- },
- },
- "not linked" => {
- "stdout" => " Removing any system startup links for /etc/init.d/chef ...",
- "stderr" => "",
- },
- },
- "Debian/Squeeze and earlier" => {
- "linked" => {
- "stdout" => "update-rc.d: using dependency based boot sequencing",
- "stderr" => <<-STDERR,
-insserv: remove service /etc/init.d/../rc0.d/K20chef-client
- insserv: remove service /etc/init.d/../rc1.d/K20chef-client
- insserv: remove service /etc/init.d/../rc2.d/S20chef-client
- insserv: remove service /etc/init.d/../rc3.d/S20chef-client
- insserv: remove service /etc/init.d/../rc4.d/S20chef-client
- insserv: remove service /etc/init.d/../rc5.d/S20chef-client
- insserv: remove service /etc/init.d/../rc6.d/K20chef-client
- insserv: dryrun, not creating .depend.boot, .depend.start, and .depend.stop
- STDERR
- "priorities" => {
- "0" => [:stop, "20"],
- "1" => [:stop, "20"],
- "2" => [:start, "20"],
- "3" => [:start, "20"],
- "4" => [:start, "20"],
- "5" => [:start, "20"],
- "6" => [:stop, "20"],
- },
- },
- "not linked" => {
- "stdout" => "update-rc.d: using dependency based boot sequencing",
- "stderr" => "",
- },
- },
- "Debian/Wheezy and earlier, a service only starting at run level S" => {
- "linked" => {
- "stdout" => "",
- "stderr" => <<-STDERR,
-insserv: remove service /etc/init.d/../rc0.d/K06rpcbind
-insserv: remove service /etc/init.d/../rc1.d/K06rpcbind
-insserv: remove service /etc/init.d/../rc6.d/K06rpcbind
-insserv: remove service /etc/init.d/../rcS.d/S13rpcbind
-insserv: dryrun, not creating .depend.boot, .depend.start, and .depend.stop
- STDERR
- "priorities" => {
- "0" => [:stop, "06"],
- "1" => [:stop, "06"],
- "6" => [:stop, "06"],
- "S" => [:start, "13"],
- },
- },
- "not linked" => {
- "stdout" => "",
- "stderr" => "insserv: dryrun, not creating .depend.boot, .depend.start, and .depend.stop",
- },
- },
- }.each do |model, expected_results|
- context "on #{model}" do
- context "when update-rc.d shows init linked to rc*.d/" do
- before do
- allow(@provider).to receive(:assert_update_rcd_available)
-
- @stdout = expected_results["linked"]["stdout"]
- @stderr = expected_results["linked"]["stderr"]
- @status = double("Status", exitstatus: 0, stdout: @stdout, stderr: @stderr)
- allow(@provider).to receive(:shell_out!).and_return(@status)
- end
-
- it "says the service is enabled" do
- expect(@provider.service_currently_enabled?(@provider.get_priority)).to be_truthy
- end
-
- it "stores the 'enabled' state" do
- allow(Chef::Resource::Service).to receive(:new).and_return(@current_resource)
- expect(@provider.load_current_resource).to equal(@current_resource)
- expect(@current_resource.enabled).to be_truthy
- end
-
- it "stores the start/stop priorities of the service" do
- @provider.load_current_resource
- expect(@provider.current_resource.priority).to eq(expected_results["linked"]["priorities"])
- end
- end
-
- context "when update-rc.d shows init isn't linked to rc*.d/" do
- before do
- allow(@provider).to receive(:assert_update_rcd_available)
- @stdout = expected_results["not linked"]["stdout"]
- @stderr = expected_results["not linked"]["stderr"]
- @status = double("Status", exitstatus: 0, stdout: @stdout, stderr: @stderr)
- allow(@provider).to receive(:shell_out!).and_return(@status)
- end
-
- it "says the service is disabled" do
- expect(@provider.service_currently_enabled?(@provider.get_priority)).to be_falsey
- end
-
- it "stores the 'disabled' state" do
- allow(Chef::Resource::Service).to receive(:new).and_return(@current_resource)
- expect(@provider.load_current_resource).to equal(@current_resource)
- expect(@current_resource.enabled).to be_falsey
- end
- end
- end
- end
-
end
describe "action_enable" do
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/provider/windows_task_spec.rb b/spec/unit/provider/windows_task_spec.rb
index a71ce92f56..66bd6854b6 100644
--- a/spec/unit/provider/windows_task_spec.rb
+++ b/spec/unit/provider/windows_task_spec.rb
@@ -18,8 +18,9 @@
require "spec_helper"
-describe Chef::Provider::WindowsTask do
+describe Chef::Provider::WindowsTask, :windows_only do
let(:new_resource) { Chef::Resource::WindowsTask.new("sample_task") }
+ let(:current_resource) { Chef::Resource::WindowsTask.new() }
let(:provider) do
node = Chef::Node.new
@@ -28,690 +29,401 @@ describe Chef::Provider::WindowsTask do
Chef::Provider::WindowsTask.new(new_resource, run_context)
end
- let(:task_hash) do
- {
- :"" => "",
- :Folder => "\\",
- :HostName => "NIMISHA-PC",
- :TaskName => "\\sample_task",
- :NextRunTime => "3/30/2017 2:42:00 PM",
- :Status => "Ready",
- :LogonMode => "Interactive/Background",
- :LastRunTime => "3/30/2017 2:27:00 PM",
- :LastResult => "1",
- :Author => "Administrator",
- :TaskToRun => "chef-client -L C:\\tmp\\",
- :StartIn => "N/A",
- :Comment => "N/A",
- :ScheduledTaskState => "Enabled",
- :IdleTime => "Disabled",
- :PowerManagement => "Stop On Battery Mode, No Start On Batteries",
- :RunAsUser => "SYSTEM",
- :DeleteTaskIfNotRescheduled => "Enabled",
- :StopTaskIfRunsXHoursandXMins => "72:00:00",
- :Schedule => "Scheduling data is not available in this format.",
- :ScheduleType => "One Time Only, Minute",
- :StartTime => "1:12:00 PM",
- :StartDate => "3/30/2017",
- :EndDate => "N/A",
- :Days => "N/A",
- :Months => "N/A",
- :"Repeat:Every" => "0 Hour(s), 15 Minute(s)",
- :"Repeat:Until:Time" => "None",
- :"Repeat:Until:Duration" => "Disabled",
- :"Repeat:StopIfStillRunning" => "Disabled",
- :run_level => "HighestAvailable",
- :repetition_interval => "PT15M",
- :execution_time_limit => "PT72H",
- }
- end
-
- let(:task_xml) do
- "<?xml version=\"1.0\" encoding=\"UTF-16\"?>\r\r\n<Task version=\"1.2\" xmlns=\"http://schemas.microsoft.com/windows/2004/02/mit/task\">\r\r\n <RegistrationInfo>\r\r\n <Date>2017-03-31T15:34:44</Date>\r\r\n <Author>Administrator</Author>\r\r\n </RegistrationInfo>\r\r\n<Triggers>\r\r\n <TimeTrigger>\r\r\n <Repetition>\r\r\n <Interval>PT15M</Interval>\r\r\n <StopAtDurationEnd>false</StopAtDurationEnd>\r\r\n </Repetition>\r\r\n <StartBoundary>2017-03-31T15:34:00</StartBoundary>\r\r\n <Enabled>true</Enabled>\r\r\n </TimeTrigger>\r\r\n </Triggers>\r\r\n <Principals>\r\r\n <Principal id=\"Author\">\r\r\n <RunLevel>HighestAvailable</RunLevel>\r\r\n <UserId>S-1-5-18</UserId>\r\r\n </Principal>\r\r\n </Principals>\r\r\n <Settings>\r\r\n <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>\r\r\n <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>\r\r\n <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>\r\r\n <AllowHardTerminate>true</AllowHardTerminate>\r\r\n <StartWhenAvailable>false</StartWhenAvailable>\r\r\n <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>\r\r\n <IdleSettings>\r\r\n <Duration>PT10M</Duration>\r\r\n<WaitTimeout>PT1H</WaitTimeout>\r\r\n <StopOnIdleEnd>true</StopOnIdleEnd>\r\r\n <RestartOnIdle>false</RestartOnIdle>\r\r\n </IdleSettings>\r\r\n <AllowStartOnDemand>true</AllowStartOnDemand>\r\r\n <Enabled>true</Enabled>\r\r\n <Hidden>false</Hidden>\r\r\n<RunOnlyIfIdle>false</RunOnlyIfIdle>\r\r\n <WakeToRun>false</WakeToRun>\r\r\n <ExecutionTimeLimit>PT72H</ExecutionTimeLimit>\r\r\n<Priority>7</Priority>\r\r\n </Settings>\r\r\n <Actions Context=\"Author\">\r\r\n <Exec>\r\r\n <Command>chef-client</Command>\r\r\n </Exec>\r\r\n </Actions>\r\r\n</Task>"
- end
-
describe "#load_current_resource" do
it "returns a current_resource" do
- allow(provider).to receive(:load_task_hash)
expect(provider.load_current_resource).to be_kind_of(Chef::Resource::WindowsTask)
end
+ end
- context "if the given task name already exists" do
- before do
- allow(provider).to receive(:load_task_hash).and_return({ :TaskName => "\\sample_task" })
- end
+ describe "#set_command_and_arguments" do
+ it "sets the command arguments if command has arguments passed in it" do
+ new_resource.command = "chef-client -W"
+ provider.send(:set_command_and_arguments)
+ expect(new_resource.command).to eq("chef-client")
+ expect(new_resource.command_arguments).to eq("-W")
+ end
+ end
- it "calls set_current_resource" do
- expect(provider).to receive(:set_current_resource)
- provider.load_current_resource
- end
+ describe "#set_start_day_and_time" do
+ it "sets the curret date and time start_day and start_time if nothing is provided by user" do
+ new_resource.start_day = nil
+ new_resource.start_time = nil
+ provider.send(:set_start_day_and_time)
+ expect(new_resource.start_day).not_to be_nil
+ expect(new_resource.start_time).not_to be_nil
end
- it "sets the attributes of current_resource" do
- allow(provider).to receive(:load_task_hash).and_return(task_hash)
- current_resource = provider.load_current_resource
- expect(current_resource.exists).to be(true)
- expect(current_resource.command).to eq("chef-client -L C:\\tmp\\")
- expect(current_resource.user).to eq("SYSTEM")
- expect(current_resource.run_level).to eq(:highest)
- expect(current_resource.frequency).to eq(:minute)
- expect(current_resource.frequency_modifier).to eq(15)
- expect(current_resource.execution_time_limit).to eq("PT72H")
- expect(current_resource.enabled).to be(true)
+ it "does not set start_day and start_time if given by user" do
+ new_resource.start_day = "12/02/2017"
+ new_resource.start_time = "17:30"
+ provider.send(:set_start_day_and_time)
+ expect(new_resource.start_day).to eq("12/02/2017")
+ expect(new_resource.start_time).to eq("17:30")
end
end
- describe "#action_create" do
- it "doesn't create the same task if it's already existing" do
- allow(provider).to receive(:load_task_hash).and_return(task_hash)
- provider.load_current_resource
- allow(provider).to receive(:task_need_update?).and_return(false)
- provider.run_action(:create)
- expect(new_resource).not_to be_updated_by_last_action
- end
-
- it "sets the start_time in 24hr format while updating an existing task" do
- # task_hash has start_time = "1:12:00 PM"
- allow(provider).to receive(:load_task_hash).and_return(task_hash)
- provider.load_current_resource
- allow(provider).to receive(:task_need_update?).and_return(true)
- allow(provider).to receive(:convert_system_date_to_mm_dd_yyyy).and_return("03/30/2017")
- allow(provider).to receive(:run_schtasks)
- provider.run_action(:create)
- # start_time gets set in 24hr format for new_resource
- expect(new_resource.start_time).to eq("13:12")
- expect(new_resource).to be_updated_by_last_action
- end
-
- it "sets the start_day in mm/dd/yyyy format while updating an existing task" do
- # start_day in yyyy-MM-dd format
- task_hash[:StartDate] = "2017-03-30"
- allow(provider).to receive(:load_task_hash).and_return(task_hash)
- current_resource = provider.load_current_resource
- allow(provider).to receive(:task_need_update?).and_return(true)
- allow(provider).to receive(:convert_system_date_format_to_ruby_date_format).and_return("%Y-%m-%d")
- allow(provider).to receive(:run_schtasks)
- provider.run_action(:create)
- # start_day gets set in mm/dd/yyyy format for new_resource
- expect(new_resource.start_day).to eq("03/30/2017")
- expect(new_resource).to be_updated_by_last_action
- end
-
- context "when start_day and start_time are N/A for frequency :on_logon" do
- it "doesn't update the start_day and start_time of new_resource" do
- task_hash[:on_logon] = true
- task_hash[:StartDate] = "N/A"
- task_hash[:StartTime] = "N/A"
- allow(provider).to receive(:load_task_hash).and_return(task_hash)
- current_resource = provider.load_current_resource
- allow(provider).to receive(:task_need_update?).and_return(true)
- allow(provider).to receive(:run_schtasks)
- expect(provider).not_to receive(:convert_system_date_to_mm_dd_yyyy)
- expect(DateTime).not_to receive(:parse)
- expect(new_resource.start_day).to eq(nil)
- expect(new_resource.start_time).to eq(nil)
- end
- end
-
- context "when task is not existing" do
- before do
- allow(provider).to receive(:load_task_hash)
- provider.load_current_resource
- end
-
- it "creates the task if it's not already existing" do
- allow(provider).to receive(:task_need_update?).and_return(true)
- allow(provider).to receive(:basic_validation).and_return(true)
- expect(provider).to receive(:run_schtasks).with("CREATE", { "F" => "", "SC" => :hourly, "MO" => 1, "TR" => nil, "RU" => "SYSTEM" })
- provider.run_action(:create)
- expect(new_resource).to be_updated_by_last_action
- end
-
- it "updates the task XML if random_delay is provided" do
- new_resource.random_delay "20"
- allow(provider).to receive(:task_need_update?).and_return(true)
- allow(provider).to receive(:basic_validation).and_return(true)
- expect(provider).to receive(:run_schtasks).with("CREATE", { "F" => "", "SC" => :hourly, "MO" => 1, "TR" => nil, "RU" => "SYSTEM" })
- expect(provider).to receive(:update_task_xml)
- provider.run_action(:create)
- expect(new_resource).to be_updated_by_last_action
- end
-
- it "updates the task XML if execution_time_limit is provided" do
- new_resource.execution_time_limit "20"
- allow(provider).to receive(:task_need_update?).and_return(true)
- allow(provider).to receive(:basic_validation).and_return(true)
- expect(provider).to receive(:run_schtasks).with("CREATE", { "F" => "", "SC" => :hourly, "MO" => 1, "TR" => nil, "RU" => "SYSTEM" })
- expect(provider).to receive(:update_task_xml)
- provider.run_action(:create)
- expect(new_resource).to be_updated_by_last_action
- end
-
- it "updates the task XML if frequency is set as `:none`" do
- new_resource.frequency :none
- new_resource.random_delay ""
- allow(provider).to receive(:task_need_update?).and_return(true)
- allow(provider).to receive(:basic_validation).and_return(true)
- allow(provider).to receive(:run_schtasks).and_return("CREATE", { "F" => "", "SC" => :once, "ST" => "00:00", "SD" => "12/12/2012", "TR" => nil, "RU" => "SYSTEM" })
- expect(provider).to receive(:update_task_xml)
- provider.run_action(:create)
- expect(new_resource).to be_updated_by_last_action
- end
+ describe "#trigger" do
+ it "returns the trigger values in hash format" do
+ new_resource.start_day "12/02/2017"
+ new_resource.start_time "17:30"
+ new_resource.frequency :minute
+ new_resource.frequency_modifier 15
+ new_resource.random_delay 60
+ result = {
+ :start_year => 2017,
+ :start_month => 12,
+ :start_day => 2,
+ :start_hour => 17,
+ :start_minute => 30,
+ :end_month => 0,
+ :end_day => 0,
+ :end_year => 0,
+ :trigger_type => 1,
+ :type => { :once => nil },
+ :random_minutes_interval => 60,
+ :minutes_interval => 15,
+ :run_on_last_day_of_month => false,
+ :run_on_last_week_of_month => false
+
+ }
+ expect(provider.send(:trigger)).to eq(result)
end
end
- describe "#action_run" do
- it "does nothing if the task doesn't exist" do
- allow(provider).to receive(:load_task_hash)
- provider.load_current_resource
- provider.run_action(:run)
- expect(new_resource).not_to be_updated_by_last_action
- end
-
- context "when the task exists" do
- it "does nothing if the task is already running" do
- task_hash[:Status] = "Running"
- allow(provider).to receive(:load_task_hash).and_return(task_hash)
- provider.load_current_resource
- provider.run_action(:run)
- expect(new_resource).not_to be_updated_by_last_action
- end
-
- it "runs the task" do
- allow(provider).to receive(:load_task_hash).and_return(task_hash)
- provider.load_current_resource
- expect(provider).to receive(:run_schtasks).with("RUN")
- provider.run_action(:run)
- expect(new_resource).to be_updated_by_last_action
- end
+ describe "#convert_hours_in_minutes" do
+ it "converts given hours in minutes" do
+ expect(provider.send(:convert_hours_in_minutes, 5)).to eq(300)
end
end
- describe "#action_delete" do
- it "deletes the task if it exists" do
- allow(provider).to receive(:load_task_hash).and_return(task_hash)
- provider.load_current_resource
- expect(provider).to receive(:run_schtasks).with("DELETE", { "F" => "" })
- provider.run_action(:delete)
- expect(new_resource).to be_updated_by_last_action
+ describe "#trigger_type" do
+ it "returns 1 if frequency :once" do
+ new_resource.frequency :once
+ expect(provider.send(:trigger_type)).to eq(1)
end
- it "does nothing if the task doesn't exist" do
- allow(provider).to receive(:load_task_hash)
- provider.load_current_resource
- provider.run_action(:delete)
- expect(new_resource).not_to be_updated_by_last_action
+ it "returns 2 if frequency :daily" do
+ new_resource.frequency :daily
+ expect(provider.send(:trigger_type)).to eq(2)
end
- end
- describe "#action_end" do
- it "does nothing if the task doesn't exist" do
- allow(provider).to receive(:load_task_hash)
- provider.load_current_resource
- provider.run_action(:end)
- expect(new_resource).not_to be_updated_by_last_action
- end
-
- context "when the task exists" do
- it "does nothing if the task is not running" do
- allow(provider).to receive(:load_task_hash).and_return(task_hash)
- provider.load_current_resource
- provider.run_action(:end)
- expect(new_resource).not_to be_updated_by_last_action
- end
-
- it "ends the task if it's running" do
- task_hash[:Status] = "Running"
- allow(provider).to receive(:load_task_hash).and_return(task_hash)
- provider.load_current_resource
- expect(provider).to receive(:run_schtasks).with("END")
- provider.run_action(:end)
- expect(new_resource).to be_updated_by_last_action
- end
+ it "returns 3 if frequency :weekly" do
+ new_resource.frequency :weekly
+ expect(provider.send(:trigger_type)).to eq(3)
end
- end
- describe "#action_enable" do
- it "raises error if the task doesn't exist" do
- allow(provider).to receive(:load_task_hash)
- provider.load_current_resource
- expect { provider.run_action(:enable) }.to raise_error(Errno::ENOENT)
- end
-
- context "when the task exists" do
- it "does nothing if the task is already enabled" do
- allow(provider).to receive(:load_task_hash).and_return(task_hash)
- provider.load_current_resource
- provider.run_action(:enable)
- expect(new_resource).not_to be_updated_by_last_action
- end
-
- it "enables the task if it exists" do
- task_hash[:ScheduledTaskState] = "Disabled"
- allow(provider).to receive(:load_task_hash).and_return(task_hash)
- provider.load_current_resource
- expect(provider).to receive(:run_schtasks).with("CHANGE", { "ENABLE" => "" })
- provider.run_action(:enable)
- expect(new_resource).to be_updated_by_last_action
- end
+ it "returns 4 if frequency :monthly" do
+ new_resource.frequency :monthly
+ expect(provider.send(:trigger_type)).to eq(4)
end
- end
- describe "#action_disable" do
- it "does nothing if the task doesn't exist" do
- allow(provider).to receive(:load_task_hash)
- provider.load_current_resource
- provider.run_action(:disable)
- expect(new_resource).not_to be_updated_by_last_action
- end
-
- context "when the task exists" do
- it "disables the task if it's enabled" do
- allow(provider).to receive(:load_task_hash).and_return(task_hash)
- provider.load_current_resource
- expect(provider).to receive(:run_schtasks).with("CHANGE", { "DISABLE" => "" })
- provider.run_action(:disable)
- expect(new_resource).to be_updated_by_last_action
- end
-
- it "does nothing if the task is already disabled" do
- task_hash[:ScheduledTaskState] = "Disabled"
- allow(provider).to receive(:load_task_hash).and_return(task_hash)
- provider.load_current_resource
- provider.run_action(:disable)
- expect(new_resource).not_to be_updated_by_last_action
- end
+ it "returns 5 if frequency :monthly and frequency_modifier is 'first, second'" do
+ new_resource.frequency :monthly
+ new_resource.frequency_modifier "first, second"
+ expect(provider.send(:trigger_type)).to eq(5)
+ end
+
+ it "returns 6 if frequency :on_idle" do
+ new_resource.frequency :on_idle
+ expect(provider.send(:trigger_type)).to eq(6)
end
- end
- describe "#run_schtasks" do
- before do
- @task_action = "CREATE"
- @options = { "F" => "", "SC" => :minute, "MO" => 15, "TR" => "chef-client", "RU" => "SYSTEM", "RL" => "HIGHEST" }
- @cmd = "schtasks /CREATE /TN \"sample_task\" /F /SC \"minute\" /MO \"15\" /RU \"SYSTEM\" /RL \"HIGHEST\" /TR \"chef-client \" "
+ it "returns 8 if frequency :onstart" do
+ new_resource.frequency :onstart
+ expect(provider.send(:trigger_type)).to eq(8)
end
- it "forms the command properly from the given options" do
- expect(provider).to receive(:shell_out!).with(@cmd, { :returns => [0] })
- provider.send(:run_schtasks, @task_action, @options)
+ it "returns 9 if frequency :on_logon" do
+ new_resource.frequency :on_logon
+ expect(provider.send(:trigger_type)).to eq(9)
end
end
- describe "#basic_validation" do
- context "when command doesn't exist" do
- it "raise error" do
- new_resource.command ""
- expect { provider.send(:basic_validation) }.to raise_error(Chef::Exceptions::ValidationFailed)
- end
+ describe "#type" do
+ it "returns type hash when frequency :once" do
+ new_resource.frequency :once
+ new_resource.frequency_modifier 2
+ result = provider.send(:type)
+ expect(result).to include(:once)
+ expect(result).to eq({ :once => nil })
end
- context "when task_name doesn't exist" do
- let(:new_resource) { Chef::Resource::WindowsTask.new("") }
- it "raise error" do
- expect { provider.send(:basic_validation) }.to raise_error(Chef::Exceptions::ValidationFailed)
- end
+ it "returns type hash when frequency :daily" do
+ new_resource.frequency :daily
+ new_resource.frequency_modifier 2
+ result = provider.send(:type)
+ expect(result).to include(:days_interval)
+ expect(result).to eq({ days_interval: 2 })
end
- context "when task_name and command exists" do
- it "returns true" do
- new_resource.command "cd ~/"
- expect(provider.send(:basic_validation)).to be(true)
- end
+ it "returns type hash when frequency :weekly" do
+ new_resource.start_day "01/02/2018"
+ new_resource.frequency :weekly
+ new_resource.frequency_modifier 2
+ result = provider.send(:type)
+ expect(result).to include(:weeks_interval)
+ expect(result).to include(:days_of_week)
+ expect(result).to eq({ weeks_interval: 2, days_of_week: 4 })
end
- end
- describe "#task_need_update?" do
- context "when task doesn't exist" do
- before do
- allow(provider).to receive(:load_task_hash)
- provider.load_current_resource
- end
-
- it "returns true" do
- new_resource.command "chef-client"
- expect(provider.send(:task_need_update?)).to be(true)
- end
- end
-
- context "when the task exists" do
- before do
- allow(provider).to receive(:load_task_hash).and_return(task_hash)
- allow(provider).to receive(:get_system_short_date_format).and_return("MM/dd/yyyy")
- provider.load_current_resource
-
- new_resource.command "chef-client -L C:\\tmp\\"
- new_resource.run_level :highest
- new_resource.frequency :minute
- new_resource.frequency_modifier 15
- new_resource.user "SYSTEM"
- new_resource.execution_time_limit "PT72H"
- new_resource.start_day "03/30/2017"
- new_resource.start_time "13:12"
- end
-
- context "when no attributes are modified" do
- it "returns false" do
- expect(provider.send(:task_need_update?)).to be(false)
- end
- end
-
- context "when frequency_modifier is updated" do
- it "returns true" do
- new_resource.frequency_modifier 25
- expect(provider.send(:task_need_update?)).to be(true)
- end
- end
-
- context "when months are updated" do
- it "returns true" do
- new_resource.months "JAN"
- expect(provider.send(:task_need_update?)).to be(true)
- end
- end
-
- context "when start_day is updated" do
- it "returns true" do
- new_resource.start_day "01/01/2000"
- expect(provider.send(:task_need_update?)).to be(true)
- end
- end
-
- context "when start_time updated" do
- it "returns true" do
- new_resource.start_time "01:01"
- expect(provider.send(:task_need_update?)).to be(true)
- end
- end
-
- context "when command updated" do
- it "return true" do
- new_resource.command "chef-client"
- expect(provider.send(:task_need_update?)).to be(true)
- end
- end
+ it "returns type hash when frequency :monthly" do
+ new_resource.frequency :monthly
+ result = provider.send(:type)
+ expect(result).to include(:months)
+ expect(result).to include(:days)
+ expect(result).to eq({ months: 4095, days: 1 })
end
- end
- describe "#start_day_updated?" do
- before do
- allow(provider).to receive(:load_task_hash).and_return(task_hash)
- allow(provider).to receive(:get_system_short_date_format).and_return("MM/dd/yyyy")
- provider.load_current_resource
+ it "returns type hash when frequency :monthly with frequency_modifier 'first, second, third'" do
+ new_resource.start_day "01/02/2018"
+ new_resource.frequency :monthly
+ new_resource.frequency_modifier "First, Second, third"
+ result = provider.send(:type)
+ expect(result).to include(:months)
+ expect(result).to include(:days_of_week)
+ expect(result).to include(:weeks_of_month)
+ expect(result).to eq({ months: 4095, days_of_week: 4, weeks_of_month: 7 })
+ end
- new_resource.command "chef-client"
- new_resource.run_level :highest
- new_resource.frequency :minute
- new_resource.frequency_modifier 15
- new_resource.user "SYSTEM"
- new_resource.execution_time_limit "PT72H"
- new_resource.start_day "03/30/2017"
- new_resource.start_time "13:12"
+ it "returns type hash when frequency :on_idle" do
+ new_resource.frequency :on_idle
+ result = provider.send(:type)
+ expect(result).to eq(nil)
end
- context "when start_day not changed" do
- it "returns false" do
- expect(provider.send(:start_day_updated?)).to be(false)
- end
+
+ it "returns type hash when frequency :onstart" do
+ new_resource.frequency :onstart
+ result = provider.send(:type)
+ expect(result).to eq(nil)
end
- context "when start_day changed" do
- it "returns true" do
- new_resource.start_day "01/01/2000"
- expect(provider.send(:start_day_updated?)).to be(true)
- end
+ it "returns type hash when frequency :on_logon" do
+ new_resource.frequency :on_logon
+ result = provider.send(:type)
+ expect(result).to eq(nil)
end
end
- describe "#start_time_updated?" do
- before do
- allow(provider).to receive(:load_task_hash).and_return(task_hash)
- provider.load_current_resource
+ describe "#weeks_of_month" do
+ it "returns the binary value 1 if frequency_modifier is set as 'first'" do
+ new_resource.frequency_modifier "first"
+ expect(provider.send(:weeks_of_month)).to eq(1)
+ end
- new_resource.command "chef-client"
- new_resource.run_level :highest
- new_resource.frequency :minute
- new_resource.frequency_modifier 15
- new_resource.user "SYSTEM"
- new_resource.execution_time_limit "PT72H"
- new_resource.start_day "3/30/2017"
- new_resource.start_time "13:12"
+ it "returns the binary value 2 if frequency_modifier is set as 'second'" do
+ new_resource.frequency_modifier "second"
+ expect(provider.send(:weeks_of_month)).to eq(2)
end
- context "when start_time not changed" do
- it "returns false" do
- expect(provider.send(:start_time_updated?)).to be(false)
- end
+
+ it "returns the binary value 4 if frequency_modifier is set as 'third'" do
+ new_resource.frequency_modifier "third"
+ expect(provider.send(:weeks_of_month)).to eq(4)
end
- context "when start_time changed" do
- it "returns true" do
- new_resource.start_time "01:01"
- expect(provider.send(:start_time_updated?)).to be(true)
- end
+ it "returns the binary value 8 if frequency_modifier is set as 'fourth'" do
+ new_resource.frequency_modifier "fourth"
+ expect(provider.send(:weeks_of_month)).to eq(8)
end
- end
- describe "#convert_user_date_to_system_date" do
- it "when current resource start date is '05/30/2017' then returns '30/05/2017'" do
- allow(provider).to receive(:get_system_short_date_format).and_return("dd/MM/yyyy")
- expect(provider.send(:convert_user_date_to_system_date, "05/30/2017")).to eq("30/05/2017")
+ it "returns the binary value 16 if frequency_modifier is set as 'last'" do
+ new_resource.frequency_modifier "last"
+ expect(provider.send(:weeks_of_month)).to eq(nil)
end
end
- describe "#convert_system_date_format_to_ruby_date_format" do
- context "when system date format 'dd-MMM-yy'" do
- it "returns '%d-%b-%y'" do
- allow(provider).to receive(:get_system_short_date_format).and_return("dd-MMM-yy")
- expect(provider.send(:convert_system_date_format_to_ruby_date_format)).to eq("%d-%b-%y")
- end
+ describe "#weeks_of_month" do
+ it "returns the binary value 1 if frequency_modifier is set as 'first'" do
+ new_resource.frequency_modifier "first"
+ expect(provider.send(:weeks_of_month)).to eq(1)
end
- context "when system date format 'dd/MM/yyyy'" do
- it "returns '%d/%m/%Y'" do
- allow(provider).to receive(:get_system_short_date_format).and_return("dd/MM/yyyy")
- expect(provider.send(:convert_system_date_format_to_ruby_date_format)).to eq("%d/%m/%Y")
- end
+ it "returns the binary value 2 if frequency_modifier is set as 'second'" do
+ new_resource.frequency_modifier "second"
+ expect(provider.send(:weeks_of_month)).to eq(2)
end
- end
- describe "#convert_system_date_format_to_ruby_long_date" do
- context "when system date format 'dd-MMM-yy'" do
- it "returns '%d-%m-%Y'" do
- allow(provider).to receive(:get_system_short_date_format).and_return("dd-MMM-yy")
- expect(provider.send(:convert_system_date_format_to_ruby_long_date)).to eq("%d-%m-%Y")
- end
+ it "returns the binary value 4 if frequency_modifier is set as 'third'" do
+ new_resource.frequency_modifier "third"
+ expect(provider.send(:weeks_of_month)).to eq(4)
end
- context "when system date format 'dd/MM/yyyy'" do
- it "returns '%d/%m/%Y'" do
- allow(provider).to receive(:get_system_short_date_format).and_return("dd/MM/yyyy")
- expect(provider.send(:convert_system_date_format_to_ruby_long_date)).to eq("%d/%m/%Y")
- end
+ it "returns the binary value 8 if frequency_modifier is set as 'fourth'" do
+ new_resource.frequency_modifier "fourth"
+ expect(provider.send(:weeks_of_month)).to eq(8)
end
- end
- describe "#common_date_format_conversion" do
- context "when system date format 'dd-MM-yyyy'" do
- it "returns '%d-%m-%Y'" do
- expect(provider.send(:common_date_format_conversion, "dd-MM-yyyy")).to eq("%d-%m-%Y")
- end
+ it "returns the binary value 16 if frequency_modifier is set as 'last'" do
+ new_resource.frequency_modifier "last"
+ expect(provider.send(:weeks_of_month)).to eq(nil)
end
- context "when system date format 'd-M-yyyy'" do
- it "returns '%d-%m-%Y'" do
- expect(provider.send(:common_date_format_conversion, "dd-MM-yyyy")).to eq("%d-%m-%Y")
- end
+ it "returns the binary value 15 if frequency_modifier is set as 'first, second, third, fourth'" do
+ new_resource.frequency_modifier "first, second, third, fourth"
+ expect(provider.send(:weeks_of_month)).to eq(15)
end
end
- describe "#update_task_xml" do
- before do
- new_resource.command "chef-client"
- new_resource.run_level :highest
- new_resource.frequency :minute
- new_resource.frequency_modifier 15
- new_resource.user "SYSTEM"
- new_resource.random_delay "20"
- end
-
- it "does nothing if the task doesn't exist" do
- task_xml = double("xml", :exitstatus => 1)
- allow(provider).to receive(:powershell_out).and_return(task_xml)
- output = provider.send(:update_task_xml, ["random_delay"])
- expect(output).to be(nil)
- end
-
- it "updates the task XML if random_delay is passed" do
- shell_out_obj = double("xml", :exitstatus => 0, :stdout => task_xml)
- allow(provider).to receive(:powershell_out).and_return(shell_out_obj)
- expect(::File).to receive(:join)
- expect(::File).to receive(:open)
- expect(::File).to receive(:delete)
- expect(provider).to receive(:run_schtasks).twice
- output = provider.send(:update_task_xml, ["random_delay"])
- end
-
- it "updates the task XML if frequency is set as `:none`" do
- new_resource.frequency :none
- new_resource.random_delay ""
- shell_out_obj = double("xml", :exitstatus => 0, :stdout => task_xml)
- allow(provider).to receive(:powershell_out).and_return(shell_out_obj)
- expect(::File).to receive(:delete)
- expect(::File).to receive(:join)
- expect(::File).to receive(:open)
- expect(provider).to receive(:run_schtasks).twice
- output = provider.send(:update_task_xml, ["random_delay"])
+ # REF: https://msdn.microsoft.com/en-us/library/windows/desktop/aa382063(v=vs.85).aspx
+ describe "#days_of_month" do
+ it "returns the binary value 1 if day is set as 1" do
+ new_resource.day "1"
+ expect(provider.send(:days_of_month)).to eq(1)
end
- end
- describe "#load_task_hash" do
- it "returns false if the task doesn't exist" do
- allow(provider).to receive_message_chain(:powershell_out, :stdout, :force_encoding).and_return("")
- allow(provider).to receive(:load_task_xml)
- expect(provider.send(:load_task_hash, "chef-client")).to be(false)
+ it "returns the binary value 2 if day is set as 2" do
+ new_resource.day "2"
+ expect(provider.send(:days_of_month)).to eq(2)
end
- it "returns task hash if the task exists" do
- powershell_output = "\r\nFolder: \\\r\nHostName: NIMISHA-PC\r\nTaskName: \\chef-client\r\n"
- task_h = { :"" => "", :Folder => "\\", :HostName => "NIMISHA-PC", :TaskName => "\\chef-client" }
- allow(provider).to receive_message_chain(:powershell_out, :stdout, :force_encoding).and_return(powershell_output)
- allow(provider).to receive(:load_task_xml).with("chef-client")
- expect(provider.send(:load_task_hash, "chef-client")).to eq(task_h)
+ it "returns the binary value 1073741824 if day is set as 31" do
+ new_resource.day "31"
+ expect(provider.send(:days_of_month)).to eq(1073741824)
+ end
+
+ it "returns the binary value 131072 if day is set as 18" do
+ new_resource.day "18"
+ expect(provider.send(:days_of_month)).to eq(131072)
end
end
- describe "#frequency_modifier_allowed" do
- it "returns true for frequency :hourly" do
- new_resource.frequency :hourly
- expect(provider.send(:frequency_modifier_allowed)).to be(true)
+ #Ref : https://msdn.microsoft.com/en-us/library/windows/desktop/aa380729(v=vs.85).aspx
+ describe "#days_of_week" do
+ it "returns the binary value 2 if day is set as 'Mon'" do
+ new_resource.day "Mon"
+ expect(provider.send(:days_of_week)).to eq(2)
end
- it "returns true for frequency :monthly if frequency_modifier is THIRD" do
- new_resource.frequency :monthly
- new_resource.frequency_modifier "THIRD"
- expect(provider.send(:frequency_modifier_allowed)).to be(true)
+ it "returns the binary value 4 if day is set as 'Tue'" do
+ new_resource.day "Tue"
+ expect(provider.send(:days_of_week)).to eq(4)
end
- it "returns false for frequency :once" do
- new_resource.frequency :once
- expect(provider.send(:frequency_modifier_allowed)).to be(false)
+ it "returns the binary value 8 if day is set as 'Wed'" do
+ new_resource.day "Wed"
+ expect(provider.send(:days_of_week)).to eq(8)
+ end
+
+ it "returns the binary value 16 if day is set as 'Thu'" do
+ new_resource.day "Thu"
+ expect(provider.send(:days_of_week)).to eq(16)
end
- it "returns false for frequency :none" do
- new_resource.frequency :none
- expect(provider.send(:frequency_modifier_allowed)).to be(false)
+ it "returns the binary value 32 if day is set as 'Fri'" do
+ new_resource.day "Fri"
+ expect(provider.send(:days_of_week)).to eq(32)
+ end
+
+ it "returns the binary value 64 if day is set as 'Sat'" do
+ new_resource.day "Sat"
+ expect(provider.send(:days_of_week)).to eq(64)
+ end
+
+ it "returns the binary value 1 if day is set as 'Sun'" do
+ new_resource.day "Sun"
+ expect(provider.send(:days_of_week)).to eq(1)
+ end
+
+ it "returns the binary value 127 if day is set as 'Mon, tue, wed, thu, fri, sat, sun'" do
+ new_resource.day "Mon, tue, wed, thu, fri, sat, sun"
+ expect(provider.send(:days_of_week)).to eq(127)
end
end
- # In windows_task resource sec_to_dur method converts seconds to duration in format 60 == 'PT60S'
- # random_delay_updated? method use the value return by sec_to_dur as input for comparison for new_resource.random_delay mocking the same here
- describe "#random_delay_updated?" do
- before do
- new_resource.command "chef-client"
- new_resource.run_level :highest
- new_resource.frequency :minute
- new_resource.frequency_modifier 15
- new_resource.user "SYSTEM"
+ # REf: https://msdn.microsoft.com/en-us/library/windows/desktop/aa382064(v=vs.85).aspx
+ describe "#monts_of_year" do
+ it "returns the binary value 1 if day is set as 'Jan'" do
+ new_resource.months "Jan"
+ expect(provider.send(:months_of_year)).to eq(1)
end
- it "returns false if current_resource.random_delay = nil & random_delay is set to '0' seconds" do
- task_hash[:random_delay] = nil
- allow(provider).to receive(:load_task_hash).and_return(task_hash)
- provider.load_current_resource
- new_resource.random_delay = "PT0S"
- expect(provider.send(:random_delay_updated?)).to be(false)
+ it "returns the binary value 2 if day is set as 'Feb'" do
+ new_resource.months "Feb"
+ expect(provider.send(:months_of_year)).to eq(2)
end
- it "returns false if current_resource.random_delay = 'P7D' & random_delay is set to '604800' seconds " do
- task_hash[:random_delay] = "P7D"
- allow(provider).to receive(:load_task_hash).and_return(task_hash)
- provider.load_current_resource
- new_resource.random_delay = "PT604800S"
- expect(provider.send(:random_delay_updated?)).to be(false)
+ it "returns the binary value 4 if day is set as 'Mar'" do
+ new_resource.months "Mar"
+ expect(provider.send(:months_of_year)).to eq(4)
end
- it "returns false if current_resource.random_delay = 'P7DT1S' & random_delay is set to '604801' seconds" do
- task_hash[:random_delay] = "P7DT1S"
- allow(provider).to receive(:load_task_hash).and_return(task_hash)
- provider.load_current_resource
- new_resource.random_delay = "PT604801S"
- expect(provider.send(:random_delay_updated?)).to be(false)
+ it "returns the binary value 8 if day is set as 'Apr'" do
+ new_resource.months "Apr"
+ expect(provider.send(:months_of_year)).to eq(8)
end
- it "returns true if current_resource.random_delay = 'PT1S' & random_delay is set to '3600' seconds" do
- task_hash[:random_delay] = "PT1S"
- allow(provider).to receive(:load_task_hash).and_return(task_hash)
- provider.load_current_resource
- new_resource.random_delay = "PT3600S"
- expect(provider.send(:random_delay_updated?)).to be(true)
+ it "returns the binary value 16 if day is set as 'May'" do
+ new_resource.months "May"
+ expect(provider.send(:months_of_year)).to eq(16)
end
- it "returns false if current_resource.random_delay = 'P2Y1MT2H' & random_delay is set to '65707200' seconds" do
- task_hash[:random_delay] = "P2Y1MT2H"
- allow(provider).to receive(:load_task_hash).and_return(task_hash)
- provider.load_current_resource
- new_resource.random_delay = "PT65707200S"
- expect(provider.send(:random_delay_updated?)).to be(false)
+ it "returns the binary value 32 if day is set as 'Jun'" do
+ new_resource.months "Jun"
+ expect(provider.send(:months_of_year)).to eq(32)
+ end
+
+ it "returns the binary value 64 if day is set as 'Jul'" do
+ new_resource.months "Jul"
+ expect(provider.send(:months_of_year)).to eq(64)
+ end
+
+ it "returns the binary value 128 if day is set as 'Aug'" do
+ new_resource.months "Aug"
+ expect(provider.send(:months_of_year)).to eq(128)
+ end
+
+ it "returns the binary value 256 if day is set as 'Sep'" do
+ new_resource.months "Sep"
+ expect(provider.send(:months_of_year)).to eq(256)
+ end
+
+ it "returns the binary value 512 if day is set as 'Oct'" do
+ new_resource.months "Oct"
+ expect(provider.send(:months_of_year)).to eq(512)
+ end
+
+ it "returns the binary value 1024 if day is set as 'Nov'" do
+ new_resource.months "Nov"
+ expect(provider.send(:months_of_year)).to eq(1024)
+ end
+
+ it "returns the binary value 2048 if day is set as 'Dec'" do
+ new_resource.months "Dec"
+ expect(provider.send(:months_of_year)).to eq(2048)
+ end
+
+ it "returns the binary value 4095 if day is set as 'jan, Feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec'" do
+ new_resource.months "jan, Feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec"
+ expect(provider.send(:months_of_year)).to eq(4095)
end
end
- describe "#execution_time_limit_updated?" do
- before do
- new_resource.command "chef-client"
+ describe "#run_level" do
+ it "return binary value 1 for run_level highest" do
new_resource.run_level :highest
- new_resource.frequency :minute
- new_resource.frequency_modifier 15
- new_resource.user "SYSTEM"
+ expect(provider.send(:run_level)).to be(1)
end
- it "returns false if current_resource.execution_time_limit = 'P7D' & execution_time_limit is set to 604800 seconds " do
- task_hash[:execution_time_limit] = "P7D"
- allow(provider).to receive(:load_task_hash).and_return(task_hash)
- provider.load_current_resource
- new_resource.execution_time_limit = "PT604800S"
- expect(provider.send(:execution_time_limit_updated?)).to be(false)
+ it "return binary value 1 for run_level limited" do
+ new_resource.run_level :limited
+ expect(provider.send(:run_level)).to be(0)
end
+ end
- it "returns false if current_resource.execution_time_limit = 'P7DT1S' & execution_time_limit is set to 604801 seconds" do
- task_hash[:execution_time_limit] = "P7DT1S"
- allow(provider).to receive(:load_task_hash).and_return(task_hash)
- provider.load_current_resource
- new_resource.execution_time_limit = "PT604801S"
- expect(provider.send(:execution_time_limit_updated?)).to be(false)
+ describe "#logon_type" do
+ it "return logon_type bindary value as 5 as if password is nil" do
+ new_resource.password = nil
+ expect(provider.send(:logon_type)).to be(5)
end
- it "returns true if current_resource.execution_time_limit = 'PT1S' & execution_time_limit is set to '3600' seconds" do
- task_hash[:execution_time_limit] = "PT1S"
- allow(provider).to receive(:load_task_hash).and_return(task_hash)
- provider.load_current_resource
- new_resource.execution_time_limit = "PT3600S"
- expect(provider.send(:execution_time_limit_updated?)).to be(true)
+ it "return logon_type bindary value as 1 as if password is not nil" do
+ new_resource.password = "abc"
+ expect(provider.send(:logon_type)).to be(1)
end
+ end
- it "returns false if current_resource.execution_time_limit = 'P2Y1MT2H' & execution_time_limit is set to '65707200' seconds" do
- task_hash[:execution_time_limit] = "P2Y1MT2H"
- allow(provider).to receive(:load_task_hash).and_return(task_hash)
- provider.load_current_resource
- new_resource.execution_time_limit = "PT65707200S"
- expect(provider.send(:execution_time_limit_updated?)).to be(false)
+ describe "#get_day" do
+ it "return day if date is provided" do
+ expect(provider.send(:get_day, "01/02/2018")).to eq("TUE")
end
end
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 dff94e6bdc..0043b08a5c 100644
--- a/spec/unit/resource/build_essential_spec.rb
+++ b/spec/unit/resource/build_essential_spec.rb
@@ -25,7 +25,19 @@ 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) }
+
+ it "the name defaults to an empty string" do
+ expect(resource.name).to eql("")
+ end
+ end
end
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 a6a556c333..aba6ab1032 100644
--- a/spec/unit/resource/gem_package_spec.rb
+++ b/spec/unit/resource/gem_package_spec.rb
@@ -33,6 +33,20 @@ 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")
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 d8eea74ed4..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
@@ -195,6 +206,6 @@ describe Chef::Resource::RegistryKey, "state" do
it "returns scrubbed values" do
resource.values([ { :name => "poosh", :type => :binary, :data => 255.chr * 1 } ])
- expect(resource.state_for_resource_reporter).to eql( { :values => [{ :name => "poosh", :type => :binary, :data => "a8100ae6aa1940d0b663bb31cd466142ebbdbd5187131b92d93818987832eb89" }] } )
+ expect(resource.state_for_resource_reporter[:values]).to eql( [{ :name => "poosh", :type => :binary, :data => "a8100ae6aa1940d0b663bb31cd466142ebbdbd5187131b92d93818987832eb89" }] )
end
end
diff --git a/spec/unit/resource/remote_directory_spec.rb b/spec/unit/resource/remote_directory_spec.rb
index c016213c4a..f010ebdf96 100644
--- a/spec/unit/resource/remote_directory_spec.rb
+++ b/spec/unit/resource/remote_directory_spec.rb
@@ -22,17 +22,28 @@ describe Chef::Resource::RemoteDirectory do
let(:resource) { Chef::Resource::RemoteDirectory.new("/etc/dunk") }
- it "sets the path to the first argument to new" 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")
end
it "has the basename of the remote directory resource as the default source" do
- expect(resource.source).to eql("dunk")
+ resource.path "/foo/bar"
+ expect(resource.source).to eql("bar")
end
it "accepts a number for the remote files backup" do
@@ -45,7 +56,7 @@ describe Chef::Resource::RemoteDirectory do
expect(resource.files_backup).to eql(false)
end
- it "accepts 3 or 4 digets for the files_mode" do
+ it "accepts 3 or 4 digits for the files_mode" do
resource.files_mode 100
expect(resource.files_mode).to eql(100)
resource.files_mode 1000
@@ -66,6 +77,10 @@ describe Chef::Resource::RemoteDirectory do
expect(resource.files_owner).to eql(1000)
end
+ it "overwrites by default" do
+ expect(resource.overwrite).to be true
+ end
+
describe "when it has cookbook, files owner, files mode, and source" do
before do
resource.path("/var/path/")
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/windows_task_spec.rb b/spec/unit/resource/windows_task_spec.rb
index 4b74a4f78a..6dbda35274 100644
--- a/spec/unit/resource/windows_task_spec.rb
+++ b/spec/unit/resource/windows_task_spec.rb
@@ -18,7 +18,7 @@
require "spec_helper"
-describe Chef::Resource::WindowsTask do
+describe Chef::Resource::WindowsTask, :windows_only do
let(:resource) { Chef::Resource::WindowsTask.new("sample_task") }
it "sets resource name as :windows_task" do
@@ -53,11 +53,16 @@ describe Chef::Resource::WindowsTask do
expect(resource.frequency_modifier).to eql(1)
end
- it "sets the default frequency as :hourly" do
- expect(resource.frequency).to eql(:hourly)
+ context "when frequency is not provided" do
+ it "raises ArgumentError to provide frequency" do
+ expect { resource.after_created }.to raise_error(ArgumentError, "Frequency needs to be provided. Valid frequencies are :minute, :hourly, :daily, :weekly, :monthly, :once, :on_logon, :onstart, :on_idle, :none." )
+ end
end
context "when user is set but password is not" do
+ before do
+ resource.frequency :hourly
+ end
it "raises an error if the user is a non-system user" do
resource.user "bob"
expect { resource.after_created }.to raise_error(ArgumentError, %q{Cannot specify a user other than the system users without specifying a password!. Valid passwordless users: 'NT AUTHORITY\SYSTEM', 'SYSTEM', 'NT AUTHORITY\LOCALSERVICE', 'NT AUTHORITY\NETWORKSERVICE', 'BUILTIN\USERS', 'USERS'})
@@ -75,10 +80,12 @@ describe Chef::Resource::WindowsTask do
end
context "when random_delay is passed" do
- it "raises error if frequency is `:once`" do
+ # changed this sepc since random_delay property is valid with it frequency :once
+ it "not raises error if frequency is `:once`" do
resource.frequency :once
resource.random_delay "20"
- expect { resource.after_created }.to raise_error(ArgumentError, "`random_delay` property is supported only for frequency :minute, :hourly, :daily, :weekly and :monthly")
+ resource.start_time "15:00"
+ expect { resource.after_created }.to_not raise_error(ArgumentError, "`random_delay` property is supported only for frequency :once, :minute, :hourly, :daily, :weekly and :monthly")
end
it "raises error for invalid random_delay" do
@@ -93,29 +100,30 @@ describe Chef::Resource::WindowsTask do
expect { resource.after_created }.to raise_error(ArgumentError, "Invalid value passed for `random_delay`. Please pass seconds as an Integer (e.g. 60) or a String with numeric values only (e.g. '60').")
end
- it "converts seconds String into iso8601 duration format" do
+ it "converts '60' seconds into integer 1 minute format" do
resource.frequency :monthly
resource.random_delay "60"
resource.after_created
- expect(resource.random_delay).to eq("PT60S")
+ expect(resource.random_delay).to eq(1)
end
- it "converts seconds Integer into iso8601 duration format" do
+ it "converts 60 Integer into integer 1 minute format" do
resource.frequency :monthly
resource.random_delay 60
resource.after_created
- expect(resource.random_delay).to eq("PT60S")
+ expect(resource.random_delay).to eq(1)
end
it "raises error that random_delay is not supported" do
- expect { resource.send(:validate_random_delay, 60, :on_idle) }.to raise_error(ArgumentError, "`random_delay` property is supported only for frequency :minute, :hourly, :daily, :weekly and :monthly")
+ expect { resource.send(:validate_random_delay, 60, :on_idle) }.to raise_error(ArgumentError, "`random_delay` property is supported only for frequency :once, :minute, :hourly, :daily, :weekly and :monthly")
end
end
context "when execution_time_limit isn't specified" do
- it "sets the default value to PT72H" do
+ it "sets the default value to PT72H which get converted to minute as 4320" do
+ resource.frequency :hourly
resource.after_created
- expect(resource.execution_time_limit).to eq("PT72H")
+ expect(resource.execution_time_limit).to eq(4320)
end
end
@@ -130,16 +138,18 @@ describe Chef::Resource::WindowsTask do
expect { resource.after_created }.to raise_error(ArgumentError, "Invalid value passed for `execution_time_limit`. Please pass seconds as an Integer (e.g. 60) or a String with numeric values only (e.g. '60').")
end
- it "converts seconds Integer into iso8601 format" do
+ it "converts seconds Integer into integer minute format" do
+ resource.frequency :hourly
resource.execution_time_limit 60
resource.after_created
- expect(resource.execution_time_limit).to eq("PT60S")
+ expect(resource.execution_time_limit).to eq(1)
end
- it "converts seconds String into iso8601 format" do
+ it "converts seconds String into integer minute format" do
+ resource.frequency :hourly
resource.execution_time_limit "60"
resource.after_created
- expect(resource.execution_time_limit).to eq("PT60S")
+ expect(resource.execution_time_limit).to eq(1)
end
end
@@ -166,15 +176,23 @@ describe Chef::Resource::WindowsTask do
end
context "#validate_start_day" do
- it "raise error if start_day is passed with invalid frequency (:on_logon)" do
- expect { resource.send(:validate_start_day, "02/07/1984", :on_logon) }.to raise_error(ArgumentError, "`start_day` property is not supported with frequency: on_logon")
+ it "not to raise error if start_day is passed with invalid frequency (:onstart)" do
+ expect { resource.send(:validate_start_day, "02/07/1984", :onstart) }.not_to raise_error
+ end
+
+ it "not to raise error if start_day is passed with invalid frequency (:on_idle)" do
+ expect { resource.send(:validate_start_day, "02/07/1984", :on_idle) }.not_to raise_error
+ end
+
+ it "not to raise error if start_day is passed with invalid frequency (:on_logon)" do
+ expect { resource.send(:validate_start_day, "02/07/1984", :on_logon) }.not_to raise_error
end
- it "does not raise error if start_day is passed with valid frequency (:weekly)" do
+ it "not raise error if start_day is passed with valid frequency (:weekly)" do
expect { resource.send(:validate_start_day, "02/07/1984", :weekly) }.not_to raise_error
end
- it "raise error if start_day is passed with invalid date format (DD/MM/YYYY)" do
+ it "not to raise error if start_day is passed with invalid date format (DD/MM/YYYY)" do
expect { resource.send(:validate_start_day, "28/12/2009", :weekly) }.to raise_error(ArgumentError, "`start_day` property must be in the MM/DD/YYYY format.")
end
@@ -224,73 +242,73 @@ describe Chef::Resource::WindowsTask do
context "when frequency is :monthly" do
it "raises error if frequency_modifier > 12" do
- expect { resource.send(:validate_create_frequency_modifier, :monthly, 14) }.to raise_error("frequency_modifier value 14 is invalid. Valid values for :monthly frequency are 1 - 12, 'FIRST', 'SECOND', 'THIRD', 'FOURTH', 'LAST', 'LASTDAY'.")
+ expect { resource.send(:validate_create_frequency_modifier, :monthly, 14) }.to raise_error("frequency_modifier value 14 is invalid. Valid values for :monthly frequency are 1 - 12, 'FIRST', 'SECOND', 'THIRD', 'FOURTH', 'LAST'.")
end
it "raises error if frequency_modifier is invalid" do
- expect { resource.send(:validate_create_frequency_modifier, :monthly, "abc") }.to raise_error("frequency_modifier value abc is invalid. Valid values for :monthly frequency are 1 - 12, 'FIRST', 'SECOND', 'THIRD', 'FOURTH', 'LAST', 'LASTDAY'.")
+ expect { resource.send(:validate_create_frequency_modifier, :monthly, "abc") }.to raise_error("frequency_modifier value abc is invalid. Valid values for :monthly frequency are 1 - 12, 'FIRST', 'SECOND', 'THIRD', 'FOURTH', 'LAST'.")
end
end
end
context "#validate_create_day" do
it "raises error if frequency is not :weekly or :monthly" do
- expect { resource.send(:validate_create_day, "Mon", :once) }.to raise_error("day property is only valid for tasks that run monthly or weekly")
+ expect { resource.send(:validate_create_day, "Mon", :once, 1) }.to raise_error("day property is only valid for tasks that run monthly or weekly")
end
it "accepts a valid single day" do
- expect { resource.send(:validate_create_day, "Mon", :weekly) }.not_to raise_error
+ expect { resource.send(:validate_create_day, "Mon", :weekly, 1) }.not_to raise_error
end
it "accepts a comma separated list of valid days" do
- expect { resource.send(:validate_create_day, "Mon, tue, THU", :weekly) }.not_to raise_error
+ expect { resource.send(:validate_create_day, "Mon, tue, THU", :weekly, 1) }.not_to raise_error
end
it "raises error for invalid day value" do
- expect { resource.send(:validate_create_day, "xyz", :weekly) }.to raise_error(ArgumentError, "day property invalid. Only valid values are: MON, TUE, WED, THU, FRI, SAT, SUN and *. Multiple values must be separated by a comma.")
+ expect { resource.send(:validate_create_day, "xyz", :weekly, 1) }.to raise_error(ArgumentError, "day property invalid. Only valid values are: MON, TUE, WED, THU, FRI, SAT, SUN, *. Multiple values must be separated by a comma.")
end
end
context "#validate_create_months" do
it "raises error if frequency is not :monthly" do
- expect { resource.send(:validate_create_months, "Jan", :once) }.to raise_error(ArgumentError, "months property is only valid for tasks that run monthly")
+ expect { resource.send(:validate_create_months, "Jan", :once) }.to raise_error(ArgumentError, "months property is only valid for tasks that run monthly")
end
it "accepts a valid single month" do
- expect { resource.send(:validate_create_months, "Feb", :monthly) }.not_to raise_error
+ expect { resource.send(:validate_create_months, "Feb", :monthly) }.not_to raise_error
end
it "accepts a comma separated list of valid months" do
- expect { resource.send(:validate_create_months, "Jan, mar, AUG", :monthly) }.not_to raise_error
+ expect { resource.send(:validate_create_months, "Jan, mar, AUG", :monthly) }.not_to raise_error
end
it "raises error for invalid month value" do
- expect { resource.send(:validate_create_months, "xyz", :monthly) }.to raise_error(ArgumentError, "months property invalid. Only valid values are: JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC and *. Multiple values must be separated by a comma.")
+ expect { resource.send(:validate_create_months, "xyz", :monthly) }.to raise_error(ArgumentError, "months property invalid. Only valid values are: JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC, *. Multiple values must be separated by a comma.")
end
end
context "#validate_idle_time" do
it "raises error if frequency is not :on_idle" do
[:minute, :hourly, :daily, :weekly, :monthly, :once, :on_logon, :onstart, :none].each do |frequency|
- expect { resource.send(:validate_idle_time, 5, frequency) }.to raise_error(ArgumentError, "idle_time property is only valid for tasks that run on_idle")
+ expect { resource.send(:validate_idle_time, 5, frequency) }.to raise_error(ArgumentError, "idle_time property is only valid for tasks that run on_idle")
end
end
it "raises error if idle_time > 999" do
- expect { resource.send(:validate_idle_time, 1000, :on_idle) }.to raise_error(ArgumentError, "idle_time value 1000 is invalid. Valid values for :on_idle frequency are 1 - 999.")
+ expect { resource.send(:validate_idle_time, 1000, :on_idle) }.to raise_error(ArgumentError, "idle_time value 1000 is invalid. Valid values for :on_idle frequency are 1 - 999.")
end
it "raises error if idle_time < 0" do
- expect { resource.send(:validate_idle_time, -5, :on_idle) }.to raise_error(ArgumentError, "idle_time value -5 is invalid. Valid values for :on_idle frequency are 1 - 999.")
+ expect { resource.send(:validate_idle_time, -5, :on_idle) }.to raise_error(ArgumentError, "idle_time value -5 is invalid. Valid values for :on_idle frequency are 1 - 999.")
end
it "raises error if idle_time is not set" do
- expect { resource.send(:validate_idle_time, nil, :on_idle) }.to raise_error(ArgumentError, "idle_time value should be set for :on_idle frequency.")
+ expect { resource.send(:validate_idle_time, nil, :on_idle) }.to raise_error(ArgumentError, "idle_time value should be set for :on_idle frequency.")
end
it "does not raises error if idle_time is not set for other frequencies" do
[:minute, :hourly, :daily, :weekly, :monthly, :once, :on_logon, :onstart, :none].each do |frequency|
- expect { resource.send(:validate_idle_time, nil, frequency) }.not_to raise_error
+ expect { resource.send(:validate_idle_time, nil, frequency) }.not_to raise_error
end
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
diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb
index fe853922a1..523f9f7365 100644
--- a/spec/unit/resource_spec.rb
+++ b/spec/unit/resource_spec.rb
@@ -555,6 +555,16 @@ end
resource.ignore_failure(true)
expect(resource.ignore_failure).to eq(true)
end
+
+ it "should allow you to set quiet ignore_failure as a symbol" do
+ resource.ignore_failure(:quiet)
+ expect(resource.ignore_failure).to eq(:quiet)
+ end
+
+ it "should allow you to set quiet ignore_failure as a string" do
+ resource.ignore_failure("quiet")
+ expect(resource.ignore_failure).to eq("quiet")
+ end
end
describe "retries" do