chef 14.1.12 → 14.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (178) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -6
  3. data/VERSION +1 -1
  4. data/chef.gemspec +2 -3
  5. data/lib/chef/chef_fs/data_handler/data_handler_base.rb +8 -4
  6. data/lib/chef/cookbook/manifest_v0.rb +2 -2
  7. data/lib/chef/cookbook_manifest.rb +3 -2
  8. data/lib/chef/cookbook_version.rb +3 -2
  9. data/lib/chef/guard_interpreter/default_guard_interpreter.rb +2 -2
  10. data/lib/chef/http/auth_credentials.rb +5 -3
  11. data/lib/chef/http/authenticator.rb +6 -3
  12. data/lib/chef/knife.rb +3 -6
  13. data/lib/chef/knife/configure.rb +12 -8
  14. data/lib/chef/knife/raw.rb +6 -1
  15. data/lib/chef/mixin/shell_out.rb +16 -14
  16. data/lib/chef/provider/execute.rb +4 -3
  17. data/lib/chef/provider/git.rb +1 -1
  18. data/lib/chef/provider/package/dnf.rb +5 -5
  19. data/lib/chef/provider/package/windows.rb +7 -0
  20. data/lib/chef/provider/package/yum.rb +7 -7
  21. data/lib/chef/provider/service/freebsd.rb +3 -3
  22. data/lib/chef/provider/service/init.rb +5 -5
  23. data/lib/chef/provider/service/macosx.rb +5 -4
  24. data/lib/chef/provider/service/simple.rb +4 -4
  25. data/lib/chef/provider/service/systemd.rb +13 -13
  26. data/lib/chef/provider/service/upstart.rb +3 -3
  27. data/lib/chef/provider/service/windows.rb +2 -0
  28. data/lib/chef/provider/systemd_unit.rb +4 -4
  29. data/lib/chef/provider/user.rb +18 -1
  30. data/lib/chef/provider/user/aix.rb +40 -8
  31. data/lib/chef/provider/user/dscl.rb +7 -14
  32. data/lib/chef/provider/user/linux.rb +1 -11
  33. data/lib/chef/provider/user/solaris.rb +57 -26
  34. data/lib/chef/provider/user/useradd.rb +4 -1
  35. data/lib/chef/provider/windows_task.rb +1 -0
  36. data/lib/chef/providers.rb +1 -2
  37. data/lib/chef/resource/execute.rb +4 -1
  38. data/lib/chef/resource/gem_package.rb +1 -1
  39. data/lib/chef/resource/hostname.rb +1 -1
  40. data/lib/chef/resource/sysctl.rb +3 -1
  41. data/lib/chef/resource/windows_ad_join.rb +16 -3
  42. data/lib/chef/resource_inspector.rb +13 -0
  43. data/lib/chef/run_context/cookbook_compiler.rb +1 -1
  44. data/lib/chef/server_api.rb +2 -0
  45. data/lib/chef/version.rb +1 -1
  46. data/spec/functional/mixin/shell_out_spec.rb +27 -1
  47. data/spec/functional/resource/execute_spec.rb +2 -2
  48. data/spec/functional/resource/windows_task_spec.rb +1 -1
  49. data/spec/support/shared/functional/securable_resource.rb +1 -1
  50. data/spec/support/shared/unit/execute_resource.rb +1 -1
  51. data/spec/support/shared/unit/provider/useradd_based_user_provider.rb +3 -3
  52. data/spec/unit/chef_fs/data_handler/data_handler_base_spec.rb +65 -0
  53. data/spec/unit/cookbook/manifest_v0_spec.rb +1 -1
  54. data/spec/unit/cookbook_manifest_spec.rb +2 -0
  55. data/spec/unit/dsl/recipe_spec.rb +1 -5
  56. data/spec/unit/http/authenticator_spec.rb +33 -8
  57. data/spec/unit/mixin/shell_out_spec.rb +61 -1
  58. data/spec/unit/provider/apt_update_spec.rb +7 -7
  59. data/spec/unit/provider/execute_spec.rb +16 -15
  60. data/spec/unit/provider/git_spec.rb +3 -3
  61. data/spec/unit/provider/package/windows_spec.rb +12 -0
  62. data/spec/unit/provider/script_spec.rb +2 -2
  63. data/spec/unit/provider/service/arch_service_spec.rb +9 -9
  64. data/spec/unit/provider/service/freebsd_service_spec.rb +6 -6
  65. data/spec/unit/provider/service/init_service_spec.rb +11 -11
  66. data/spec/unit/provider/service/invokercd_service_spec.rb +9 -9
  67. data/spec/unit/provider/service/macosx_spec.rb +11 -11
  68. data/spec/unit/provider/service/openbsd_service_spec.rb +6 -6
  69. data/spec/unit/provider/service/simple_service_spec.rb +4 -4
  70. data/spec/unit/provider/service/systemd_service_spec.rb +16 -16
  71. data/spec/unit/provider/service/upstart_service_spec.rb +12 -12
  72. data/spec/unit/provider/service/windows_spec.rb +5 -0
  73. data/spec/unit/provider/systemd_unit_spec.rb +163 -118
  74. data/spec/unit/provider/user/dscl_spec.rb +2 -9
  75. data/spec/unit/provider/user/solaris_spec.rb +2 -2
  76. data/spec/unit/provider/zypper_repository_spec.rb +3 -3
  77. data/spec/unit/provider_spec.rb +1 -5
  78. data/spec/unit/resource/apt_package_spec.rb +14 -0
  79. data/spec/unit/resource/apt_preference_spec.rb +14 -1
  80. data/spec/unit/resource/apt_repository_spec.rb +12 -3
  81. data/spec/unit/resource/apt_update_spec.rb +9 -0
  82. data/spec/unit/resource/bash_spec.rb +8 -0
  83. data/spec/unit/resource/bff_package_spec.rb +51 -0
  84. data/spec/unit/resource/breakpoint_spec.rb +4 -4
  85. data/spec/unit/resource/build_essential_spec.rb +5 -1
  86. data/spec/unit/resource/cab_package_spec.rb +10 -0
  87. data/spec/unit/resource/chef_gem_spec.rb +14 -0
  88. data/spec/unit/resource/chef_handler_spec.rb +9 -4
  89. data/spec/unit/resource/chocolatey_package_spec.rb +15 -1
  90. data/spec/unit/resource/conditional_spec.rb +3 -3
  91. data/spec/unit/resource/cookbook_file_spec.rb +13 -2
  92. data/spec/unit/resource/cron_spec.rb +2 -7
  93. data/spec/unit/resource/csh_spec.rb +8 -0
  94. data/spec/unit/resource/directory_spec.rb +4 -9
  95. data/spec/unit/resource/dmg_package_spec.rb +8 -4
  96. data/spec/unit/resource/dnf_package_spec.rb +16 -1
  97. data/spec/unit/resource/dpkg_package_spec.rb +18 -0
  98. data/spec/unit/resource/dsc_resource_spec.rb +6 -6
  99. data/spec/unit/resource/dsc_script_spec.rb +39 -39
  100. data/spec/unit/resource/execute_spec.rb +20 -12
  101. data/spec/unit/resource/file_spec.rb +10 -10
  102. data/spec/unit/resource/freebsd_package_spec.rb +16 -0
  103. data/spec/unit/resource/gem_package_spec.rb +27 -0
  104. data/spec/unit/resource/git_spec.rb +17 -2
  105. data/spec/unit/resource/group_spec.rb +18 -17
  106. data/spec/unit/resource/homebrew_cask_spec.rb +9 -4
  107. data/spec/unit/resource/homebrew_package_spec.rb +14 -0
  108. data/spec/unit/resource/homebrew_tap_spec.rb +8 -3
  109. data/spec/unit/resource/hostname_spec.rb +10 -6
  110. data/spec/unit/resource/http_request_spec.rb +14 -0
  111. data/spec/unit/resource/ips_package_spec.rb +15 -3
  112. data/spec/unit/resource/ksh_spec.rb +8 -0
  113. data/spec/unit/resource/launchd_spec.rb +11 -5
  114. data/spec/unit/resource/link_spec.rb +6 -11
  115. data/spec/unit/resource/log_spec.rb +8 -8
  116. data/spec/unit/resource/macos_user_defaults_spec.rb +5 -1
  117. data/spec/unit/resource/macports_package_spec.rb +19 -0
  118. data/spec/unit/resource/mdadm_spec.rb +7 -3
  119. data/spec/unit/resource/mount_spec.rb +15 -18
  120. data/spec/unit/resource/msu_package_spec.rb +10 -0
  121. data/spec/unit/resource/ohai_hint_spec.rb +9 -8
  122. data/spec/unit/resource/ohai_spec.rb +11 -3
  123. data/spec/unit/resource/openbsd_package_spec.rb +14 -0
  124. data/spec/unit/resource/openssl_dhparam.rb +10 -5
  125. data/spec/unit/resource/openssl_rsa_private_key_spec.rb +10 -5
  126. data/spec/unit/resource/openssl_rsa_public_key_spec.rb +9 -5
  127. data/spec/unit/resource/osx_profile_spec.rb +7 -4
  128. data/spec/unit/resource/package_spec.rb +14 -0
  129. data/spec/unit/resource/pacman_package_spec.rb +17 -3
  130. data/spec/unit/resource/paludis_package_spec.rb +36 -0
  131. data/spec/unit/resource/perl_spec.rb +8 -0
  132. data/spec/unit/resource/portage_package_spec.rb +14 -0
  133. data/spec/unit/resource/powershell_package_spec.rb +14 -0
  134. data/spec/unit/resource/python_spec.rb +8 -0
  135. data/spec/unit/resource/reboot_spec.rb +5 -3
  136. data/spec/unit/resource/registry_key_spec.rb +12 -1
  137. data/spec/unit/resource/remote_directory_spec.rb +11 -1
  138. data/spec/unit/resource/remote_file_spec.rb +19 -0
  139. data/spec/unit/resource/rhsm_errata_level_spec.rb +7 -3
  140. data/spec/unit/resource/rhsm_errata_spec.rb +8 -4
  141. data/spec/unit/resource/rhsm_register_spec.rb +6 -1
  142. data/spec/unit/resource/rhsm_repo_spec.rb +9 -4
  143. data/spec/unit/resource/rhsm_subscription_spec.rb +9 -4
  144. data/spec/unit/resource/route_spec.rb +4 -9
  145. data/spec/unit/resource/rpm_package_spec.rb +14 -0
  146. data/spec/unit/resource/ruby_block_spec.rb +12 -8
  147. data/spec/unit/resource/ruby_spec.rb +8 -0
  148. data/spec/unit/resource/scm_spec.rb +16 -8
  149. data/spec/unit/resource/script_spec.rb +8 -0
  150. data/spec/unit/resource/service_spec.rb +15 -0
  151. data/spec/unit/resource/smartos_package_spec.rb +18 -4
  152. data/spec/unit/resource/solaris_package_spec.rb +14 -0
  153. data/spec/unit/resource/subversion_spec.rb +14 -8
  154. data/spec/unit/resource/sudo_spec.rb +11 -4
  155. data/spec/unit/resource/swap_file_spec.rb +4 -5
  156. data/spec/unit/resource/sysctl_spec.rb +8 -10
  157. data/spec/unit/resource/systemd_unit_spec.rb +14 -12
  158. data/spec/unit/resource/template_spec.rb +19 -0
  159. data/spec/unit/resource/{windows_ad_join.rb → windows_ad_join_spec.rb} +12 -6
  160. data/spec/unit/resource/windows_auto_run_spec.rb +9 -9
  161. data/spec/unit/resource/windows_env_spec.rb +8 -16
  162. data/spec/unit/resource/windows_feature.rb +27 -8
  163. data/spec/unit/resource/windows_feature_dism.rb +30 -9
  164. data/spec/unit/resource/windows_feature_powershell.rb +7 -7
  165. data/spec/unit/resource/windows_font_spec.rb +3 -4
  166. data/spec/unit/resource/windows_package_spec.rb +12 -2
  167. data/spec/unit/resource/windows_pagefile_spec.rb +12 -8
  168. data/spec/unit/resource/windows_path_spec.rb +4 -5
  169. data/spec/unit/resource/windows_printer_port_spec.rb +20 -3
  170. data/spec/unit/resource/windows_printer_spec.rb +12 -5
  171. data/spec/unit/resource/windows_service_spec.rb +24 -1
  172. data/spec/unit/resource/windows_shortcut_spec.rb +4 -5
  173. data/spec/unit/resource/yum_repository_spec.rb +48 -2
  174. data/spec/unit/resource/zypper_package_spec.rb +51 -0
  175. data/spec/unit/resource/zypper_repository_spec.rb +56 -11
  176. data/spec/unit/resource_spec.rb +1 -5
  177. metadata +21 -12
  178. data/spec/functional/resource/user/useradd_spec.rb +0 -709
@@ -22,22 +22,17 @@ require "spec_helper"
22
22
  describe Chef::Resource::Directory do
23
23
  let(:resource) { Chef::Resource::Directory.new("fakey_fakerton") }
24
24
 
25
- it "has a name property" do
26
- expect(resource.name).to eql("fakey_fakerton")
25
+ it "the path property is the name_property" do
26
+ expect(resource.path).to eql("fakey_fakerton")
27
27
  end
28
28
 
29
- it "has a default action of 'create'" do
29
+ it "sets the default action as :create" do
30
30
  expect(resource.action).to eql([:create])
31
31
  end
32
32
 
33
- it "accepts create or delete for action" do
33
+ it "supports :create, :delete actions" do
34
34
  expect { resource.action :create }.not_to raise_error
35
35
  expect { resource.action :delete }.not_to raise_error
36
- expect { resource.action :blues }.to raise_error(ArgumentError)
37
- end
38
-
39
- it "uses the object name as the path by default" do
40
- expect(resource.path).to eql("fakey_fakerton")
41
36
  end
42
37
 
43
38
  it "accepts a string as the path" do
@@ -19,17 +19,21 @@ require "spec_helper"
19
19
 
20
20
  describe Chef::Resource::DmgPackage do
21
21
 
22
- let(:resource) { Chef::Resource::DmgPackage.new("myapp") }
22
+ let(:resource) { Chef::Resource::DmgPackage.new("fakey_fakerton") }
23
23
 
24
24
  it "has a resource name of :dmg_package" do
25
25
  expect(resource.resource_name).to eql(:dmg_package)
26
26
  end
27
27
 
28
- it "has a default action of install" do
28
+ it "the app property is the name_property" do
29
+ expect(resource.app).to eql("fakey_fakerton")
30
+ end
31
+
32
+ it "sets the default action as :install" do
29
33
  expect(resource.action).to eql([:install])
30
34
  end
31
35
 
32
- it "the app property is the name property" do
33
- expect(resource.app).to eql("myapp")
36
+ it "supports :install action" do
37
+ expect { resource.action :install }.not_to raise_error
34
38
  end
35
39
  end
@@ -31,13 +31,28 @@ describe Chef::Resource::DnfPackage, "initialize" do
31
31
 
32
32
  end
33
33
 
34
- describe Chef::Resource::DnfPackage, "arch" do
34
+ describe Chef::Resource::DnfPackage, "defaults" do
35
35
  let(:resource) { Chef::Resource::DnfPackage.new("foo") }
36
36
 
37
37
  it "sets the arch variable to whatever is passed in" do
38
38
  resource.arch("i386")
39
39
  expect(resource.arch).to eql(["i386"])
40
40
  end
41
+
42
+ it "sets the default action as :install" do
43
+ expect(resource.action).to eql([:install])
44
+ end
45
+
46
+ it "supports :flush_cache, :install, :lock, :purge, :reconfig, :remove, :unlock, :upgrade actions" do
47
+ expect { resource.action :flush_cache }.not_to raise_error
48
+ expect { resource.action :install }.not_to raise_error
49
+ expect { resource.action :lock }.not_to raise_error
50
+ expect { resource.action :purge }.not_to raise_error
51
+ expect { resource.action :reconfig }.not_to raise_error
52
+ expect { resource.action :remove }.not_to raise_error
53
+ expect { resource.action :unlock }.not_to raise_error
54
+ expect { resource.action :upgrade }.not_to raise_error
55
+ end
41
56
  end
42
57
 
43
58
  describe Chef::Resource::DnfPackage, "flush_cache" do
@@ -29,4 +29,22 @@ describe Chef::Resource::DpkgPackage, "initialize" do
29
29
  os: "linux"
30
30
  )
31
31
 
32
+ describe Chef::Resource::DpkgPackage, "defaults" do
33
+ let(:resource) { Chef::Resource::DpkgPackage.new("fakey_fakerton") }
34
+
35
+ it "sets the default action as :install" do
36
+ expect(resource.action).to eql([:install])
37
+ end
38
+
39
+ it "supports :install, :lock, :purge, :reconfig, :remove, :unlock, :upgrade actions" do
40
+ expect { resource.action :install }.not_to raise_error
41
+ expect { resource.action :lock }.not_to raise_error
42
+ expect { resource.action :purge }.not_to raise_error
43
+ expect { resource.action :reconfig }.not_to raise_error
44
+ expect { resource.action :remove }.not_to raise_error
45
+ expect { resource.action :unlock }.not_to raise_error
46
+ expect { resource.action :upgrade }.not_to raise_error
47
+ end
48
+ end
49
+
32
50
  end
@@ -40,31 +40,31 @@ describe Chef::Resource::DscResource do
40
40
  expect(dsc_test_resource.action).to eq([:run])
41
41
  end
42
42
 
43
- it "has an ed_actions attribute with only the `:run` and `:nothing` attributes" do
43
+ it "has an ed_actions property with only the `:run` and `:nothing` properties" do
44
44
  expect(dsc_test_resource.allowed_actions.to_set).to eq([:run, :nothing].to_set)
45
45
  end
46
46
 
47
- it "allows the resource attribute to be set" do
47
+ it "allows the resource property to be set" do
48
48
  dsc_test_resource.resource(dsc_test_resource_name)
49
49
  expect(dsc_test_resource.resource).to eq(dsc_test_resource_name)
50
50
  end
51
51
 
52
- it "allows the module_name attribute to be set" do
52
+ it "allows the module_name property to be set" do
53
53
  dsc_test_resource.module_name(dsc_test_resource_name)
54
54
  expect(dsc_test_resource.module_name).to eq(dsc_test_resource_name)
55
55
  end
56
56
 
57
- it "allows the module_version attribute to be set" do
57
+ it "allows the module_version property to be set" do
58
58
  dsc_test_resource.module_version(dsc_test_resource_module_version)
59
59
  expect(dsc_test_resource.module_version).to eq(dsc_test_resource_module_version)
60
60
  end
61
61
 
62
- it "allows the reboot_action attribute to be set" do
62
+ it "allows the reboot_action property to be set" do
63
63
  dsc_test_resource.reboot_action(dsc_test_reboot_action)
64
64
  expect(dsc_test_resource.reboot_action).to eq(dsc_test_reboot_action)
65
65
  end
66
66
 
67
- it "allows the timeout attribute to be set" do
67
+ it "allows the timeout property to be set" do
68
68
  dsc_test_resource.timeout(dsc_test_timeout)
69
69
  expect(dsc_test_resource.timeout).to eq(dsc_test_timeout)
70
70
  end
@@ -19,7 +19,7 @@
19
19
  require "spec_helper"
20
20
 
21
21
  describe Chef::Resource::DscScript do
22
- let(:dsc_test_resource_name) { "DSCTest" }
22
+ let(:resource_name) { "DSCTest" }
23
23
 
24
24
  context "when Powershell supports Dsc" do
25
25
  let(:dsc_test_run_context) do
@@ -28,8 +28,8 @@ describe Chef::Resource::DscScript do
28
28
  empty_events = Chef::EventDispatch::Dispatcher.new
29
29
  Chef::RunContext.new(node, {}, empty_events)
30
30
  end
31
- let(:dsc_test_resource) do
32
- Chef::Resource::DscScript.new(dsc_test_resource_name, dsc_test_run_context)
31
+ let(:resource) do
32
+ Chef::Resource::DscScript.new(resource_name, dsc_test_run_context)
33
33
  end
34
34
  let(:configuration_code) { 'echo "This is supposed to create a configuration document."' }
35
35
  let(:configuration_path) { "c:/myconfigs/formatc.ps1" }
@@ -37,41 +37,41 @@ describe Chef::Resource::DscScript do
37
37
  let(:configuration_data) { '@{AllNodes = @( @{ NodeName = "localhost"; PSDscAllowPlainTextPassword = $true })}' }
38
38
  let(:configuration_data_script) { "c:/myconfigs/data/safedata.psd1" }
39
39
 
40
- it "has a default action of `:run`" do
41
- expect(dsc_test_resource.action).to eq([:run])
40
+ it "sets the default action as :run" do
41
+ expect(resource.action).to eql([:run])
42
42
  end
43
43
 
44
- it "has an allowed_actions attribute with only the `:run` and `:nothing` attributes" do
45
- expect(dsc_test_resource.allowed_actions.to_set).to eq([:run, :nothing].to_set)
44
+ it "supports :run action" do
45
+ expect { resource.action :run }.not_to raise_error
46
46
  end
47
47
 
48
48
  it "allows the code attribute to be set" do
49
- dsc_test_resource.code(configuration_code)
50
- expect(dsc_test_resource.code).to eq(configuration_code)
49
+ resource.code(configuration_code)
50
+ expect(resource.code).to eq(configuration_code)
51
51
  end
52
52
 
53
53
  it "allows the command attribute to be set" do
54
- dsc_test_resource.command(configuration_path)
55
- expect(dsc_test_resource.command).to eq(configuration_path)
54
+ resource.command(configuration_path)
55
+ expect(resource.command).to eq(configuration_path)
56
56
  end
57
57
 
58
58
  it "allows the configuration_name attribute to be set" do
59
- dsc_test_resource.configuration_name(configuration_name)
60
- expect(dsc_test_resource.configuration_name).to eq(configuration_name)
59
+ resource.configuration_name(configuration_name)
60
+ expect(resource.configuration_name).to eq(configuration_name)
61
61
  end
62
62
 
63
63
  it "allows the configuration_data attribute to be set" do
64
- dsc_test_resource.configuration_data(configuration_data)
65
- expect(dsc_test_resource.configuration_data).to eq(configuration_data)
64
+ resource.configuration_data(configuration_data)
65
+ expect(resource.configuration_data).to eq(configuration_data)
66
66
  end
67
67
 
68
68
  it "allows the configuration_data_script attribute to be set" do
69
- dsc_test_resource.configuration_data_script(configuration_data_script)
70
- expect(dsc_test_resource.configuration_data_script).to eq(configuration_data_script)
69
+ resource.configuration_data_script(configuration_data_script)
70
+ expect(resource.configuration_data_script).to eq(configuration_data_script)
71
71
  end
72
72
 
73
73
  it "has the ps_credential helper method" do
74
- expect(dsc_test_resource).to respond_to(:ps_credential)
74
+ expect(resource).to respond_to(:ps_credential)
75
75
  end
76
76
 
77
77
  context "when calling imports" do
@@ -80,55 +80,55 @@ describe Chef::Resource::DscScript do
80
80
  let(:dsc_resources) { %w{ResourceA ResourceB} }
81
81
 
82
82
  it "allows an arbitrary number of resources to be set for a module to be set" do
83
- dsc_test_resource.imports module_name, *dsc_resources
84
- module_imports = dsc_test_resource.imports[module_name]
83
+ resource.imports module_name, *dsc_resources
84
+ module_imports = resource.imports[module_name]
85
85
  expect(module_imports).to eq(dsc_resources)
86
86
  end
87
87
 
88
88
  it "adds * to the imports when no resources are set for a moudle" do
89
- dsc_test_resource.imports module_name
90
- module_imports = dsc_test_resource.imports[module_name]
89
+ resource.imports module_name
90
+ module_imports = resource.imports[module_name]
91
91
  expect(module_imports).to eq(["*"])
92
92
  end
93
93
 
94
94
  it "allows an arbitrary number of modules" do
95
- dsc_test_resource.imports module_name
96
- dsc_test_resource.imports module_name_b
97
- expect(dsc_test_resource.imports).to have_key(module_name)
98
- expect(dsc_test_resource.imports).to have_key(module_name_b)
95
+ resource.imports module_name
96
+ resource.imports module_name_b
97
+ expect(resource.imports).to have_key(module_name)
98
+ expect(resource.imports).to have_key(module_name_b)
99
99
  end
100
100
 
101
101
  it "allows resources to be added for a module" do
102
- dsc_test_resource.imports module_name, dsc_resources[0]
103
- dsc_test_resource.imports module_name, dsc_resources[1]
104
- module_imports = dsc_test_resource.imports[module_name]
102
+ resource.imports module_name, dsc_resources[0]
103
+ resource.imports module_name, dsc_resources[1]
104
+ module_imports = resource.imports[module_name]
105
105
  expect(module_imports).to eq(dsc_resources)
106
106
  end
107
107
  end
108
108
 
109
109
  it "raises an ArgumentError exception if an attempt is made to set the code attribute when the command attribute is already set" do
110
- dsc_test_resource.command(configuration_path)
111
- expect { dsc_test_resource.code(configuration_code) }.to raise_error(ArgumentError)
110
+ resource.command(configuration_path)
111
+ expect { resource.code(configuration_code) }.to raise_error(ArgumentError)
112
112
  end
113
113
 
114
114
  it "raises an ArgumentError exception if an attempt is made to set the command attribute when the code attribute is already set" do
115
- dsc_test_resource.code(configuration_code)
116
- expect { dsc_test_resource.command(configuration_path) }.to raise_error(ArgumentError)
115
+ resource.code(configuration_code)
116
+ expect { resource.command(configuration_path) }.to raise_error(ArgumentError)
117
117
  end
118
118
 
119
119
  it "raises an ArgumentError exception if an attempt is made to set the configuration_name attribute when the code attribute is already set" do
120
- dsc_test_resource.code(configuration_code)
121
- expect { dsc_test_resource.configuration_name(configuration_name) }.to raise_error(ArgumentError)
120
+ resource.code(configuration_code)
121
+ expect { resource.configuration_name(configuration_name) }.to raise_error(ArgumentError)
122
122
  end
123
123
 
124
124
  it "raises an ArgumentError exception if an attempt is made to set the configuration_data attribute when the configuration_data_script attribute is already set" do
125
- dsc_test_resource.configuration_data_script(configuration_data_script)
126
- expect { dsc_test_resource.configuration_data(configuration_data) }.to raise_error(ArgumentError)
125
+ resource.configuration_data_script(configuration_data_script)
126
+ expect { resource.configuration_data(configuration_data) }.to raise_error(ArgumentError)
127
127
  end
128
128
 
129
129
  it "raises an ArgumentError exception if an attempt is made to set the configuration_data_script attribute when the configuration_data attribute is already set" do
130
- dsc_test_resource.configuration_data(configuration_data)
131
- expect { dsc_test_resource.configuration_data_script(configuration_data_script) }.to raise_error(ArgumentError)
130
+ resource.configuration_data(configuration_data)
131
+ expect { resource.configuration_data_script(configuration_data_script) }.to raise_error(ArgumentError)
132
132
  end
133
133
  end
134
134
  end
@@ -21,15 +21,23 @@ require "spec_helper"
21
21
 
22
22
  describe Chef::Resource::Execute do
23
23
  let(:resource_instance_name) { "some command" }
24
- let(:execute_resource) { Chef::Resource::Execute.new(resource_instance_name) }
24
+ let(:resource) { Chef::Resource::Execute.new(resource_instance_name) }
25
25
  it_behaves_like "an execute resource"
26
26
 
27
+ it "sets the default action as :run" do
28
+ expect(resource.action).to eql([:run])
29
+ end
30
+
31
+ it "supports :run action" do
32
+ expect { resource.action :run }.not_to raise_error
33
+ end
34
+
27
35
  it "default guard interpreter is :execute interpreter" do
28
- expect(execute_resource.guard_interpreter).to be(:execute)
36
+ expect(resource.guard_interpreter).to be(:execute)
29
37
  end
30
38
 
31
39
  it "defaults to not being a guard interpreter" do
32
- expect(execute_resource.is_guard_interpreter).to eq(false)
40
+ expect(resource.is_guard_interpreter).to eq(false)
33
41
  end
34
42
 
35
43
  describe "#qualify_user" do
@@ -40,7 +48,7 @@ describe Chef::Resource::Execute do
40
48
  let(:username) { "user@domain" }
41
49
 
42
50
  it "correctly parses the user and domain" do
43
- identity = execute_resource.qualify_user(username, password, domain)
51
+ identity = resource.qualify_user(username, password, domain)
44
52
  expect(identity[:domain]).to eq("domain")
45
53
  expect(identity[:user]).to eq("user")
46
54
  end
@@ -50,7 +58,7 @@ describe Chef::Resource::Execute do
50
58
  let(:username) { "domain\\user" }
51
59
 
52
60
  it "correctly parses the user and domain" do
53
- identity = execute_resource.qualify_user(username, password, domain)
61
+ identity = resource.qualify_user(username, password, domain)
54
62
  expect(identity[:domain]).to eq("domain")
55
63
  expect(identity[:user]).to eq("user")
56
64
  end
@@ -60,14 +68,14 @@ describe Chef::Resource::Execute do
60
68
  shared_examples_for "it received valid credentials" do
61
69
  describe "the validation method" do
62
70
  it "does not raise an error" do
63
- expect { execute_resource.validate_identity_platform(username, password, domain) }.not_to raise_error
71
+ expect { resource.validate_identity_platform(username, password, domain) }.not_to raise_error
64
72
  end
65
73
  end
66
74
 
67
75
  describe "the name qualification method" do
68
76
  it "correctly translates the user and domain" do
69
77
  identity = nil
70
- expect { identity = execute_resource.qualify_user(username, password, domain) }.not_to raise_error
78
+ expect { identity = resource.qualify_user(username, password, domain) }.not_to raise_error
71
79
  expect(identity[:domain]).to eq(domain)
72
80
  expect(identity[:user]).to eq(username)
73
81
  end
@@ -77,7 +85,7 @@ describe Chef::Resource::Execute do
77
85
  shared_examples_for "it received invalid credentials" do
78
86
  describe "the validation method" do
79
87
  it "raises an error" do
80
- expect { execute_resource.validate_identity_platform(username, password, domain, elevated) }.to raise_error(ArgumentError)
88
+ expect { resource.validate_identity_platform(username, password, domain, elevated) }.to raise_error(ArgumentError)
81
89
  end
82
90
  end
83
91
  end
@@ -85,7 +93,7 @@ describe Chef::Resource::Execute do
85
93
  shared_examples_for "it received invalid username and domain" do
86
94
  describe "the validation method" do
87
95
  it "raises an error" do
88
- expect { execute_resource.qualify_user(username, password, domain) }.to raise_error(ArgumentError)
96
+ expect { resource.qualify_user(username, password, domain) }.to raise_error(ArgumentError)
89
97
  end
90
98
  end
91
99
  end
@@ -93,7 +101,7 @@ describe Chef::Resource::Execute do
93
101
  shared_examples_for "it received credentials that are not valid on the platform" do
94
102
  describe "the validation method" do
95
103
  it "raises an error" do
96
- expect { execute_resource.validate_identity_platform(username, password, domain) }.to raise_error(Chef::Exceptions::UnsupportedPlatform)
104
+ expect { resource.validate_identity_platform(username, password, domain) }.to raise_error(Chef::Exceptions::UnsupportedPlatform)
97
105
  end
98
106
  end
99
107
  end
@@ -101,7 +109,7 @@ describe Chef::Resource::Execute do
101
109
  shared_examples_for "a consumer of the Execute resource" do
102
110
  context "when running on Windows" do
103
111
  before do
104
- allow(execute_resource).to receive(:node).and_return({ :platform_family => "windows" })
112
+ allow(resource).to receive(:node).and_return({ :platform_family => "windows" })
105
113
  end
106
114
 
107
115
  context "when no user, domain, or password is specified" do
@@ -203,7 +211,7 @@ describe Chef::Resource::Execute do
203
211
 
204
212
  context "when not running on Windows" do
205
213
  before do
206
- allow(execute_resource).to receive(:node).and_return({ :platform_family => "ubuntu" })
214
+ allow(resource).to receive(:node).and_return({ :platform_family => "ubuntu" })
207
215
  end
208
216
 
209
217
  context "when no user, domain, or password is specified" do
@@ -22,14 +22,21 @@ describe Chef::Resource::File do
22
22
 
23
23
  let(:resource) { Chef::Resource::File.new("fakey_fakerton") }
24
24
 
25
- it "has a name property" do
26
- expect(resource.name).to eql("fakey_fakerton")
25
+ it "the path property is the name_property" do
26
+ expect(resource.path).to eql("fakey_fakerton")
27
27
  end
28
28
 
29
- it "has a default action of 'create'" do
29
+ it "sets the default action as :create" do
30
30
  expect(resource.action).to eql([:create])
31
31
  end
32
32
 
33
+ it "supports :create, :create_if_missing, :delete, :touch actions" do
34
+ expect { resource.action :create }.not_to raise_error
35
+ expect { resource.action :create_if_missing }.not_to raise_error
36
+ expect { resource.action :delete }.not_to raise_error
37
+ expect { resource.action :touch }.not_to raise_error
38
+ end
39
+
33
40
  it "has a default content of nil" do
34
41
  expect(resource.content).to be_nil
35
42
  end
@@ -57,13 +64,6 @@ describe Chef::Resource::File do
57
64
  expect { resource.checksum "monkey!" }.to raise_error(ArgumentError)
58
65
  end
59
66
 
60
- it "accepts create, delete or touch for action" do
61
- expect { resource.action :create }.not_to raise_error
62
- expect { resource.action :delete }.not_to raise_error
63
- expect { resource.action :touch }.not_to raise_error
64
- expect { resource.action :blues }.to raise_error(ArgumentError)
65
- end
66
-
67
67
  it "accepts a block, symbol, or string for verify" do
68
68
  expect { resource.verify {} }.not_to raise_error
69
69
  expect { resource.verify "" }.not_to raise_error
@@ -42,6 +42,22 @@ describe Chef::Resource::FreebsdPackage do
42
42
  end
43
43
  end
44
44
 
45
+ describe "Actions" do
46
+ it "sets the default action as :install" do
47
+ expect(resource.action).to eql([:install])
48
+ end
49
+
50
+ it "supports :install, :lock, :purge, :reconfig, :remove, :unlock, :upgrade actions" do
51
+ expect { resource.action :install }.not_to raise_error
52
+ expect { resource.action :lock }.not_to raise_error
53
+ expect { resource.action :purge }.not_to raise_error
54
+ expect { resource.action :reconfig }.not_to raise_error
55
+ expect { resource.action :remove }.not_to raise_error
56
+ expect { resource.action :unlock }.not_to raise_error
57
+ expect { resource.action :upgrade }.not_to raise_error
58
+ end
59
+ end
60
+
45
61
  describe "Assigning provider after creation" do
46
62
  describe "if ports specified as source" do
47
63
  it "is Freebsd::Port" do