chef 12.4.3-universal-mingw32 → 12.5.1-universal-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/spec/unit/provider_spec.rb
CHANGED
@@ -114,9 +114,7 @@ describe Chef::Provider do
|
|
114
114
|
end
|
115
115
|
|
116
116
|
it "does not re-load recipes when creating the temporary run context" do
|
117
|
-
|
118
|
-
# can't stub all instances of an object with rspec's mocks. :/
|
119
|
-
allow(Chef::RunContext).to receive(:new).and_raise("not supposed to happen")
|
117
|
+
expect_any_instance_of(Chef::RunContext).not_to receive(:load)
|
120
118
|
snitch = Proc.new {temporary_collection = @run_context.resource_collection}
|
121
119
|
@provider.send(:recipe_eval, &snitch)
|
122
120
|
end
|
data/spec/unit/recipe_spec.rb
CHANGED
@@ -154,8 +154,6 @@ describe Chef::Recipe do
|
|
154
154
|
end
|
155
155
|
|
156
156
|
it "selects the first one alphabetically" do
|
157
|
-
expect(Chef::Log).to receive(:warn).with("You declared a new resource TottenhamHotspur for resource football, but it comes alphabetically after Sounders and has the same filters ({:platform=>\"nbc_sports\"}), so it will not be used. Use override: true if you want to use it for football.")
|
158
|
-
|
159
157
|
Sounders.provides :football, platform: "nbc_sports"
|
160
158
|
TottenhamHotspur.provides :football, platform: "nbc_sports"
|
161
159
|
|
@@ -165,8 +163,6 @@ describe Chef::Recipe do
|
|
165
163
|
end
|
166
164
|
|
167
165
|
it "selects the first one alphabetically even if the declaration order is reversed" do
|
168
|
-
expect(Chef::Log).to receive(:warn).with("You are overriding football2 on {:platform=>\"nbc_sports\"} with Sounders: used to be TottenhamHotspur. Use override: true if this is what you intended.")
|
169
|
-
|
170
166
|
TottenhamHotspur.provides :football2, platform: "nbc_sports"
|
171
167
|
Sounders.provides :football2, platform: "nbc_sports"
|
172
168
|
|
@@ -148,10 +148,16 @@ describe Chef::Resource::Deploy do
|
|
148
148
|
expect(@resource.current_path).to eql("/my/deploy/dir/current")
|
149
149
|
end
|
150
150
|
|
151
|
+
it "allows depth to be set via integer" do
|
152
|
+
expect(@resource.depth).to be_nil
|
153
|
+
@resource.depth 1
|
154
|
+
expect(@resource.depth).to eql(1)
|
155
|
+
end
|
156
|
+
|
151
157
|
it "gives #depth as 5 if shallow clone is true, nil otherwise" do
|
152
158
|
expect(@resource.depth).to be_nil
|
153
159
|
@resource.shallow_clone true
|
154
|
-
expect(@resource.depth).to eql(
|
160
|
+
expect(@resource.depth).to eql(5)
|
155
161
|
end
|
156
162
|
|
157
163
|
it "aliases repo as repository" do
|
@@ -70,6 +70,10 @@ describe Chef::Resource::DscScript do
|
|
70
70
|
expect(dsc_test_resource.configuration_data_script).to eq(configuration_data_script)
|
71
71
|
end
|
72
72
|
|
73
|
+
it "has the ps_credential helper method" do
|
74
|
+
expect(dsc_test_resource).to respond_to(:ps_credential)
|
75
|
+
end
|
76
|
+
|
73
77
|
context "when calling imports" do
|
74
78
|
let(:module_name) { 'FooModule' }
|
75
79
|
let(:module_name_b) { 'BarModule' }
|
@@ -69,12 +69,40 @@ describe Chef::Resource::File::Verification do
|
|
69
69
|
end
|
70
70
|
|
71
71
|
context "with a verification command(String)" do
|
72
|
+
before(:each) do
|
73
|
+
allow(Chef::Log).to receive(:deprecation).and_return(nil)
|
74
|
+
end
|
75
|
+
|
76
|
+
def platform_specific_verify_command(variable_name)
|
77
|
+
if windows?
|
78
|
+
"if \"#{temp_path}\" == \"%{#{variable_name}}\" (exit 0) else (exit 1)"
|
79
|
+
else
|
80
|
+
"test #{temp_path} = %{#{variable_name}}"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
72
84
|
it "substitutes \%{file} with the path" do
|
73
|
-
test_command =
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
85
|
+
test_command = platform_specific_verify_command('file')
|
86
|
+
v = Chef::Resource::File::Verification.new(parent_resource, test_command, {})
|
87
|
+
expect(v.verify(temp_path)).to eq(true)
|
88
|
+
end
|
89
|
+
|
90
|
+
it "warns about deprecation when \%{file} is used" do
|
91
|
+
expect(Chef::Log).to receive(:deprecation).with(/%{file} is deprecated/, /verification_spec\.rb/)
|
92
|
+
test_command = platform_specific_verify_command('file')
|
93
|
+
Chef::Resource::File::Verification.new(parent_resource, test_command, {})
|
94
|
+
.verify(temp_path)
|
95
|
+
end
|
96
|
+
|
97
|
+
it "does not warn about deprecation when \%{file} is not used" do
|
98
|
+
expect(Chef::Log).to_not receive(:deprecation)
|
99
|
+
test_command = platform_specific_verify_command('path')
|
100
|
+
Chef::Resource::File::Verification.new(parent_resource, test_command, {})
|
101
|
+
.verify(temp_path)
|
102
|
+
end
|
103
|
+
|
104
|
+
it "substitutes \%{path} with the path" do
|
105
|
+
test_command = platform_specific_verify_command('path')
|
78
106
|
v = Chef::Resource::File::Verification.new(parent_resource, test_command, {})
|
79
107
|
expect(v.verify(temp_path)).to eq(true)
|
80
108
|
end
|
@@ -30,24 +30,28 @@ describe Chef::Resource::PowershellScript do
|
|
30
30
|
run_context = Chef::RunContext.new(node, nil, nil)
|
31
31
|
|
32
32
|
@resource = Chef::Resource::PowershellScript.new("powershell_unit_test", run_context)
|
33
|
-
|
34
33
|
end
|
35
34
|
|
36
|
-
it "
|
35
|
+
it "creates a new Chef::Resource::PowershellScript" do
|
37
36
|
expect(@resource).to be_a_kind_of(Chef::Resource::PowershellScript)
|
38
37
|
end
|
39
38
|
|
40
|
-
it "
|
39
|
+
it "sets convert_boolean_return to false by default" do
|
41
40
|
expect(@resource.convert_boolean_return).to eq(false)
|
42
41
|
end
|
43
42
|
|
44
|
-
it "
|
43
|
+
it "returns the value for convert_boolean_return that was set" do
|
45
44
|
@resource.convert_boolean_return true
|
46
45
|
expect(@resource.convert_boolean_return).to eq(true)
|
47
46
|
@resource.convert_boolean_return false
|
48
47
|
expect(@resource.convert_boolean_return).to eq(false)
|
49
48
|
end
|
50
49
|
|
50
|
+
it "raises an error when architecture is i386 on Windows Nano Server" do
|
51
|
+
allow(Chef::Platform).to receive(:windows_nano_server?).and_return(true)
|
52
|
+
expect{@resource.architecture(:i386)}.to raise_error(Chef::Exceptions::Win32ArchitectureIncorrect, "cannot execute script with requested architecture 'i386' on Windows Nano Server")
|
53
|
+
end
|
54
|
+
|
51
55
|
context "when using guards" do
|
52
56
|
let(:resource) { @resource }
|
53
57
|
before(:each) do
|
@@ -62,32 +66,32 @@ describe Chef::Resource::PowershellScript do
|
|
62
66
|
expect(inherited_difference).to eq([])
|
63
67
|
end
|
64
68
|
|
65
|
-
it "
|
69
|
+
it "allows guard interpreter to be set to Chef::Resource::Script" do
|
66
70
|
resource.guard_interpreter(:script)
|
67
71
|
allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:evaluate_action).and_return(false)
|
68
72
|
resource.only_if("echo hi")
|
69
73
|
end
|
70
74
|
|
71
|
-
it "
|
75
|
+
it "allows guard interpreter to be set to Chef::Resource::Bash derived from Chef::Resource::Script" do
|
72
76
|
resource.guard_interpreter(:bash)
|
73
77
|
allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:evaluate_action).and_return(false)
|
74
78
|
resource.only_if("echo hi")
|
75
79
|
end
|
76
80
|
|
77
|
-
it "
|
81
|
+
it "allows guard interpreter to be set to Chef::Resource::PowershellScript derived indirectly from Chef::Resource::Script" do
|
78
82
|
resource.guard_interpreter(:powershell_script)
|
79
83
|
allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:evaluate_action).and_return(false)
|
80
84
|
resource.only_if("echo hi")
|
81
85
|
end
|
82
86
|
|
83
|
-
it "
|
87
|
+
it "enables convert_boolean_return by default for guards in the context of powershell_script when no guard params are specified" do
|
84
88
|
allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:evaluate_action).and_return(true)
|
85
89
|
allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:block_from_attributes).with(
|
86
90
|
{:convert_boolean_return => true, :code => "$true"}).and_return(Proc.new {})
|
87
91
|
resource.only_if("$true")
|
88
92
|
end
|
89
93
|
|
90
|
-
it "
|
94
|
+
it "enables convert_boolean_return by default for guards in non-Chef::Resource::Script derived resources when no guard params are specified" do
|
91
95
|
node = Chef::Node.new
|
92
96
|
run_context = Chef::RunContext.new(node, nil, nil)
|
93
97
|
file_resource = Chef::Resource::File.new('idontexist', run_context)
|
@@ -98,21 +102,21 @@ describe Chef::Resource::PowershellScript do
|
|
98
102
|
resource.only_if("$true")
|
99
103
|
end
|
100
104
|
|
101
|
-
it "
|
105
|
+
it "enables convert_boolean_return by default for guards in the context of powershell_script when guard params are specified" do
|
102
106
|
guard_parameters = {:cwd => '/etc/chef', :architecture => :x86_64}
|
103
107
|
allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:block_from_attributes).with(
|
104
108
|
{:convert_boolean_return => true, :code => "$true"}.merge(guard_parameters)).and_return(Proc.new {})
|
105
109
|
resource.only_if("$true", guard_parameters)
|
106
110
|
end
|
107
111
|
|
108
|
-
it "
|
112
|
+
it "passes convert_boolean_return as true if it was specified as true in a guard parameter" do
|
109
113
|
guard_parameters = {:cwd => '/etc/chef', :convert_boolean_return => true, :architecture => :x86_64}
|
110
114
|
allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:block_from_attributes).with(
|
111
115
|
{:convert_boolean_return => true, :code => "$true"}.merge(guard_parameters)).and_return(Proc.new {})
|
112
116
|
resource.only_if("$true", guard_parameters)
|
113
117
|
end
|
114
118
|
|
115
|
-
it "
|
119
|
+
it "passes convert_boolean_return as false if it was specified as true in a guard parameter" do
|
116
120
|
other_guard_parameters = {:cwd => '/etc/chef', :architecture => :x86_64}
|
117
121
|
parameters_with_boolean_disabled = other_guard_parameters.merge({:convert_boolean_return => false, :code => "$true"})
|
118
122
|
allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:block_from_attributes).with(
|
@@ -127,6 +131,6 @@ describe Chef::Resource::PowershellScript do
|
|
127
131
|
let(:resource_name) { :powershell_script }
|
128
132
|
let(:interpreter_file_name) { 'powershell.exe' }
|
129
133
|
|
130
|
-
|
134
|
+
it_behaves_like "a Windows script resource"
|
131
135
|
end
|
132
136
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#
|
2
2
|
# Author:: AJ Christensen (<aj@hjksolutions.com>)
|
3
3
|
# Author:: Tyler Cloke (<tyler@opscode.com>)
|
4
|
-
# Copyright:: Copyright (c) 2008
|
4
|
+
# Copyright:: Copyright (c) 2008-2015 Chef Software, Inc.
|
5
5
|
# License:: Apache License, Version 2.0
|
6
6
|
#
|
7
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -139,14 +139,14 @@ describe Chef::Resource::Service do
|
|
139
139
|
expect { @resource.send(attrib, "poop") }.to raise_error(ArgumentError)
|
140
140
|
end
|
141
141
|
|
142
|
-
it "should default all the feature support to
|
143
|
-
support_hash = { :status =>
|
142
|
+
it "should default all the feature support to nil" do
|
143
|
+
support_hash = { :status => nil, :restart => nil, :reload=> nil }
|
144
144
|
expect(@resource.supports).to eq(support_hash)
|
145
145
|
end
|
146
146
|
|
147
147
|
it "should allow you to set what features this resource supports as a array" do
|
148
148
|
support_array = [ :status, :restart ]
|
149
|
-
support_hash = { :status => true, :restart => true, :reload =>
|
149
|
+
support_hash = { :status => true, :restart => true, :reload => nil }
|
150
150
|
@resource.supports(support_array)
|
151
151
|
expect(@resource.supports).to eq(support_hash)
|
152
152
|
end
|
@@ -54,6 +54,10 @@ describe Chef::Resource::Subversion do
|
|
54
54
|
expect(@svn.svn_arguments).to eq('--no-auth-cache')
|
55
55
|
end
|
56
56
|
|
57
|
+
it "sets svn binary to nil by default" do
|
58
|
+
expect(@svn.svn_binary).to be_nil
|
59
|
+
end
|
60
|
+
|
57
61
|
it "resets svn arguments to nil when given false in the setter" do
|
58
62
|
@svn.svn_arguments(false)
|
59
63
|
expect(@svn.svn_arguments).to be_nil
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# Author:: AJ Christensen (<aj@opscode.com>)
|
3
|
-
# Copyright:: Copyright (c) 2008
|
3
|
+
# Copyright:: Copyright (c) 2008-2015 Chef Software, Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -78,3 +78,12 @@ describe Chef::Resource::YumPackage, "allow_downgrade" do
|
|
78
78
|
expect { @resource.allow_downgrade "monkey" }.to raise_error(ArgumentError)
|
79
79
|
end
|
80
80
|
end
|
81
|
+
|
82
|
+
describe Chef::Resource::YumPackage, "yum_binary" do
|
83
|
+
let(:resource) { Chef::Resource::YumPackage.new("foo") }
|
84
|
+
|
85
|
+
it "should allow you to specify the yum_binary" do
|
86
|
+
resource.yum_binary "/usr/bin/yum-something"
|
87
|
+
expect(resource.yum_binary).to eql("/usr/bin/yum-something")
|
88
|
+
end
|
89
|
+
end
|
data/spec/unit/resource_spec.rb
CHANGED
@@ -59,8 +59,8 @@ describe Chef::Resource do
|
|
59
59
|
end
|
60
60
|
|
61
61
|
describe "when declaring the identity attribute" do
|
62
|
-
it "has
|
63
|
-
expect(Chef::Resource.identity_attr).to
|
62
|
+
it "has :name as identity attribute by default" do
|
63
|
+
expect(Chef::Resource.identity_attr).to eq(:name)
|
64
64
|
end
|
65
65
|
|
66
66
|
it "sets an identity attribute" do
|
@@ -0,0 +1,133 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
+
# Author:: Tim Hinderliter (<tim@opscode.com>)
|
4
|
+
# Author:: Christopher Walters (<cw@opscode.com>)
|
5
|
+
# Copyright:: Copyright (c) 2008, 2010 Opscode, Inc.
|
6
|
+
# License:: Apache License, Version 2.0
|
7
|
+
#
|
8
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
9
|
+
# you may not use this file except in compliance with the License.
|
10
|
+
# You may obtain a copy of the License at
|
11
|
+
#
|
12
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
13
|
+
#
|
14
|
+
# Unless required by applicable law or agreed to in writing, software
|
15
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
16
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
17
|
+
# See the License for the specific language governing permissions and
|
18
|
+
# limitations under the License.
|
19
|
+
#
|
20
|
+
|
21
|
+
require 'spec_helper'
|
22
|
+
require 'support/lib/library_load_order'
|
23
|
+
|
24
|
+
describe Chef::RunContext::ChildRunContext do
|
25
|
+
context "with a run context with stuff in it" do
|
26
|
+
let(:chef_repo_path) { File.expand_path(File.join(CHEF_SPEC_DATA, "run_context", "cookbooks")) }
|
27
|
+
let(:cookbook_collection) {
|
28
|
+
cl = Chef::CookbookLoader.new(chef_repo_path)
|
29
|
+
cl.load_cookbooks
|
30
|
+
Chef::CookbookCollection.new(cl)
|
31
|
+
}
|
32
|
+
let(:node) {
|
33
|
+
node = Chef::Node.new
|
34
|
+
node.run_list << "test" << "test::one" << "test::two"
|
35
|
+
node
|
36
|
+
}
|
37
|
+
let(:events) { Chef::EventDispatch::Dispatcher.new }
|
38
|
+
let(:run_context) { Chef::RunContext.new(node, cookbook_collection, events) }
|
39
|
+
|
40
|
+
context "and a child run context" do
|
41
|
+
let(:child) { run_context.create_child }
|
42
|
+
|
43
|
+
it "parent_run_context is set to the parent" do
|
44
|
+
expect(child.parent_run_context).to eq run_context
|
45
|
+
end
|
46
|
+
|
47
|
+
it "audits is not the same as the parent" do
|
48
|
+
expect(child.audits.object_id).not_to eq run_context.audits.object_id
|
49
|
+
child.audits['hi'] = 'lo'
|
50
|
+
expect(child.audits['hi']).to eq('lo')
|
51
|
+
expect(run_context.audits['hi']).not_to eq('lo')
|
52
|
+
end
|
53
|
+
|
54
|
+
it "resource_collection is not the same as the parent" do
|
55
|
+
expect(child.resource_collection.object_id).not_to eq run_context.resource_collection.object_id
|
56
|
+
f = Chef::Resource::File.new('hi', child)
|
57
|
+
child.resource_collection.insert(f)
|
58
|
+
expect(child.resource_collection).to include f
|
59
|
+
expect(run_context.resource_collection).not_to include f
|
60
|
+
end
|
61
|
+
|
62
|
+
it "immediate_notification_collection is not the same as the parent" do
|
63
|
+
expect(child.immediate_notification_collection.object_id).not_to eq run_context.immediate_notification_collection.object_id
|
64
|
+
src = Chef::Resource::File.new('hi', child)
|
65
|
+
dest = Chef::Resource::File.new('argh', child)
|
66
|
+
notification = Chef::Resource::Notification.new(dest, :create, src)
|
67
|
+
child.notifies_immediately(notification)
|
68
|
+
expect(child.immediate_notification_collection['file[hi]']).to eq([notification])
|
69
|
+
expect(run_context.immediate_notification_collection['file[hi]']).not_to eq([notification])
|
70
|
+
end
|
71
|
+
|
72
|
+
it "immediate_notifications is not the same as the parent" do
|
73
|
+
src = Chef::Resource::File.new('hi', child)
|
74
|
+
dest = Chef::Resource::File.new('argh', child)
|
75
|
+
notification = Chef::Resource::Notification.new(dest, :create, src)
|
76
|
+
child.notifies_immediately(notification)
|
77
|
+
expect(child.immediate_notifications(src)).to eq([notification])
|
78
|
+
expect(run_context.immediate_notifications(src)).not_to eq([notification])
|
79
|
+
end
|
80
|
+
|
81
|
+
it "delayed_notification_collection is not the same as the parent" do
|
82
|
+
expect(child.delayed_notification_collection.object_id).not_to eq run_context.delayed_notification_collection.object_id
|
83
|
+
src = Chef::Resource::File.new('hi', child)
|
84
|
+
dest = Chef::Resource::File.new('argh', child)
|
85
|
+
notification = Chef::Resource::Notification.new(dest, :create, src)
|
86
|
+
child.notifies_delayed(notification)
|
87
|
+
expect(child.delayed_notification_collection['file[hi]']).to eq([notification])
|
88
|
+
expect(run_context.delayed_notification_collection['file[hi]']).not_to eq([notification])
|
89
|
+
end
|
90
|
+
|
91
|
+
it "delayed_notifications is not the same as the parent" do
|
92
|
+
src = Chef::Resource::File.new('hi', child)
|
93
|
+
dest = Chef::Resource::File.new('argh', child)
|
94
|
+
notification = Chef::Resource::Notification.new(dest, :create, src)
|
95
|
+
child.notifies_delayed(notification)
|
96
|
+
expect(child.delayed_notifications(src)).to eq([notification])
|
97
|
+
expect(run_context.delayed_notifications(src)).not_to eq([notification])
|
98
|
+
end
|
99
|
+
|
100
|
+
it "create_child creates a child-of-child" do
|
101
|
+
c = child.create_child
|
102
|
+
expect(c.parent_run_context).to eq child
|
103
|
+
end
|
104
|
+
|
105
|
+
context "after load('include::default')" do
|
106
|
+
before do
|
107
|
+
run_list = Chef::RunList.new('include::default').expand('_default')
|
108
|
+
# TODO not sure why we had to do this to get everything to work ...
|
109
|
+
node.automatic_attrs[:recipes] = []
|
110
|
+
child.load(run_list)
|
111
|
+
end
|
112
|
+
|
113
|
+
it "load_recipe loads into the child" do
|
114
|
+
expect(child.resource_collection).to be_empty
|
115
|
+
child.load_recipe("include::includee")
|
116
|
+
expect(child.resource_collection).not_to be_empty
|
117
|
+
end
|
118
|
+
|
119
|
+
it "include_recipe loads into the child" do
|
120
|
+
expect(child.resource_collection).to be_empty
|
121
|
+
child.include_recipe("include::includee")
|
122
|
+
expect(child.resource_collection).not_to be_empty
|
123
|
+
end
|
124
|
+
|
125
|
+
it "load_recipe_file loads into the child" do
|
126
|
+
expect(child.resource_collection).to be_empty
|
127
|
+
child.load_recipe_file(File.expand_path("include/recipes/includee.rb", chef_repo_path))
|
128
|
+
expect(child.resource_collection).not_to be_empty
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
@@ -68,6 +68,9 @@ describe Chef::RunContext do
|
|
68
68
|
"dependency2" => {
|
69
69
|
"version" => "0.0.0",
|
70
70
|
},
|
71
|
+
"include" => {
|
72
|
+
"version" => "0.0.0",
|
73
|
+
},
|
71
74
|
"no-default-attr" => {
|
72
75
|
"version" => "0.0.0",
|
73
76
|
},
|
@@ -84,6 +87,10 @@ describe Chef::RunContext do
|
|
84
87
|
)
|
85
88
|
end
|
86
89
|
|
90
|
+
it "has a nil parent_run_context" do
|
91
|
+
expect(run_context.parent_run_context).to be_nil
|
92
|
+
end
|
93
|
+
|
87
94
|
describe "loading cookbooks for a run list" do
|
88
95
|
before do
|
89
96
|
|
@@ -0,0 +1,394 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Prajakta Purohit (prajakta@opscode.com)
|
3
|
+
# Copyright:: Copyright (c) 2012 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'spec_helper'
|
20
|
+
|
21
|
+
describe Chef::Win32::Registry do
|
22
|
+
include_context "Win32"
|
23
|
+
|
24
|
+
let(:value1) { { :name => "one", :type => :string, :data => "1" } }
|
25
|
+
let(:value1_upcase_name) { {:name => "ONE", :type => :string, :data => "1"} }
|
26
|
+
let(:key_path) { 'HKCU\Software\OpscodeNumbers' }
|
27
|
+
let(:key) { 'Software\OpscodeNumbers' }
|
28
|
+
let(:key_parent) { 'Software' }
|
29
|
+
let(:key_to_delete) { 'OpscodeNumbers' }
|
30
|
+
let(:sub_key) {'OpscodePrimes'}
|
31
|
+
let(:missing_key_path) {'HKCU\Software'}
|
32
|
+
let(:registry) { Chef::Win32::Registry.new() }
|
33
|
+
let(:hive_mock) { double("::Win32::Registry::KHKEY_CURRENT_USER") }
|
34
|
+
let(:reg_mock) { double("reg") }
|
35
|
+
|
36
|
+
before(:all) do
|
37
|
+
Win32::Registry = Class.new
|
38
|
+
Win32::Registry::Error = Class.new(RuntimeError)
|
39
|
+
end
|
40
|
+
|
41
|
+
before(:each) do
|
42
|
+
allow_any_instance_of(Chef::Win32::Registry).to receive(:machine_architecture).and_return(:x86_64)
|
43
|
+
|
44
|
+
#Making the values for registry constants available on unix
|
45
|
+
Win32::Registry::KEY_SET_VALUE = 0x0002
|
46
|
+
Win32::Registry::KEY_QUERY_VALUE = 0x0001
|
47
|
+
Win32::Registry::KEY_WRITE = 0x00020000 | 0x0002 | 0x0004
|
48
|
+
Win32::Registry::KEY_READ = 0x00020000 | 0x0001 | 0x0008 | 0x0010
|
49
|
+
end
|
50
|
+
|
51
|
+
after(:each) do
|
52
|
+
Win32::Registry.send(:remove_const, 'KEY_SET_VALUE') if defined?(Win32::Registry::KEY_SET_VALUE)
|
53
|
+
Win32::Registry.send(:remove_const, 'KEY_QUERY_VALUE') if defined?(Win32::Registry::KEY_QUERY_VALUE)
|
54
|
+
Win32::Registry.send(:remove_const, 'KEY_READ') if defined?(Win32::Registry::KEY_READ)
|
55
|
+
Win32::Registry.send(:remove_const, 'KEY_WRITE') if defined?(Win32::Registry::KEY_WRITE)
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "get_values" do
|
59
|
+
it "gets all values for a key if the key exists" do
|
60
|
+
expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
|
61
|
+
expect(registry).to receive(:key_exists!).with(key_path).and_return(true)
|
62
|
+
expect(hive_mock).to receive(:open).with(key, ::Win32::Registry::KEY_READ | registry.registry_system_architecture).and_yield(reg_mock)
|
63
|
+
expect(reg_mock).to receive(:map)
|
64
|
+
registry.get_values(key_path)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "throws an exception if key does not exist" do
|
68
|
+
expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
|
69
|
+
expect(registry).to receive(:key_exists!).with(key_path).and_raise(Chef::Exceptions::Win32RegKeyMissing)
|
70
|
+
expect{registry.get_values(key_path)}.to raise_error(Chef::Exceptions::Win32RegKeyMissing)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "set_value" do
|
75
|
+
it "does nothing if key and hive and value exist" do
|
76
|
+
expect(registry).to receive(:key_exists!).with(key_path).and_return(true)
|
77
|
+
expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
|
78
|
+
expect(registry).to receive(:value_exists?).with(key_path, value1).and_return(true)
|
79
|
+
expect(registry).to receive(:data_exists?).with(key_path, value1).and_return(true)
|
80
|
+
registry.set_value(key_path, value1)
|
81
|
+
end
|
82
|
+
it "does nothing if case insensitive key and hive and value exist" do
|
83
|
+
expect(registry).to receive(:key_exists!).with(key_path.downcase).and_return(true)
|
84
|
+
expect(registry).to receive(:get_hive_and_key).with(key_path.downcase).and_return([hive_mock, key])
|
85
|
+
expect(registry).to receive(:value_exists?).with(key_path.downcase, value1).and_return(true)
|
86
|
+
expect(registry).to receive(:data_exists?).with(key_path.downcase, value1).and_return(true)
|
87
|
+
registry.set_value(key_path.downcase, value1)
|
88
|
+
end
|
89
|
+
it "does nothing if key and hive and value with a case insensitive name exist" do
|
90
|
+
expect(registry).to receive(:key_exists!).with(key_path.downcase).and_return(true)
|
91
|
+
expect(registry).to receive(:get_hive_and_key).with(key_path.downcase).and_return([hive_mock, key])
|
92
|
+
expect(registry).to receive(:value_exists?).with(key_path.downcase, value1_upcase_name).and_return(true)
|
93
|
+
expect(registry).to receive(:data_exists?).with(key_path.downcase, value1_upcase_name).and_return(true)
|
94
|
+
registry.set_value(key_path.downcase, value1_upcase_name)
|
95
|
+
end
|
96
|
+
it "updates value if key and hive and value exist, but data is different" do
|
97
|
+
expect(registry).to receive(:key_exists!).with(key_path).and_return(true)
|
98
|
+
expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
|
99
|
+
expect(registry).to receive(:value_exists?).with(key_path, value1).and_return(true)
|
100
|
+
expect(registry).to receive(:data_exists?).with(key_path, value1).and_return(false)
|
101
|
+
expect(hive_mock).to receive(:open).with(key, Win32::Registry::KEY_SET_VALUE | ::Win32::Registry::KEY_QUERY_VALUE | registry.registry_system_architecture).and_yield(reg_mock)
|
102
|
+
expect(registry).to receive(:get_type_from_name).with(:string).and_return(1)
|
103
|
+
expect(reg_mock).to receive(:write).with("one", 1, "1")
|
104
|
+
registry.set_value(key_path, value1)
|
105
|
+
end
|
106
|
+
|
107
|
+
it "creates value if the key exists and the value does not exist" do
|
108
|
+
expect(registry).to receive(:key_exists!).with(key_path).and_return(true)
|
109
|
+
expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
|
110
|
+
expect(registry).to receive(:value_exists?).with(key_path, value1).and_return(false)
|
111
|
+
expect(hive_mock).to receive(:open).with(key, ::Win32::Registry::KEY_SET_VALUE | ::Win32::Registry::KEY_QUERY_VALUE | registry.registry_system_architecture).and_yield(reg_mock)
|
112
|
+
expect(registry).to receive(:get_type_from_name).with(:string).and_return(1)
|
113
|
+
expect(reg_mock).to receive(:write).with("one", 1, "1")
|
114
|
+
registry.set_value(key_path, value1)
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should raise an exception if the key does not exist" do
|
118
|
+
expect(registry).to receive(:key_exists!).with(key_path).and_raise(Chef::Exceptions::Win32RegKeyMissing)
|
119
|
+
expect {registry.set_value(key_path, value1)}.to raise_error(Chef::Exceptions::Win32RegKeyMissing)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe "delete_value" do
|
124
|
+
it "deletes value if value exists" do
|
125
|
+
expect(registry).to receive(:value_exists?).with(key_path, value1).and_return(true)
|
126
|
+
expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
|
127
|
+
expect(hive_mock).to receive(:open).with(key, ::Win32::Registry::KEY_SET_VALUE | registry.registry_system_architecture).and_yield(reg_mock)
|
128
|
+
expect(reg_mock).to receive(:delete_value).with("one").and_return(true)
|
129
|
+
registry.delete_value(key_path, value1)
|
130
|
+
end
|
131
|
+
|
132
|
+
it "raises an exception if the key does not exist" do
|
133
|
+
expect(registry).to receive(:value_exists?).with(key_path, value1).and_return(true)
|
134
|
+
expect(registry).to receive(:get_hive_and_key).with(key_path).and_raise(Chef::Exceptions::Win32RegKeyMissing)
|
135
|
+
registry.delete_value(key_path, value1)
|
136
|
+
end
|
137
|
+
|
138
|
+
it "does nothing if the value does not exist" do
|
139
|
+
expect(registry).to receive(:value_exists?).with(key_path, value1).and_return(false)
|
140
|
+
registry.delete_value(key_path, value1)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
describe "create_key" do
|
145
|
+
it "creates key if intermediate keys are missing and recursive is set to true" do
|
146
|
+
expect(registry).to receive(:keys_missing?).with(key_path).and_return(true)
|
147
|
+
expect(registry).to receive(:create_missing).with(key_path)
|
148
|
+
expect(registry).to receive(:key_exists?).with(key_path).and_return(false)
|
149
|
+
expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
|
150
|
+
expect(hive_mock).to receive(:create).with(key, ::Win32::Registry::KEY_WRITE | registry.registry_system_architecture)
|
151
|
+
registry.create_key(key_path, true)
|
152
|
+
end
|
153
|
+
|
154
|
+
it "raises an exception if intermediate keys are missing and recursive is set to false" do
|
155
|
+
expect(registry).to receive(:keys_missing?).with(key_path).and_return(true)
|
156
|
+
expect{registry.create_key(key_path, false)}.to raise_error(Chef::Exceptions::Win32RegNoRecursive)
|
157
|
+
end
|
158
|
+
|
159
|
+
it "does nothing if the key exists" do
|
160
|
+
expect(registry).to receive(:keys_missing?).with(key_path).and_return(true)
|
161
|
+
expect(registry).to receive(:create_missing).with(key_path)
|
162
|
+
expect(registry).to receive(:key_exists?).with(key_path).and_return(true)
|
163
|
+
registry.create_key(key_path, true)
|
164
|
+
end
|
165
|
+
|
166
|
+
it "create key if intermediate keys not missing and recursive is set to false" do
|
167
|
+
expect(registry).to receive(:keys_missing?).with(key_path).and_return(false)
|
168
|
+
expect(registry).to receive(:key_exists?).with(key_path).and_return(false)
|
169
|
+
expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
|
170
|
+
expect(hive_mock).to receive(:create).with(key, ::Win32::Registry::KEY_WRITE | registry.registry_system_architecture)
|
171
|
+
registry.create_key(key_path, false)
|
172
|
+
end
|
173
|
+
|
174
|
+
it "create key if intermediate keys not missing and recursive is set to true" do
|
175
|
+
expect(registry).to receive(:keys_missing?).with(key_path).and_return(false)
|
176
|
+
expect(registry).to receive(:key_exists?).with(key_path).and_return(false)
|
177
|
+
expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
|
178
|
+
expect(hive_mock).to receive(:create).with(key, ::Win32::Registry::KEY_WRITE | registry.registry_system_architecture)
|
179
|
+
registry.create_key(key_path, true)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
describe "delete_key", :windows_only do
|
184
|
+
it "deletes key if it has subkeys and recursive is set to true" do
|
185
|
+
expect(registry).to receive(:key_exists?).with(key_path).and_return(true)
|
186
|
+
expect(registry).to receive(:has_subkeys?).with(key_path).and_return(true)
|
187
|
+
expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
|
188
|
+
expect(hive_mock).to receive(:open).with(key_parent, ::Win32::Registry::KEY_WRITE | registry.registry_system_architecture).and_yield(reg_mock)
|
189
|
+
expect(reg_mock).to receive(:delete_key).with(key_to_delete, true).and_return(true)
|
190
|
+
registry.delete_key(key_path, true)
|
191
|
+
end
|
192
|
+
|
193
|
+
it "raises an exception if it has subkeys but recursive is set to false" do
|
194
|
+
expect(registry).to receive(:key_exists?).with(key_path).and_return(true)
|
195
|
+
expect(registry).to receive(:has_subkeys?).with(key_path).and_return(true)
|
196
|
+
expect{registry.delete_key(key_path, false)}.to raise_error(Chef::Exceptions::Win32RegNoRecursive)
|
197
|
+
end
|
198
|
+
|
199
|
+
it "deletes key if the key exists and has no subkeys" do
|
200
|
+
expect(registry).to receive(:key_exists?).with(key_path).and_return(true)
|
201
|
+
expect(registry).to receive(:has_subkeys?).with(key_path).and_return(false)
|
202
|
+
expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
|
203
|
+
expect(hive_mock).to receive(:open).with(key_parent, ::Win32::Registry::KEY_WRITE | registry.registry_system_architecture).and_yield(reg_mock)
|
204
|
+
expect(reg_mock).to receive(:delete_key).with(key_to_delete, true).and_return(true)
|
205
|
+
registry.delete_key(key_path, true)
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
describe "key_exists?" do
|
210
|
+
it "returns true if key_exists" do
|
211
|
+
expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
|
212
|
+
expect(hive_mock).to receive(:open).with(key, ::Win32::Registry::KEY_READ | registry.registry_system_architecture).and_yield(reg_mock)
|
213
|
+
expect(registry.key_exists?(key_path)).to eq(true)
|
214
|
+
end
|
215
|
+
|
216
|
+
it "returns false if key does not exist" do
|
217
|
+
expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
|
218
|
+
expect(hive_mock).to receive(:open).with(key, ::Win32::Registry::KEY_READ | registry.registry_system_architecture).and_raise(::Win32::Registry::Error)
|
219
|
+
expect(registry.key_exists?(key_path)).to eq(false)
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
describe "key_exists!" do
|
224
|
+
it "throws an exception if the key_parent does not exist" do
|
225
|
+
expect(registry).to receive(:key_exists?).with(key_path).and_return(false)
|
226
|
+
expect{registry.key_exists!(key_path)}.to raise_error(Chef::Exceptions::Win32RegKeyMissing)
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
describe "hive_exists?" do
|
231
|
+
it "returns true if the hive exists" do
|
232
|
+
expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
|
233
|
+
registry.hive_exists?(key_path) == true
|
234
|
+
end
|
235
|
+
|
236
|
+
it "returns false if the hive does not exist" do
|
237
|
+
expect(registry).to receive(:get_hive_and_key).with(key_path).and_raise(Chef::Exceptions::Win32RegHiveMissing)
|
238
|
+
registry.hive_exists?(key_path) == false
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
describe "has_subkeys?" do
|
243
|
+
it "returns true if the key has subkeys" do
|
244
|
+
expect(registry).to receive(:key_exists!).with(key_path).and_return(true)
|
245
|
+
expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
|
246
|
+
expect(hive_mock).to receive(:open).with(key, ::Win32::Registry::KEY_READ | registry.registry_system_architecture).and_yield(reg_mock)
|
247
|
+
expect(reg_mock).to receive(:each_key).and_yield(key)
|
248
|
+
registry.has_subkeys?(key_path) == true
|
249
|
+
end
|
250
|
+
|
251
|
+
it "returns false if the key does not have subkeys" do
|
252
|
+
expect(registry).to receive(:key_exists!).with(key_path).and_return(true)
|
253
|
+
expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
|
254
|
+
expect(hive_mock).to receive(:open).with(key, ::Win32::Registry::KEY_READ | registry.registry_system_architecture).and_yield(reg_mock)
|
255
|
+
expect(reg_mock).to receive(:each_key).and_return(no_args())
|
256
|
+
expect(registry.has_subkeys?(key_path)).to eq(false)
|
257
|
+
end
|
258
|
+
|
259
|
+
it "throws an exception if the key does not exist" do
|
260
|
+
expect(registry).to receive(:key_exists!).with(key_path).and_raise(Chef::Exceptions::Win32RegKeyMissing)
|
261
|
+
expect {registry.set_value(key_path, value1)}.to raise_error(Chef::Exceptions::Win32RegKeyMissing)
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
describe "get_subkeys" do
|
266
|
+
it "returns the subkeys if they exist" do
|
267
|
+
expect(registry).to receive(:key_exists!).with(key_path).and_return(true)
|
268
|
+
expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
|
269
|
+
expect(hive_mock).to receive(:open).with(key, ::Win32::Registry::KEY_READ | registry.registry_system_architecture).and_yield(reg_mock)
|
270
|
+
expect(reg_mock).to receive(:each_key).and_yield(sub_key)
|
271
|
+
registry.get_subkeys(key_path)
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
describe "value_exists?" do
|
276
|
+
it "throws an exception if the key does not exist" do
|
277
|
+
expect(registry).to receive(:key_exists!).with(key_path).and_raise(Chef::Exceptions::Win32RegKeyMissing)
|
278
|
+
expect {registry.value_exists?(key_path, value1)}.to raise_error(Chef::Exceptions::Win32RegKeyMissing)
|
279
|
+
end
|
280
|
+
|
281
|
+
it "returns true if the value exists" do
|
282
|
+
expect(registry).to receive(:key_exists!).with(key_path).and_return(true)
|
283
|
+
expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
|
284
|
+
expect(hive_mock).to receive(:open).with(key, ::Win32::Registry::KEY_READ | registry.registry_system_architecture).and_yield(reg_mock)
|
285
|
+
expect(reg_mock).to receive(:any?).and_yield("one")
|
286
|
+
registry.value_exists?(key_path, value1) == true
|
287
|
+
end
|
288
|
+
|
289
|
+
it "returns false if the value does not exist" do
|
290
|
+
expect(registry).to receive(:key_exists!).with(key_path).and_return(true)
|
291
|
+
expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
|
292
|
+
expect(hive_mock).to receive(:open).with(key, ::Win32::Registry::KEY_READ | registry.registry_system_architecture).and_yield(reg_mock)
|
293
|
+
expect(reg_mock).to receive(:any?).and_yield(no_args())
|
294
|
+
registry.value_exists?(key_path, value1) == false
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
describe "data_exists?" do
|
299
|
+
it "throws an exception if the key does not exist" do
|
300
|
+
expect(registry).to receive(:key_exists!).with(key_path).and_raise(Chef::Exceptions::Win32RegKeyMissing)
|
301
|
+
expect {registry.data_exists?(key_path, value1)}.to raise_error(Chef::Exceptions::Win32RegKeyMissing)
|
302
|
+
end
|
303
|
+
|
304
|
+
it "returns true if the data exists" do
|
305
|
+
expect(registry).to receive(:key_exists!).with(key_path).and_return(true)
|
306
|
+
expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
|
307
|
+
expect(registry).to receive(:get_type_from_name).with(:string).and_return(1)
|
308
|
+
expect(reg_mock).to receive(:each).with(no_args()).and_yield("one", 1, "1")
|
309
|
+
expect(hive_mock).to receive(:open).with(key, ::Win32::Registry::KEY_READ | registry.registry_system_architecture).and_yield(reg_mock)
|
310
|
+
expect(registry.data_exists?(key_path, value1)).to eq(true)
|
311
|
+
end
|
312
|
+
|
313
|
+
it "returns false if the data does not exist" do
|
314
|
+
expect(registry).to receive(:key_exists!).with(key_path).and_return(true)
|
315
|
+
expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
|
316
|
+
expect(hive_mock).to receive(:open).with(key, ::Win32::Registry::KEY_READ | registry.registry_system_architecture).and_yield(reg_mock)
|
317
|
+
expect(registry).to receive(:get_type_from_name).with(:string).and_return(1)
|
318
|
+
expect(reg_mock).to receive(:each).with(no_args()).and_yield("one", 1, "2")
|
319
|
+
expect(registry.data_exists?(key_path, value1)).to eq(false)
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
describe "value_exists!" do
|
324
|
+
it "does nothing if the value exists" do
|
325
|
+
expect(registry).to receive(:value_exists?).with(key_path, value1).and_return(true)
|
326
|
+
registry.value_exists!(key_path, value1)
|
327
|
+
end
|
328
|
+
|
329
|
+
it "throws an exception if the value does not exist" do
|
330
|
+
expect(registry).to receive(:value_exists?).with(key_path, value1).and_return(false)
|
331
|
+
expect{registry.value_exists!(key_path, value1)}.to raise_error(Chef::Exceptions::Win32RegValueMissing)
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
335
|
+
describe "data_exists!" do
|
336
|
+
it "does nothing if the data exists" do
|
337
|
+
expect(registry).to receive(:data_exists?).with(key_path, value1).and_return(true)
|
338
|
+
registry.data_exists!(key_path, value1)
|
339
|
+
end
|
340
|
+
|
341
|
+
it "throws an exception if the data does not exist" do
|
342
|
+
expect(registry).to receive(:data_exists?).with(key_path, value1).and_return(false)
|
343
|
+
expect{registry.data_exists!(key_path, value1)}.to raise_error(Chef::Exceptions::Win32RegDataMissing)
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
347
|
+
describe "type_matches?" do
|
348
|
+
it "returns true if type matches" do
|
349
|
+
expect(registry).to receive(:value_exists!).with(key_path, value1).and_return(true)
|
350
|
+
expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
|
351
|
+
expect(hive_mock).to receive(:open).with(key, ::Win32::Registry::KEY_READ | registry.registry_system_architecture).and_yield(reg_mock)
|
352
|
+
expect(registry).to receive(:get_type_from_name).with(:string).and_return(1)
|
353
|
+
expect(reg_mock).to receive(:each).and_yield("one", 1)
|
354
|
+
expect(registry.type_matches?(key_path, value1)).to eq(true)
|
355
|
+
end
|
356
|
+
|
357
|
+
it "returns false if type does not match" do
|
358
|
+
expect(registry).to receive(:value_exists!).with(key_path, value1).and_return(true)
|
359
|
+
expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
|
360
|
+
expect(hive_mock).to receive(:open).with(key, ::Win32::Registry::KEY_READ | registry.registry_system_architecture).and_yield(reg_mock)
|
361
|
+
expect(reg_mock).to receive(:each).and_yield("two", 2)
|
362
|
+
expect(registry.type_matches?(key_path, value1)).to eq(false)
|
363
|
+
end
|
364
|
+
|
365
|
+
it "throws an exception if value does not exist" do
|
366
|
+
expect(registry).to receive(:value_exists?).with(key_path, value1).and_return(false)
|
367
|
+
expect{registry.type_matches?(key_path, value1)}.to raise_error(Chef::Exceptions::Win32RegValueMissing)
|
368
|
+
end
|
369
|
+
end
|
370
|
+
|
371
|
+
describe "type_matches!" do
|
372
|
+
it "does nothing if the type_matches" do
|
373
|
+
expect(registry).to receive(:type_matches?).with(key_path, value1).and_return(true)
|
374
|
+
registry.type_matches!(key_path, value1)
|
375
|
+
end
|
376
|
+
|
377
|
+
it "throws an exception if the type does not match" do
|
378
|
+
expect(registry).to receive(:type_matches?).with(key_path, value1).and_return(false)
|
379
|
+
expect{registry.type_matches!(key_path, value1)}.to raise_error(Chef::Exceptions::Win32RegTypesMismatch)
|
380
|
+
end
|
381
|
+
end
|
382
|
+
|
383
|
+
describe "keys_missing?" do
|
384
|
+
it "returns true if the keys are missing" do
|
385
|
+
expect(registry).to receive(:key_exists?).with(missing_key_path).and_return(false)
|
386
|
+
expect(registry.keys_missing?(key_path)).to eq(true)
|
387
|
+
end
|
388
|
+
|
389
|
+
it "returns false if no keys in the path are missing" do
|
390
|
+
expect(registry).to receive(:key_exists?).with(missing_key_path).and_return(true)
|
391
|
+
expect(registry.keys_missing?(key_path)).to eq(false)
|
392
|
+
end
|
393
|
+
end
|
394
|
+
end
|