chef 12.4.3-universal-mingw32 → 12.5.1-universal-mingw32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +21 -25
- data/Gemfile +46 -0
- data/README.md +4 -4
- data/Rakefile +4 -110
- data/bin/chef-service-manager +3 -1
- data/distro/common/html/knife_cookbook_site.html +18 -18
- data/distro/common/man/man1/knife-cookbook-site.1 +11 -11
- data/lib/chef.rb +1 -1
- data/lib/chef/application.rb +1 -1
- data/lib/chef/application/apply.rb +19 -1
- data/lib/chef/application/client.rb +11 -5
- data/lib/chef/application/knife.rb +2 -2
- data/lib/chef/application/solo.rb +1 -1
- data/lib/chef/application/windows_service_manager.rb +19 -12
- data/lib/chef/chef_class.rb +46 -0
- data/lib/chef/chef_fs/config.rb +22 -24
- data/lib/chef/chef_fs/data_handler/client_data_handler.rb +3 -1
- data/lib/chef/chef_fs/file_pattern.rb +4 -15
- data/lib/chef/chef_fs/file_system/acl_dir.rb +3 -4
- data/lib/chef/chef_fs/file_system/acls_dir.rb +5 -1
- data/lib/chef/chef_fs/file_system/base_fs_dir.rb +0 -5
- data/lib/chef/chef_fs/file_system/base_fs_object.rb +5 -2
- data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb +2 -9
- data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_entry.rb +2 -9
- data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbooks_dir.rb +10 -17
- data/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +1 -12
- data/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb +15 -11
- data/lib/chef/chef_fs/file_system/chef_server_root_dir.rb +8 -2
- data/lib/chef/chef_fs/file_system/cookbook_dir.rb +4 -4
- data/lib/chef/chef_fs/file_system/cookbooks_acl_dir.rb +1 -1
- data/lib/chef/chef_fs/file_system/cookbooks_dir.rb +3 -11
- data/lib/chef/chef_fs/file_system/data_bags_dir.rb +3 -5
- data/lib/chef/chef_fs/file_system/environments_dir.rb +1 -1
- data/lib/chef/chef_fs/file_system/file_system_entry.rb +7 -4
- data/lib/chef/chef_fs/file_system/memory_dir.rb +2 -3
- data/lib/chef/chef_fs/file_system/multiplexed_dir.rb +15 -0
- data/lib/chef/chef_fs/file_system/nodes_dir.rb +1 -1
- data/lib/chef/chef_fs/file_system/organization_members_entry.rb +2 -2
- data/lib/chef/chef_fs/file_system/rest_list_dir.rb +4 -9
- data/lib/chef/chef_fs/knife.rb +35 -7
- data/lib/chef/chef_fs/path_utils.rb +65 -34
- data/lib/chef/client.rb +2 -3
- data/lib/chef/config.rb +34 -2
- data/lib/chef/{mixin/wstring.rb → constants.rb} +9 -13
- data/lib/chef/cookbook/metadata.rb +25 -3
- data/lib/chef/cookbook/synchronizer.rb +1 -1
- data/lib/chef/cookbook_site_streaming_uploader.rb +1 -1
- data/lib/chef/cookbook_version.rb +3 -3
- data/lib/chef/delayed_evaluator.rb +21 -0
- data/lib/chef/deprecation/mixin/template.rb +1 -2
- data/lib/chef/deprecation/provider/cookbook_file.rb +1 -1
- data/lib/chef/deprecation/provider/file.rb +1 -1
- data/lib/chef/deprecation/provider/remote_directory.rb +52 -0
- data/lib/chef/deprecation/provider/remote_file.rb +1 -2
- data/lib/chef/deprecation/provider/template.rb +1 -1
- data/lib/chef/deprecation/warnings.rb +3 -4
- data/lib/chef/dsl/reboot_pending.rb +3 -2
- data/lib/chef/dsl/recipe.rb +26 -7
- data/lib/chef/dsl/resources.rb +2 -2
- data/lib/chef/event_dispatch/base.rb +51 -22
- data/lib/chef/event_dispatch/dispatcher.rb +21 -6
- data/lib/chef/event_dispatch/dsl.rb +64 -0
- data/lib/chef/exceptions.rb +28 -1
- data/lib/chef/file_content_management/tempfile.rb +1 -1
- data/lib/chef/formatters/base.rb +3 -0
- data/lib/chef/formatters/doc.rb +56 -6
- data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +36 -0
- data/lib/chef/formatters/minimal.rb +2 -2
- data/lib/chef/guard_interpreter/resource_guard_interpreter.rb +3 -1
- data/lib/chef/http/http_request.rb +1 -1
- data/lib/chef/knife.rb +35 -55
- data/lib/chef/knife/bootstrap.rb +41 -0
- data/lib/chef/knife/bootstrap/chef_vault_handler.rb +1 -0
- data/lib/chef/knife/bootstrap/client_builder.rb +16 -0
- data/lib/chef/knife/bootstrap/templates/README.md +3 -4
- data/lib/chef/knife/bootstrap/templates/chef-full.erb +1 -1
- data/lib/chef/knife/cookbook_create.rb +1 -1
- data/lib/chef/knife/cookbook_site_download.rb +1 -1
- data/lib/chef/knife/cookbook_site_install.rb +1 -1
- data/lib/chef/knife/cookbook_site_share.rb +6 -6
- data/lib/chef/knife/cookbook_site_unshare.rb +2 -2
- data/lib/chef/knife/core/bootstrap_context.rb +12 -4
- data/lib/chef/knife/core/custom_manifest_loader.rb +69 -0
- data/lib/chef/knife/core/gem_glob_loader.rb +138 -0
- data/lib/chef/knife/core/hashed_command_loader.rb +80 -0
- data/lib/chef/knife/core/node_presenter.rb +24 -1
- data/lib/chef/knife/core/object_loader.rb +1 -0
- data/lib/chef/knife/core/subcommand_loader.rb +131 -146
- data/lib/chef/knife/node_run_list_remove.rb +12 -1
- data/lib/chef/knife/null.rb +10 -0
- data/lib/chef/knife/rehash.rb +62 -0
- data/lib/chef/knife/search.rb +3 -3
- data/lib/chef/knife/ssh.rb +52 -30
- data/lib/chef/knife/ssl_check.rb +3 -2
- data/lib/chef/knife/user_edit.rb +1 -2
- data/lib/chef/local_mode.rb +5 -0
- data/lib/chef/log.rb +5 -1
- data/lib/chef/mixin/deprecation.rb +8 -8
- data/lib/chef/mixin/params_validate.rb +362 -135
- data/lib/chef/mixin/template.rb +48 -0
- data/lib/chef/mixin/which.rb +1 -1
- data/lib/chef/mixin/wide_string.rb +72 -0
- data/lib/chef/mixin/windows_architecture_helper.rb +15 -39
- data/lib/chef/mixin/windows_env_helper.rb +4 -1
- data/lib/chef/monkey_patches/webrick-utils.rb +51 -0
- data/lib/chef/monkey_patches/win32/registry.rb +72 -0
- data/lib/chef/node.rb +116 -3
- data/lib/chef/node_map.rb +2 -2
- data/lib/chef/platform/handler_map.rb +0 -5
- data/lib/chef/platform/provider_mapping.rb +5 -6
- data/lib/chef/platform/query_helpers.rb +46 -4
- data/lib/chef/platform/rebooter.rb +1 -1
- data/lib/chef/platform/service_helpers.rb +30 -32
- data/lib/chef/policy_builder.rb +1 -8
- data/lib/chef/policy_builder/dynamic.rb +186 -0
- data/lib/chef/policy_builder/expand_node_object.rb +30 -15
- data/lib/chef/policy_builder/policyfile.rb +155 -18
- data/lib/chef/property.rb +568 -0
- data/lib/chef/provider.rb +222 -13
- data/lib/chef/provider/batch.rb +8 -0
- data/lib/chef/provider/deploy.rb +5 -7
- data/lib/chef/provider/directory.rb +14 -2
- data/lib/chef/provider/dsc_resource.rb +5 -9
- data/lib/chef/provider/group/pw.rb +1 -1
- data/lib/chef/provider/ifconfig.rb +2 -2
- data/lib/chef/provider/lwrp_base.rb +1 -75
- data/lib/chef/provider/mount.rb +7 -3
- data/lib/chef/provider/package.rb +1 -1
- data/lib/chef/provider/package/dpkg.rb +5 -11
- data/lib/chef/provider/package/rpm.rb +2 -2
- data/lib/chef/provider/package/rubygems.rb +1 -1
- data/lib/chef/provider/package/windows/msi.rb +2 -2
- data/lib/chef/provider/package/yum.rb +17 -5
- data/lib/chef/provider/powershell_script.rb +59 -23
- data/lib/chef/provider/registry_key.rb +5 -5
- data/lib/chef/provider/remote_directory.rb +190 -102
- data/lib/chef/provider/service.rb +12 -2
- data/lib/chef/provider/service/aix.rb +1 -1
- data/lib/chef/provider/service/debian.rb +3 -5
- data/lib/chef/provider/service/freebsd.rb +1 -1
- data/lib/chef/provider/service/gentoo.rb +3 -3
- data/lib/chef/provider/service/init.rb +3 -3
- data/lib/chef/provider/service/insserv.rb +2 -4
- data/lib/chef/provider/service/invokercd.rb +2 -4
- data/lib/chef/provider/service/macosx.rb +5 -1
- data/lib/chef/provider/service/openbsd.rb +2 -1
- data/lib/chef/provider/service/redhat.rb +52 -16
- data/lib/chef/provider/service/simple.rb +2 -2
- data/lib/chef/provider/service/systemd.rb +3 -5
- data/lib/chef/provider/service/upstart.rb +4 -6
- data/lib/chef/provider/subversion.rb +13 -7
- data/lib/chef/provider/template/content.rb +16 -6
- data/lib/chef/provider/user/solaris.rb +32 -4
- data/lib/chef/provider/windows_script.rb +3 -5
- data/lib/chef/provider_resolver.rb +2 -2
- data/lib/chef/recipe.rb +1 -8
- data/lib/chef/resource.rb +563 -90
- data/lib/chef/resource/action_class.rb +83 -0
- data/lib/chef/resource/chef_gem.rb +3 -3
- data/lib/chef/resource/deploy.rb +8 -2
- data/lib/chef/resource/dsc_script.rb +2 -0
- data/lib/chef/resource/file/verification.rb +7 -1
- data/lib/chef/resource/lwrp_base.rb +1 -7
- data/lib/chef/resource/registry_key.rb +1 -1
- data/lib/chef/resource/service.rb +10 -2
- data/lib/chef/resource/subversion.rb +5 -0
- data/lib/chef/resource/windows_script.rb +6 -2
- data/lib/chef/resource/yum_package.rb +10 -1
- data/lib/chef/resource_resolver.rb +3 -3
- data/lib/chef/run_context.rb +402 -83
- data/lib/chef/run_list/versioned_recipe_list.rb +15 -0
- data/lib/chef/run_lock.rb +30 -21
- data/lib/chef/util/powershell/ps_credential.rb +4 -0
- data/lib/chef/util/windows.rb +0 -32
- data/lib/chef/util/windows/net_group.rb +85 -106
- data/lib/chef/util/windows/net_use.rb +35 -71
- data/lib/chef/util/windows/net_user.rb +0 -1
- data/lib/chef/util/windows/volume.rb +19 -19
- data/lib/chef/version.rb +3 -3
- data/lib/chef/win32/api.rb +1 -0
- data/lib/chef/win32/api/file.rb +20 -0
- data/lib/chef/win32/api/net.rb +163 -43
- data/lib/chef/win32/api/registry.rb +51 -0
- data/lib/chef/win32/api/system.rb +23 -0
- data/lib/chef/win32/api/unicode.rb +0 -43
- data/lib/chef/win32/crypto.rb +2 -1
- data/lib/chef/win32/file.rb +28 -3
- data/lib/chef/win32/mutex.rb +1 -2
- data/lib/chef/win32/net.rb +162 -8
- data/lib/chef/win32/process.rb +13 -0
- data/lib/chef/win32/registry.rb +35 -30
- data/lib/chef/win32/security.rb +1 -1
- data/lib/chef/win32/security/token.rb +1 -1
- data/lib/chef/win32/system.rb +62 -0
- data/lib/chef/win32/unicode.rb +7 -2
- data/lib/chef/win32/version.rb +0 -4
- data/lib/chef/workstation_config_loader.rb +3 -158
- data/spec/data/cookbooks/openldap/templates/default/helpers.erb +14 -0
- data/spec/data/cookbooks/openldap/templates/default/nested_openldap_partials.erb +1 -0
- data/spec/data/cookbooks/openldap/templates/default/nested_partial.erb +1 -0
- data/spec/data/dsc_lcm.pfx +0 -0
- data/spec/data/run_context/cookbooks/include/recipes/default.rb +24 -0
- data/spec/data/run_context/cookbooks/include/recipes/includee.rb +3 -0
- data/spec/functional/dsl/reboot_pending_spec.rb +33 -43
- data/spec/functional/knife/cookbook_delete_spec.rb +17 -7
- data/spec/functional/knife/ssh_spec.rb +16 -0
- data/spec/functional/rebooter_spec.rb +1 -1
- data/spec/functional/resource/deploy_revision_spec.rb +1 -1
- data/spec/functional/resource/dsc_resource_spec.rb +2 -0
- data/spec/functional/resource/dsc_script_spec.rb +91 -2
- data/spec/functional/resource/group_spec.rb +67 -44
- data/spec/functional/resource/{powershell_spec.rb → powershell_script_spec.rb} +107 -18
- data/spec/functional/resource/windows_service_spec.rb +1 -1
- data/spec/functional/run_lock_spec.rb +368 -189
- data/spec/functional/win32/{registry_helper_spec.rb → registry_spec.rb} +16 -23
- data/spec/functional/win32/service_manager_spec.rb +2 -2
- data/spec/integration/client/client_spec.rb +51 -0
- data/spec/integration/knife/chef_repo_path_spec.rb +13 -11
- data/spec/integration/knife/download_spec.rb +4 -0
- data/spec/integration/knife/list_spec.rb +8 -0
- data/spec/integration/knife/upload_spec.rb +1 -1
- data/spec/integration/recipes/recipe_dsl_spec.rb +1 -16
- data/spec/integration/recipes/remote_directory.rb +74 -0
- data/spec/integration/recipes/resource_action_spec.rb +363 -0
- data/spec/integration/recipes/resource_converge_if_changed_spec.rb +423 -0
- data/spec/integration/recipes/resource_load_spec.rb +206 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/support/platform_helpers.rb +13 -0
- data/spec/support/shared/context/win32.rb +34 -0
- data/spec/support/shared/functional/win32_service.rb +2 -1
- data/spec/support/shared/functional/windows_script.rb +63 -26
- data/spec/support/shared/unit/mock_shellout.rb +46 -0
- data/spec/support/shared/unit/provider/file.rb +10 -4
- data/spec/unit/application/client_spec.rb +16 -3
- data/spec/unit/application/knife_spec.rb +2 -2
- data/spec/unit/application/solo_spec.rb +4 -3
- data/spec/unit/chef_class_spec.rb +23 -4
- data/spec/unit/chef_fs/path_util_spec.rb +108 -0
- data/spec/unit/client_spec.rb +6 -1
- data/spec/unit/config_spec.rb +31 -0
- data/spec/unit/cookbook/metadata_spec.rb +23 -3
- data/spec/unit/cookbook/syntax_check_spec.rb +3 -0
- data/spec/unit/deprecation_spec.rb +3 -6
- data/spec/unit/dsl/reboot_pending_spec.rb +12 -6
- data/spec/unit/event_dispatch/dispatcher_spec.rb +65 -3
- data/spec/unit/event_dispatch/dsl_spec.rb +83 -0
- data/spec/unit/formatters/doc_spec.rb +32 -0
- data/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb +26 -0
- data/spec/unit/json_compat_spec.rb +4 -3
- data/spec/unit/knife/bootstrap/client_builder_spec.rb +27 -0
- data/spec/unit/knife/bootstrap_spec.rb +55 -3
- data/spec/unit/knife/cookbook_site_share_spec.rb +3 -3
- data/spec/unit/knife/core/bootstrap_context_spec.rb +21 -4
- data/spec/unit/knife/core/custom_manifest_loader_spec.rb +41 -0
- data/spec/unit/knife/core/gem_glob_loader_spec.rb +210 -0
- data/spec/unit/knife/core/hashed_command_loader_spec.rb +93 -0
- data/spec/unit/knife/core/subcommand_loader_spec.rb +16 -192
- data/spec/unit/knife/node_run_list_remove_spec.rb +17 -0
- data/spec/unit/knife/ssl_check_spec.rb +4 -0
- data/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb +10 -10
- data/spec/unit/mixin/params_validate_spec.rb +4 -2
- data/spec/unit/mixin/template_spec.rb +5 -1
- data/spec/unit/mixin/windows_architecture_helper_spec.rb +13 -8
- data/spec/unit/node_spec.rb +220 -0
- data/spec/unit/platform/query_helpers_spec.rb +146 -3
- data/spec/unit/policy_builder/dynamic_spec.rb +275 -0
- data/spec/unit/policy_builder/expand_node_object_spec.rb +37 -38
- data/spec/unit/policy_builder/policyfile_spec.rb +260 -46
- data/spec/unit/property/state_spec.rb +506 -0
- data/spec/unit/property/validation_spec.rb +663 -0
- data/spec/unit/property_spec.rb +1094 -0
- data/spec/unit/provider/deploy_spec.rb +5 -5
- data/spec/unit/provider/directory_spec.rb +35 -0
- data/spec/unit/provider/dsc_resource_spec.rb +3 -10
- data/spec/unit/provider/ifconfig_spec.rb +22 -2
- data/spec/unit/provider/mount/aix_spec.rb +2 -1
- data/spec/unit/provider/mount/mount_spec.rb +6 -0
- data/spec/unit/provider/mount/windows_spec.rb +14 -0
- data/spec/unit/provider/mount_spec.rb +12 -1
- data/spec/unit/provider/package/dpkg_spec.rb +8 -1
- data/spec/unit/provider/package/rpm_spec.rb +18 -1
- data/spec/unit/provider/package/rubygems_spec.rb +18 -0
- data/spec/unit/provider/package/yum_spec.rb +97 -24
- data/spec/unit/provider/powershell_script_spec.rb +106 -0
- data/spec/unit/provider/registry_key_spec.rb +12 -0
- data/spec/unit/provider/remote_directory_spec.rb +1 -2
- data/spec/unit/provider/service/aix_service_spec.rb +3 -3
- data/spec/unit/provider/service/gentoo_service_spec.rb +4 -4
- data/spec/unit/provider/service/macosx_spec.rb +4 -4
- data/spec/unit/provider/service/openbsd_service_spec.rb +10 -8
- data/spec/unit/provider/service/redhat_spec.rb +88 -8
- data/spec/unit/provider/service/upstart_service_spec.rb +11 -7
- data/spec/unit/provider/service/windows_spec.rb +211 -200
- data/spec/unit/provider/subversion_spec.rb +50 -31
- data/spec/unit/provider/template/content_spec.rb +93 -2
- data/spec/unit/provider/user/solaris_spec.rb +66 -9
- data/spec/unit/provider_resolver_spec.rb +707 -650
- data/spec/unit/provider_spec.rb +1 -3
- data/spec/unit/recipe_spec.rb +0 -4
- data/spec/unit/resource/deploy_spec.rb +7 -1
- data/spec/unit/resource/dsc_script_spec.rb +4 -0
- data/spec/unit/resource/file/verification_spec.rb +33 -5
- data/spec/unit/resource/{powershell_spec.rb → powershell_script_spec.rb} +17 -13
- data/spec/unit/resource/service_spec.rb +4 -4
- data/spec/unit/resource/subversion_spec.rb +4 -0
- data/spec/unit/resource/yum_package_spec.rb +10 -1
- data/spec/unit/resource_spec.rb +2 -2
- data/spec/unit/run_context/child_run_context_spec.rb +133 -0
- data/spec/unit/run_context_spec.rb +7 -0
- data/spec/unit/run_list/versioned_recipe_list_spec.rb +5 -0
- data/spec/unit/win32/registry_spec.rb +394 -0
- data/tasks/external_tests.rb +47 -23
- data/tasks/maintainers.rb +155 -14
- metadata +64 -53
- data/lib/chef/knife/bootstrap/templates/archlinux-gems.erb +0 -76
- data/lib/chef/knife/bootstrap/templates/chef-aix.erb +0 -72
- data/spec/unit/provider/powershell_spec.rb +0 -80
- data/spec/unit/registry_helper_spec.rb +0 -376
- data/spec/unit/workstation_config_loader_spec.rb +0 -283
@@ -0,0 +1,506 @@
|
|
1
|
+
require 'support/shared/integration/integration_helper'
|
2
|
+
|
3
|
+
describe "Chef::Resource#identity and #state" do
|
4
|
+
include IntegrationSupport
|
5
|
+
|
6
|
+
class NewResourceNamer
|
7
|
+
@i = 0
|
8
|
+
def self.next
|
9
|
+
"chef_resource_property_spec_#{@i += 1}"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.new_resource_name
|
14
|
+
NewResourceNamer.next
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:resource_class) do
|
18
|
+
new_resource_name = self.class.new_resource_name
|
19
|
+
Class.new(Chef::Resource) do
|
20
|
+
resource_name new_resource_name
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
let(:resource) do
|
25
|
+
resource_class.new("blah")
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.english_join(values)
|
29
|
+
return '<nothing>' if values.size == 0
|
30
|
+
return values[0].inspect if values.size == 1
|
31
|
+
"#{values[0..-2].map { |v| v.inspect }.join(", ")} and #{values[-1].inspect}"
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.with_property(*properties, &block)
|
35
|
+
tags_index = properties.find_index { |p| !p.is_a?(String)}
|
36
|
+
if tags_index
|
37
|
+
properties, tags = properties[0..tags_index-1], properties[tags_index..-1]
|
38
|
+
else
|
39
|
+
tags = []
|
40
|
+
end
|
41
|
+
properties = properties.map { |property| "property #{property}" }
|
42
|
+
context "With properties #{english_join(properties)}", *tags do
|
43
|
+
before do
|
44
|
+
properties.each do |property_str|
|
45
|
+
resource_class.class_eval(property_str, __FILE__, __LINE__)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
instance_eval(&block)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# identity
|
53
|
+
context "Chef::Resource#identity_properties" do
|
54
|
+
with_property ":x" do
|
55
|
+
it "name is the default identity" do
|
56
|
+
expect(resource_class.identity_properties).to eq [ Chef::Resource.properties[:name] ]
|
57
|
+
expect(Chef::Resource.properties[:name].identity?).to be_falsey
|
58
|
+
expect(resource.name).to eq 'blah'
|
59
|
+
expect(resource.identity).to eq 'blah'
|
60
|
+
end
|
61
|
+
|
62
|
+
it "identity_properties :x changes the identity" do
|
63
|
+
expect(resource_class.identity_properties :x).to eq [ resource_class.properties[:x] ]
|
64
|
+
expect(resource_class.identity_properties).to eq [ resource_class.properties[:x] ]
|
65
|
+
expect(Chef::Resource.properties[:name].identity?).to be_falsey
|
66
|
+
expect(resource_class.properties[:x].identity?).to be_truthy
|
67
|
+
|
68
|
+
expect(resource.x 'woo').to eq 'woo'
|
69
|
+
expect(resource.x).to eq 'woo'
|
70
|
+
|
71
|
+
expect(resource.name).to eq 'blah'
|
72
|
+
expect(resource.identity).to eq 'woo'
|
73
|
+
end
|
74
|
+
|
75
|
+
with_property ":y, identity: true" do
|
76
|
+
context "and identity_properties :x" do
|
77
|
+
before do
|
78
|
+
resource_class.class_eval do
|
79
|
+
identity_properties :x
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
it "only returns :x as identity" do
|
84
|
+
resource.x 'foo'
|
85
|
+
resource.y 'bar'
|
86
|
+
expect(resource_class.identity_properties).to eq [ resource_class.properties[:x] ]
|
87
|
+
expect(resource.identity).to eq 'foo'
|
88
|
+
end
|
89
|
+
it "does not flip y.desired_state off" do
|
90
|
+
resource.x 'foo'
|
91
|
+
resource.y 'bar'
|
92
|
+
expect(resource_class.state_properties).to eq [
|
93
|
+
resource_class.properties[:x],
|
94
|
+
resource_class.properties[:y]
|
95
|
+
]
|
96
|
+
expect(resource.state_for_resource_reporter).to eq(x: 'foo', y: 'bar')
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context "With a subclass" do
|
102
|
+
let(:subresource_class) do
|
103
|
+
new_resource_name = self.class.new_resource_name
|
104
|
+
Class.new(resource_class) do
|
105
|
+
resource_name new_resource_name
|
106
|
+
end
|
107
|
+
end
|
108
|
+
let(:subresource) do
|
109
|
+
subresource_class.new('sub')
|
110
|
+
end
|
111
|
+
|
112
|
+
it "name is the default identity on the subclass" do
|
113
|
+
expect(subresource_class.identity_properties).to eq [ Chef::Resource.properties[:name] ]
|
114
|
+
expect(Chef::Resource.properties[:name].identity?).to be_falsey
|
115
|
+
expect(subresource.name).to eq 'sub'
|
116
|
+
expect(subresource.identity).to eq 'sub'
|
117
|
+
end
|
118
|
+
|
119
|
+
context "With identity_properties :x on the superclass" do
|
120
|
+
before do
|
121
|
+
resource_class.class_eval do
|
122
|
+
identity_properties :x
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
it "The subclass inherits :x as identity" do
|
127
|
+
expect(subresource_class.identity_properties).to eq [ subresource_class.properties[:x] ]
|
128
|
+
expect(Chef::Resource.properties[:name].identity?).to be_falsey
|
129
|
+
expect(subresource_class.properties[:x].identity?).to be_truthy
|
130
|
+
|
131
|
+
subresource.x 'foo'
|
132
|
+
expect(subresource.identity).to eq 'foo'
|
133
|
+
end
|
134
|
+
|
135
|
+
context "With property :y, identity: true on the subclass" do
|
136
|
+
before do
|
137
|
+
subresource_class.class_eval do
|
138
|
+
property :y, identity: true
|
139
|
+
end
|
140
|
+
end
|
141
|
+
it "The subclass's identity includes both x and y" do
|
142
|
+
expect(subresource_class.identity_properties).to eq [
|
143
|
+
subresource_class.properties[:x],
|
144
|
+
subresource_class.properties[:y]
|
145
|
+
]
|
146
|
+
subresource.x 'foo'
|
147
|
+
subresource.y 'bar'
|
148
|
+
expect(subresource.identity).to eq(x: 'foo', y: 'bar')
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
with_property ":y, String" do
|
153
|
+
context "With identity_properties :y on the subclass" do
|
154
|
+
before do
|
155
|
+
subresource_class.class_eval do
|
156
|
+
identity_properties :y
|
157
|
+
end
|
158
|
+
end
|
159
|
+
it "y is part of state" do
|
160
|
+
subresource.x 'foo'
|
161
|
+
subresource.y 'bar'
|
162
|
+
expect(subresource.state_for_resource_reporter).to eq(x: 'foo', y: 'bar')
|
163
|
+
expect(subresource_class.state_properties).to eq [
|
164
|
+
subresource_class.properties[:x],
|
165
|
+
subresource_class.properties[:y]
|
166
|
+
]
|
167
|
+
end
|
168
|
+
it "y is the identity" do
|
169
|
+
expect(subresource_class.identity_properties).to eq [ subresource_class.properties[:y] ]
|
170
|
+
subresource.x 'foo'
|
171
|
+
subresource.y 'bar'
|
172
|
+
expect(subresource.identity).to eq 'bar'
|
173
|
+
end
|
174
|
+
it "y still has validation" do
|
175
|
+
expect { subresource.y 12 }.to raise_error Chef::Exceptions::ValidationFailed
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
with_property ":string_only, String, identity: true", ":string_only2, String" do
|
184
|
+
it "identity_properties does not change validation" do
|
185
|
+
resource_class.identity_properties :string_only
|
186
|
+
expect { resource.string_only 12 }.to raise_error Chef::Exceptions::ValidationFailed
|
187
|
+
expect { resource.string_only2 12 }.to raise_error Chef::Exceptions::ValidationFailed
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
with_property ":x, desired_state: false" do
|
192
|
+
it "identity_properties does not change desired_state" do
|
193
|
+
resource_class.identity_properties :x
|
194
|
+
resource.x 'hi'
|
195
|
+
expect(resource.identity).to eq 'hi'
|
196
|
+
expect(resource_class.properties[:x].desired_state?).to be_falsey
|
197
|
+
expect(resource_class.state_properties).to eq []
|
198
|
+
expect(resource.state_for_resource_reporter).to eq({})
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
context "With custom property custom_property defined only as methods, using different variables for storage" do
|
203
|
+
before do
|
204
|
+
resource_class.class_eval do
|
205
|
+
def custom_property
|
206
|
+
@blarghle ? @blarghle*3 : nil
|
207
|
+
end
|
208
|
+
def custom_property=(x)
|
209
|
+
@blarghle = x*2
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
context "And identity_properties :custom_property" do
|
215
|
+
before do
|
216
|
+
resource_class.class_eval do
|
217
|
+
identity_properties :custom_property
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
it "identity_properties comes back as :custom_property" do
|
222
|
+
expect(resource_class.properties[:custom_property].identity?).to be_truthy
|
223
|
+
expect(resource_class.identity_properties).to eq [ resource_class.properties[:custom_property] ]
|
224
|
+
end
|
225
|
+
it "custom_property becomes part of desired_state" do
|
226
|
+
resource.custom_property = 1
|
227
|
+
expect(resource.state_for_resource_reporter).to eq(custom_property: 6)
|
228
|
+
expect(resource_class.properties[:custom_property].desired_state?).to be_truthy
|
229
|
+
expect(resource_class.state_properties).to eq [
|
230
|
+
resource_class.properties[:custom_property]
|
231
|
+
]
|
232
|
+
end
|
233
|
+
it "identity_properties does not change custom_property's getter or setter" do
|
234
|
+
resource.custom_property = 1
|
235
|
+
expect(resource.custom_property).to eq 6
|
236
|
+
end
|
237
|
+
it "custom_property is returned as the identity" do
|
238
|
+
expect(resource.identity).to be_nil
|
239
|
+
resource.custom_property = 1
|
240
|
+
expect(resource.identity).to eq 6
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
context "Property#identity" do
|
247
|
+
with_property ":x, identity: true" do
|
248
|
+
it "name is only part of the identity if an identity attribute is defined" do
|
249
|
+
expect(resource_class.identity_properties).to eq [ resource_class.properties[:x] ]
|
250
|
+
resource.x 'woo'
|
251
|
+
expect(resource.identity).to eq 'woo'
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
with_property ":x, identity: true, default: 'xxx'",
|
256
|
+
":y, identity: true, default: 'yyy'",
|
257
|
+
":z, identity: true, default: 'zzz'" do
|
258
|
+
it "identity_property raises an error if multiple identity values are defined" do
|
259
|
+
expect { resource_class.identity_property }.to raise_error Chef::Exceptions::MultipleIdentityError
|
260
|
+
end
|
261
|
+
it "identity_attr raises an error if multiple identity values are defined" do
|
262
|
+
expect { resource_class.identity_attr }.to raise_error Chef::Exceptions::MultipleIdentityError
|
263
|
+
end
|
264
|
+
it "identity returns all identity values in a hash if multiple are defined" do
|
265
|
+
resource.x 'foo'
|
266
|
+
resource.y 'bar'
|
267
|
+
resource.z 'baz'
|
268
|
+
expect(resource.identity).to eq(x: 'foo', y: 'bar', z: 'baz')
|
269
|
+
end
|
270
|
+
it "identity returns all values whether any value is set or not" do
|
271
|
+
expect(resource.identity).to eq(x: 'xxx', y: 'yyy', z: 'zzz')
|
272
|
+
end
|
273
|
+
it "identity_properties wipes out any other identity attributes if multiple are defined" do
|
274
|
+
resource_class.identity_properties :y
|
275
|
+
resource.x 'foo'
|
276
|
+
resource.y 'bar'
|
277
|
+
resource.z 'baz'
|
278
|
+
expect(resource.identity).to eq 'bar'
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
with_property ":x, identity: true, name_property: true" do
|
283
|
+
it "identity when x is not defined returns the value of x" do
|
284
|
+
expect(resource.identity).to eq 'blah'
|
285
|
+
end
|
286
|
+
it "state when x is not defined returns the value of x" do
|
287
|
+
expect(resource.state_for_resource_reporter).to eq(x: 'blah')
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
# state_properties
|
293
|
+
context "Chef::Resource#state_properties" do
|
294
|
+
it "state_properties is empty by default" do
|
295
|
+
expect(Chef::Resource.state_properties).to eq []
|
296
|
+
expect(resource.state_for_resource_reporter).to eq({})
|
297
|
+
end
|
298
|
+
|
299
|
+
with_property ":x", ":y", ":z" do
|
300
|
+
it "x, y and z are state attributes" do
|
301
|
+
resource.x 1
|
302
|
+
resource.y 2
|
303
|
+
resource.z 3
|
304
|
+
expect(resource_class.state_properties).to eq [
|
305
|
+
resource_class.properties[:x],
|
306
|
+
resource_class.properties[:y],
|
307
|
+
resource_class.properties[:z]
|
308
|
+
]
|
309
|
+
expect(resource.state_for_resource_reporter).to eq(x: 1, y: 2, z: 3)
|
310
|
+
end
|
311
|
+
it "values that are not set are not included in state" do
|
312
|
+
resource.x 1
|
313
|
+
expect(resource.state_for_resource_reporter).to eq(x: 1)
|
314
|
+
end
|
315
|
+
it "when no values are set, nothing is included in state" do
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
with_property ":x", ":y, desired_state: false", ":z, desired_state: true" do
|
320
|
+
it "x and z are state attributes, and y is not" do
|
321
|
+
resource.x 1
|
322
|
+
resource.y 2
|
323
|
+
resource.z 3
|
324
|
+
expect(resource_class.state_properties).to eq [
|
325
|
+
resource_class.properties[:x],
|
326
|
+
resource_class.properties[:z]
|
327
|
+
]
|
328
|
+
expect(resource.state_for_resource_reporter).to eq(x: 1, z: 3)
|
329
|
+
end
|
330
|
+
end
|
331
|
+
|
332
|
+
with_property ":x, name_property: true" do
|
333
|
+
# it "Unset values with name_property are included in state" do
|
334
|
+
# expect(resource.state_for_resource_reporter).to eq({ x: 'blah' })
|
335
|
+
# end
|
336
|
+
it "Set values with name_property are included in state" do
|
337
|
+
resource.x 1
|
338
|
+
expect(resource.state_for_resource_reporter).to eq(x: 1)
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
with_property ":x, default: 1" do
|
343
|
+
it "Unset values with defaults are not included in state" do
|
344
|
+
expect(resource.state_for_resource_reporter).to eq({})
|
345
|
+
end
|
346
|
+
it "Set values with defaults are included in state" do
|
347
|
+
resource.x 1
|
348
|
+
expect(resource.state_for_resource_reporter).to eq(x: 1)
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
context "With a class with a normal getter and setter" do
|
353
|
+
before do
|
354
|
+
resource_class.class_eval do
|
355
|
+
def x
|
356
|
+
@blah*3
|
357
|
+
end
|
358
|
+
def x=(value)
|
359
|
+
@blah = value*2
|
360
|
+
end
|
361
|
+
end
|
362
|
+
end
|
363
|
+
it "state_properties(:x) causes the value to be included in properties" do
|
364
|
+
resource_class.state_properties(:x)
|
365
|
+
resource.x = 1
|
366
|
+
|
367
|
+
expect(resource.x).to eq 6
|
368
|
+
expect(resource.state_for_resource_reporter).to eq(x: 6)
|
369
|
+
end
|
370
|
+
end
|
371
|
+
|
372
|
+
context "When state_properties happens before properties are declared" do
|
373
|
+
before do
|
374
|
+
resource_class.class_eval do
|
375
|
+
state_properties :x
|
376
|
+
property :x
|
377
|
+
end
|
378
|
+
end
|
379
|
+
it "the property works and is in state_properties" do
|
380
|
+
expect(resource_class.state_properties).to include(resource_class.properties[:x])
|
381
|
+
resource.x = 1
|
382
|
+
expect(resource.x).to eq 1
|
383
|
+
expect(resource.state_for_resource_reporter).to eq(x: 1)
|
384
|
+
end
|
385
|
+
end
|
386
|
+
|
387
|
+
with_property ":x, Integer, identity: true" do
|
388
|
+
it "state_properties(:x) leaves the property in desired_state" do
|
389
|
+
resource_class.state_properties(:x)
|
390
|
+
resource.x 10
|
391
|
+
|
392
|
+
expect(resource_class.properties[:x].desired_state?).to be_truthy
|
393
|
+
expect(resource_class.state_properties).to eq [
|
394
|
+
resource_class.properties[:x]
|
395
|
+
]
|
396
|
+
expect(resource.state_for_resource_reporter).to eq(x: 10)
|
397
|
+
end
|
398
|
+
it "state_properties(:x) does not turn off validation" do
|
399
|
+
resource_class.state_properties(:x)
|
400
|
+
expect { resource.x 'ouch' }.to raise_error Chef::Exceptions::ValidationFailed
|
401
|
+
end
|
402
|
+
it "state_properties(:x) does not turn off identity" do
|
403
|
+
resource_class.state_properties(:x)
|
404
|
+
resource.x 10
|
405
|
+
|
406
|
+
expect(resource_class.identity_properties).to eq [ resource_class.properties[:x] ]
|
407
|
+
expect(resource_class.properties[:x].identity?).to be_truthy
|
408
|
+
expect(resource.identity).to eq 10
|
409
|
+
end
|
410
|
+
end
|
411
|
+
|
412
|
+
with_property ":x, Integer, identity: true, desired_state: false" do
|
413
|
+
before do
|
414
|
+
resource_class.class_eval do
|
415
|
+
def y
|
416
|
+
20
|
417
|
+
end
|
418
|
+
end
|
419
|
+
end
|
420
|
+
|
421
|
+
it "state_properties(:x) leaves x identical" do
|
422
|
+
old_value = resource_class.properties[:y]
|
423
|
+
resource_class.state_properties(:x)
|
424
|
+
resource.x 10
|
425
|
+
|
426
|
+
expect(resource_class.properties[:y].object_id).to eq old_value.object_id
|
427
|
+
|
428
|
+
expect(resource_class.properties[:x].desired_state?).to be_truthy
|
429
|
+
expect(resource_class.properties[:x].identity?).to be_truthy
|
430
|
+
expect(resource_class.identity_properties).to eq [
|
431
|
+
resource_class.properties[:x]
|
432
|
+
]
|
433
|
+
expect(resource.identity).to eq(10)
|
434
|
+
expect(resource_class.state_properties).to eq [
|
435
|
+
resource_class.properties[:x]
|
436
|
+
]
|
437
|
+
expect(resource.state_for_resource_reporter).to eq(x: 10)
|
438
|
+
end
|
439
|
+
|
440
|
+
it "state_properties(:y) adds y to desired state" do
|
441
|
+
old_value = resource_class.properties[:x]
|
442
|
+
resource_class.state_properties(:y)
|
443
|
+
resource.x 10
|
444
|
+
|
445
|
+
expect(resource_class.properties[:x].object_id).to eq old_value.object_id
|
446
|
+
expect(resource_class.properties[:x].desired_state?).to be_falsey
|
447
|
+
expect(resource_class.properties[:y].desired_state?).to be_truthy
|
448
|
+
expect(resource_class.state_properties).to eq [
|
449
|
+
resource_class.properties[:y]
|
450
|
+
]
|
451
|
+
expect(resource.state_for_resource_reporter).to eq(y: 20)
|
452
|
+
end
|
453
|
+
|
454
|
+
context "With a subclassed resource" do
|
455
|
+
let(:subresource_class) do
|
456
|
+
new_resource_name = self.class.new_resource_name
|
457
|
+
Class.new(resource_class) do
|
458
|
+
resource_name new_resource_name
|
459
|
+
end
|
460
|
+
end
|
461
|
+
let(:subresource) do
|
462
|
+
subresource_class.new('blah')
|
463
|
+
end
|
464
|
+
|
465
|
+
it "state_properties(:x) adds x to desired state" do
|
466
|
+
old_value = resource_class.properties[:y]
|
467
|
+
subresource_class.state_properties(:x)
|
468
|
+
subresource.x 10
|
469
|
+
|
470
|
+
expect(subresource_class.properties[:y].object_id).to eq old_value.object_id
|
471
|
+
|
472
|
+
expect(subresource_class.properties[:x].desired_state?).to be_truthy
|
473
|
+
expect(subresource_class.properties[:x].identity?).to be_truthy
|
474
|
+
expect(subresource_class.identity_properties).to eq [
|
475
|
+
subresource_class.properties[:x]
|
476
|
+
]
|
477
|
+
expect(subresource.identity).to eq(10)
|
478
|
+
expect(subresource_class.state_properties).to eq [
|
479
|
+
subresource_class.properties[:x]
|
480
|
+
]
|
481
|
+
expect(subresource.state_for_resource_reporter).to eq(x: 10)
|
482
|
+
end
|
483
|
+
|
484
|
+
it "state_properties(:y) adds y to desired state" do
|
485
|
+
old_value = resource_class.properties[:x]
|
486
|
+
subresource_class.state_properties(:y)
|
487
|
+
subresource.x 10
|
488
|
+
|
489
|
+
expect(subresource_class.properties[:x].object_id).to eq old_value.object_id
|
490
|
+
expect(subresource_class.properties[:y].desired_state?).to be_truthy
|
491
|
+
expect(subresource_class.state_properties).to eq [
|
492
|
+
subresource_class.properties[:y]
|
493
|
+
]
|
494
|
+
expect(subresource.state_for_resource_reporter).to eq(y: 20)
|
495
|
+
|
496
|
+
expect(subresource_class.properties[:x].identity?).to be_truthy
|
497
|
+
expect(subresource_class.identity_properties).to eq [
|
498
|
+
subresource_class.properties[:x]
|
499
|
+
]
|
500
|
+
expect(subresource.identity).to eq(10)
|
501
|
+
end
|
502
|
+
end
|
503
|
+
end
|
504
|
+
end
|
505
|
+
|
506
|
+
end
|