chef 12.5.1 → 12.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (221) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +6 -1
  3. data/README.md +6 -4
  4. data/Rakefile +1 -4
  5. data/chef-windows.gemspec +21 -0
  6. data/chef.gemspec +58 -0
  7. data/lib/chef/api_client/registration.rb +9 -4
  8. data/lib/chef/application.rb +3 -84
  9. data/lib/chef/application/apply.rb +9 -2
  10. data/lib/chef/application/client.rb +8 -3
  11. data/lib/chef/application/solo.rb +7 -1
  12. data/lib/chef/application/windows_service.rb +21 -6
  13. data/lib/chef/application/windows_service_manager.rb +2 -3
  14. data/lib/chef/audit/runner.rb +1 -0
  15. data/lib/chef/chef_class.rb +1 -11
  16. data/lib/chef/chef_fs/chef_fs_data_store.rb +181 -2
  17. data/lib/chef/chef_fs/file_system/cookbook_subdir.rb +5 -0
  18. data/lib/chef/chef_fs/file_system/file_system_entry.rb +11 -7
  19. data/lib/chef/client.rb +28 -1
  20. data/lib/chef/cookbook/cookbook_collection.rb +14 -1
  21. data/lib/chef/cookbook/cookbook_version_loader.rb +1 -1
  22. data/lib/chef/cookbook/metadata.rb +115 -9
  23. data/lib/chef/cookbook/remote_file_vendor.rb +1 -1
  24. data/lib/chef/cookbook_version.rb +6 -2
  25. data/lib/chef/data_bag.rb +1 -1
  26. data/lib/chef/data_bag_item.rb +1 -1
  27. data/lib/chef/digester.rb +5 -1
  28. data/lib/chef/dsl/chef_provisioning.rb +57 -0
  29. data/lib/chef/dsl/cheffish.rb +64 -0
  30. data/lib/chef/dsl/declare_resource.rb +108 -0
  31. data/lib/chef/dsl/platform_introspection.rb +3 -3
  32. data/lib/chef/dsl/recipe.rb +3 -73
  33. data/lib/chef/dsl/resources.rb +27 -1
  34. data/lib/chef/event_dispatch/base.rb +3 -0
  35. data/lib/chef/event_dispatch/dispatcher.rb +5 -0
  36. data/lib/chef/event_dispatch/events_output_stream.rb +8 -0
  37. data/lib/chef/exceptions.rb +21 -1
  38. data/lib/chef/file_access_control/unix.rb +12 -12
  39. data/lib/chef/file_content_management/deploy/cp.rb +2 -2
  40. data/lib/chef/file_content_management/deploy/mv_unix.rb +4 -4
  41. data/lib/chef/file_content_management/deploy/mv_windows.rb +1 -1
  42. data/lib/chef/formatters/base.rb +7 -0
  43. data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +2 -2
  44. data/lib/chef/formatters/indentable_output_stream.rb +5 -0
  45. data/lib/chef/http.rb +19 -3
  46. data/lib/chef/http/decompressor.rb +2 -2
  47. data/lib/chef/json_compat.rb +1 -0
  48. data/lib/chef/knife.rb +16 -2
  49. data/lib/chef/knife/bootstrap.rb +55 -10
  50. data/lib/chef/knife/cookbook_site_install.rb +5 -1
  51. data/lib/chef/knife/core/bootstrap_context.rb +2 -1
  52. data/lib/chef/knife/core/node_presenter.rb +1 -1
  53. data/lib/chef/knife/ssh.rb +30 -16
  54. data/lib/chef/knife/ssl_check.rb +4 -2
  55. data/lib/chef/knife/ssl_fetch.rb +3 -2
  56. data/lib/chef/knife/status.rb +14 -1
  57. data/lib/chef/log.rb +14 -0
  58. data/lib/chef/mixin/get_source_from_package.rb +7 -2
  59. data/lib/chef/mixin/properties.rb +302 -0
  60. data/lib/chef/mixin/proxified_socket.rb +38 -0
  61. data/lib/chef/mixin/subclass_directive.rb +37 -0
  62. data/lib/chef/node.rb +13 -5
  63. data/lib/chef/platform/query_helpers.rb +14 -3
  64. data/lib/chef/platform/service_helpers.rb +20 -38
  65. data/lib/chef/policy_builder/expand_node_object.rb +3 -0
  66. data/lib/chef/policy_builder/policyfile.rb +1 -0
  67. data/lib/chef/property.rb +51 -12
  68. data/lib/chef/provider.rb +40 -35
  69. data/lib/chef/provider/deploy.rb +1 -1
  70. data/lib/chef/provider/dsc_resource.rb +54 -20
  71. data/lib/chef/provider/execute.rb +25 -4
  72. data/lib/chef/provider/group.rb +1 -1
  73. data/lib/chef/provider/lwrp_base.rb +1 -0
  74. data/lib/chef/provider/package.rb +76 -30
  75. data/lib/chef/provider/package/dpkg.rb +152 -69
  76. data/lib/chef/provider/package/openbsd.rb +6 -8
  77. data/lib/chef/provider/package/solaris.rb +2 -0
  78. data/lib/chef/provider/package/windows.rb +95 -14
  79. data/lib/chef/provider/package/windows/exe.rb +129 -0
  80. data/lib/chef/provider/package/windows/msi.rb +37 -13
  81. data/lib/chef/provider/package/windows/registry_uninstall_entry.rb +89 -0
  82. data/lib/chef/provider/package/yum.rb +13 -3
  83. data/lib/chef/provider/powershell_script.rb +3 -0
  84. data/lib/chef/provider/remote_file/cache_control_data.rb +37 -4
  85. data/lib/chef/provider/remote_file/http.rb +1 -1
  86. data/lib/chef/provider/script.rb +1 -0
  87. data/lib/chef/provider/service.rb +13 -10
  88. data/lib/chef/provider/service/solaris.rb +43 -17
  89. data/lib/chef/provider/service/upstart.rb +3 -3
  90. data/lib/chef/provider/user.rb +1 -1
  91. data/lib/chef/provider/user/dscl.rb +111 -100
  92. data/lib/chef/provider/user/windows.rb +5 -3
  93. data/lib/chef/recipe.rb +3 -5
  94. data/lib/chef/resource.rb +77 -320
  95. data/lib/chef/resource/action_class.rb +4 -0
  96. data/lib/chef/resource/dpkg_package.rb +4 -3
  97. data/lib/chef/resource/dsc_resource.rb +40 -2
  98. data/lib/chef/resource/execute.rb +9 -1
  99. data/lib/chef/resource/ksh.rb +32 -0
  100. data/lib/chef/resource/lwrp_base.rb +6 -10
  101. data/lib/chef/resource/package.rb +8 -9
  102. data/lib/chef/resource/registry_key.rb +1 -1
  103. data/lib/chef/resource/resource_notification.rb +14 -1
  104. data/lib/chef/resource/script.rb +1 -1
  105. data/lib/chef/resource/windows_package.rb +1 -1
  106. data/lib/chef/resource_builder.rb +14 -7
  107. data/lib/chef/resource_reporter.rb +6 -0
  108. data/lib/chef/resources.rb +1 -7
  109. data/lib/chef/rest.rb +1 -1
  110. data/lib/chef/run_context.rb +45 -2
  111. data/lib/chef/run_list/run_list_expansion.rb +47 -0
  112. data/lib/chef/runner.rb +25 -0
  113. data/lib/chef/search/query.rb +16 -2
  114. data/lib/chef/util/diff.rb +2 -2
  115. data/lib/chef/util/powershell/ps_credential.rb +2 -3
  116. data/lib/chef/version.rb +1 -1
  117. data/lib/chef/win32/api/file.rb +51 -1
  118. data/lib/chef/win32/file.rb +5 -0
  119. data/lib/chef/win32/file/version_info.rb +93 -0
  120. data/lib/chef/win32/mutex.rb +1 -1
  121. data/spec/data/apt/chef-integration-test2-1.0/debian/changelog +5 -0
  122. data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2.debhelper.log +45 -0
  123. data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2.substvars +1 -0
  124. data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2/DEBIAN/conffiles +1 -0
  125. data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2/DEBIAN/control +10 -0
  126. data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2/DEBIAN/md5sums +1 -0
  127. data/spec/data/apt/chef-integration-test2-1.0/debian/compat +1 -0
  128. data/spec/data/apt/chef-integration-test2-1.0/debian/conffiles +1 -0
  129. data/spec/data/apt/chef-integration-test2-1.0/debian/control +13 -0
  130. data/spec/data/apt/chef-integration-test2-1.0/debian/copyright +34 -0
  131. data/spec/data/apt/chef-integration-test2-1.0/debian/files +1 -0
  132. data/spec/data/apt/chef-integration-test2-1.0/debian/rules +13 -0
  133. data/spec/data/apt/chef-integration-test2-1.0/debian/source/format +1 -0
  134. data/spec/data/apt/chef-integration-test2_1.0-1.debian.tar.gz +0 -0
  135. data/spec/data/apt/chef-integration-test2_1.0-1.dsc +18 -0
  136. data/spec/data/apt/chef-integration-test2_1.0-1_amd64.build +91 -0
  137. data/spec/data/apt/chef-integration-test2_1.0-1_amd64.changes +31 -0
  138. data/spec/data/apt/chef-integration-test2_1.0-1_amd64.deb +0 -0
  139. data/spec/data/apt/chef-integration-test2_1.0.orig.tar.gz +0 -0
  140. data/spec/functional/application_spec.rb +1 -1
  141. data/spec/functional/audit/runner_spec.rb +4 -0
  142. data/spec/functional/knife/ssh_spec.rb +5 -5
  143. data/spec/functional/notifications_spec.rb +74 -4
  144. data/spec/functional/resource/aix_service_spec.rb +2 -2
  145. data/spec/functional/resource/dpkg_package_spec.rb +339 -0
  146. data/spec/functional/resource/ifconfig_spec.rb +3 -1
  147. data/spec/functional/resource/mount_spec.rb +5 -2
  148. data/spec/functional/resource/package_spec.rb +1 -1
  149. data/spec/functional/resource/user/windows_spec.rb +8 -0
  150. data/spec/functional/resource/windows_package_spec.rb +177 -0
  151. data/spec/functional/win32/version_info_spec.rb +50 -0
  152. data/spec/integration/client/client_spec.rb +80 -0
  153. data/spec/integration/knife/download_spec.rb +9 -0
  154. data/spec/integration/knife/upload_spec.rb +28 -1
  155. data/spec/integration/recipes/lwrp_inline_resources_spec.rb +93 -23
  156. data/spec/integration/recipes/resource_action_spec.rb +211 -116
  157. data/spec/integration/recipes/resource_converge_if_changed_spec.rb +72 -0
  158. data/spec/integration/solo/solo_spec.rb +34 -0
  159. data/spec/spec_helper.rb +11 -1
  160. data/spec/support/platform_helpers.rb +8 -0
  161. data/spec/support/shared/integration/integration_helper.rb +6 -0
  162. data/spec/support/shared/unit/execute_resource.rb +5 -0
  163. data/spec/support/shared/unit/platform_introspector.rb +7 -0
  164. data/spec/tiny_server.rb +6 -2
  165. data/spec/unit/api_client/registration_spec.rb +5 -4
  166. data/spec/unit/application_spec.rb +1 -181
  167. data/spec/unit/chef_fs/file_system/cookbook_subdir_spec.rb +34 -0
  168. data/spec/unit/cookbook/metadata_spec.rb +122 -2
  169. data/spec/unit/http_spec.rb +102 -0
  170. data/spec/unit/knife/bootstrap_spec.rb +55 -13
  171. data/spec/unit/knife/core/bootstrap_context_spec.rb +10 -3
  172. data/spec/unit/knife/ssl_check_spec.rb +7 -3
  173. data/spec/unit/knife/ssl_fetch_spec.rb +2 -2
  174. data/spec/unit/knife/status_spec.rb +13 -13
  175. data/spec/unit/knife_spec.rb +26 -2
  176. data/spec/unit/lwrp_spec.rb +1 -1
  177. data/spec/unit/mixin/properties_spec.rb +97 -0
  178. data/spec/unit/mixin/proxified_socket_spec.rb +94 -0
  179. data/spec/unit/mixin/subclass_directive_spec.rb +45 -0
  180. data/spec/unit/node_spec.rb +9 -1
  181. data/spec/unit/policy_builder/policyfile_spec.rb +2 -0
  182. data/spec/unit/property/validation_spec.rb +14 -12
  183. data/spec/unit/property_spec.rb +56 -0
  184. data/spec/unit/provider/deploy_spec.rb +1 -1
  185. data/spec/unit/provider/dsc_resource_spec.rb +63 -24
  186. data/spec/unit/provider/execute_spec.rb +95 -28
  187. data/spec/unit/provider/package/dpkg_spec.rb +185 -96
  188. data/spec/unit/provider/package/windows/exe_spec.rb +251 -0
  189. data/spec/unit/provider/package/windows/msi_spec.rb +94 -10
  190. data/spec/unit/provider/package/windows_spec.rb +227 -26
  191. data/spec/unit/provider/package/yum_spec.rb +6 -0
  192. data/spec/unit/provider/package_spec.rb +495 -366
  193. data/spec/unit/provider/remote_file/cache_control_data_spec.rb +62 -36
  194. data/spec/unit/provider/script_spec.rb +2 -2
  195. data/spec/unit/provider/service/solaris_smf_service_spec.rb +110 -39
  196. data/spec/unit/provider/service/upstart_service_spec.rb +19 -0
  197. data/spec/unit/provider/user/dscl_spec.rb +14 -0
  198. data/spec/unit/provider/user/windows_spec.rb +2 -2
  199. data/spec/unit/provider/user_spec.rb +9 -0
  200. data/spec/unit/provider_resolver_spec.rb +6 -30
  201. data/spec/unit/recipe_spec.rb +46 -20
  202. data/spec/unit/resource/chef_gem_spec.rb +1 -1
  203. data/spec/unit/resource/dsc_resource_spec.rb +14 -3
  204. data/spec/unit/resource/ksh_spec.rb +40 -0
  205. data/spec/unit/resource/registry_key_spec.rb +2 -2
  206. data/spec/unit/resource/resource_notification_spec.rb +44 -45
  207. data/spec/unit/resource_reporter_spec.rb +7 -0
  208. data/spec/unit/resource_spec.rb +268 -253
  209. data/spec/unit/rest_spec.rb +2 -2
  210. data/spec/unit/run_list/run_list_expansion_spec.rb +18 -3
  211. data/spec/unit/search/query_spec.rb +19 -1
  212. data/spec/unit/util/powershell/ps_credential_spec.rb +8 -1
  213. data/spec/unit/windows_service_spec.rb +83 -38
  214. data/tasks/external_tests.rb +19 -9
  215. data/tasks/rspec.rb +1 -1
  216. metadata +64 -15
  217. data/spec/support/pedant/Gemfile +0 -3
  218. data/spec/support/pedant/pedant_config.rb +0 -129
  219. data/spec/support/pedant/run_pedant.rb +0 -63
  220. data/spec/support/pedant/stickywicket.pem +0 -27
  221. data/spec/unit/provider/package_spec.rbe +0 -0
@@ -921,6 +921,9 @@ describe "Chef::Resource.property" do
921
921
  expect(resource.x 10).to eq "101"
922
922
  expect(Namer.current_index).to eq 1
923
923
  end
924
+ it "does not emit a deprecation warning if set to nil" do
925
+ expect(resource.x nil).to eq "1"
926
+ end
924
927
  it "coercion sets the value (and coercion does not run on get)" do
925
928
  expect(resource.x 10).to eq "101"
926
929
  expect(resource.x).to eq "101"
@@ -933,6 +936,11 @@ describe "Chef::Resource.property" do
933
936
  expect(Namer.current_index).to eq 2
934
937
  end
935
938
  end
939
+ with_property ':x, coerce: proc { |x| x }' do
940
+ it "does not emit a deprecation warning if set to nil" do
941
+ expect(resource.x nil).to be_nil
942
+ end
943
+ end
936
944
  with_property ':x, coerce: proc { |x| Namer.next_index; raise "hi" if x == 10; x }, is: proc { |x| Namer.next_index; x != 10 }' do
937
945
  it "failed coercion fails to set the value" do
938
946
  resource.x 20
@@ -1091,4 +1099,52 @@ describe "Chef::Resource.property" do
1091
1099
  expect { resource_class.property :x, :name_property => true, :name_attribute => true }.to raise_error ArgumentError,
1092
1100
  /Cannot specify both name_property and name_attribute together on property x of resource chef_resource_property_spec_(\d+)./
1093
1101
  end
1102
+
1103
+ context "with a custom property type" do
1104
+ class CustomPropertyType < Chef::Property
1105
+ end
1106
+
1107
+ with_property ":x, CustomPropertyType.new" do
1108
+ it "creates x with the given type" do
1109
+ expect(resource_class.properties[:x]).to be_kind_of(CustomPropertyType)
1110
+ end
1111
+
1112
+ context "and a subclass" do
1113
+ let(:subresource_class) do
1114
+ new_resource_name = self.class.new_resource_name
1115
+ Class.new(resource_class) do
1116
+ resource_name new_resource_name
1117
+ end
1118
+ end
1119
+ let(:subresource) do
1120
+ subresource_class.new('blah')
1121
+ end
1122
+
1123
+ context "with property :x, default: 10 on the subclass" do
1124
+ before do
1125
+ subresource_class.class_eval do
1126
+ property :x, default: 10
1127
+ end
1128
+ end
1129
+
1130
+ it "x has the given type and default on the subclass" do
1131
+ expect(subresource_class.properties[:x]).to be_kind_of(CustomPropertyType)
1132
+ expect(subresource_class.properties[:x].default).to eq(10)
1133
+ end
1134
+
1135
+ it "x does not have the default on the superclass" do
1136
+ expect(resource_class.properties[:x]).to be_kind_of(CustomPropertyType)
1137
+ expect(resource_class.properties[:x].default).to be_nil
1138
+ end
1139
+ end
1140
+ end
1141
+ end
1142
+
1143
+ with_property ":x, CustomPropertyType.new, default: 10" do
1144
+ it "passes the default to the custom property type" do
1145
+ expect(resource_class.properties[:x]).to be_kind_of(CustomPropertyType)
1146
+ expect(resource_class.properties[:x].default).to eq(10)
1147
+ end
1148
+ end
1149
+ end
1094
1150
  end
@@ -356,7 +356,7 @@ describe Chef::Provider::Deploy do
356
356
  it "chowns the whole release dir to user and group specified in the resource" do
357
357
  @resource.user "foo"
358
358
  @resource.group "bar"
359
- expect(FileUtils).to receive(:chown_R).with("foo", "bar", "/my/deploy/dir")
359
+ expect(FileUtils).to receive(:chown_R).with("foo", "bar", "/my/deploy/dir", { :force => true })
360
360
  @provider.enforce_ownership
361
361
  end
362
362
 
@@ -16,7 +16,6 @@
16
16
  # See the License for the specific language governing permissions and
17
17
  # limitations under the License.
18
18
  #
19
-
20
19
  require 'chef'
21
20
  require 'spec_helper'
22
21
 
@@ -34,7 +33,6 @@ describe Chef::Provider::DscResource do
34
33
  node.automatic[:languages][:powershell][:version] = '4.0'
35
34
  node
36
35
  }
37
-
38
36
  it 'raises a ProviderNotFound exception' do
39
37
  expect(provider).not_to receive(:meta_configuration)
40
38
  expect{provider.run_action(:run)}.to raise_error(
@@ -43,35 +41,76 @@ describe Chef::Provider::DscResource do
43
41
  end
44
42
 
45
43
  context 'when Powershell supports Invoke-DscResource' do
44
+
45
+ context 'when RefreshMode is not set to Disabled' do
46
+ context 'and the WMF 5 is a preview release' do
47
+ let (:node) {
48
+ node = Chef::Node.new
49
+ node.automatic[:languages][:powershell][:version] = '5.0.10018.0'
50
+ node
51
+ }
52
+ it 'raises an exception' do
53
+ expect(provider).to receive(:dsc_refresh_mode_disabled?).and_return(false)
54
+ expect { provider.run_action(:run) }.to raise_error(
55
+ Chef::Exceptions::ProviderNotFound, /Disabled/)
56
+ end
57
+ end
58
+ context 'and the WMF is 5 RTM or newer' do
59
+ let (:node) {
60
+ node = Chef::Node.new
61
+ node.automatic[:languages][:powershell][:version] = '5.0.10586.0'
62
+ node
63
+ }
64
+ it 'does not raises an exception' do
65
+ expect(provider).to receive(:test_resource)
66
+ expect(provider).to receive(:set_resource)
67
+ expect(provider).to receive(:reboot_if_required)
68
+ expect { provider.run_action(:run) }.to_not raise_error
69
+ end
70
+ end
71
+ end
72
+ end
73
+
74
+ context 'when the LCM supports Invoke-DscResource' do
46
75
  let (:node) {
47
76
  node = Chef::Node.new
48
77
  node.automatic[:languages][:powershell][:version] = '5.0.10018.0'
49
78
  node
50
79
  }
51
80
 
52
- context 'when RefreshMode is not set to Disabled' do
53
- it 'raises an exception' do
54
- expect(provider).to receive(:dsc_refresh_mode_disabled?).and_return(false)
55
- expect { provider.run_action(:run) }.to raise_error(
56
- Chef::Exceptions::ProviderNotFound, /Disabled/)
57
- end
81
+ it 'does not update the resource if it is up to date' do
82
+ expect(provider).to receive(:dsc_refresh_mode_disabled?).and_return(true)
83
+ expect(provider).to receive(:test_resource).and_return(true)
84
+ provider.run_action(:run)
85
+ expect(resource).not_to be_updated
58
86
  end
59
87
 
60
- context 'when RefreshMode is set to Disabled' do
61
- it 'does not update the resource if it is up to date' do
62
- expect(provider).to receive(:dsc_refresh_mode_disabled?).and_return(true)
63
- expect(provider).to receive(:test_resource).and_return(true)
64
- provider.run_action(:run)
65
- expect(resource).not_to be_updated
66
- end
67
-
68
- it 'converges the resource if it is not up to date' do
69
- expect(provider).to receive(:dsc_refresh_mode_disabled?).and_return(true)
70
- expect(provider).to receive(:test_resource).and_return(false)
71
- expect(provider).to receive(:set_resource)
72
- provider.run_action(:run)
73
- expect(resource).to be_updated
74
- end
88
+ it 'converges the resource if it is not up to date' do
89
+ expect(provider).to receive(:dsc_refresh_mode_disabled?).and_return(true)
90
+ expect(provider).to receive(:test_resource).and_return(false)
91
+ expect(provider).to receive(:set_resource)
92
+ provider.run_action(:run)
93
+ expect(resource).to be_updated
94
+ end
95
+
96
+ it 'flags the resource as reboot required when required' do
97
+ expect(provider).to receive(:dsc_refresh_mode_disabled?).and_return(true)
98
+ expect(provider).to receive(:test_resource).and_return(false)
99
+ expect(provider).to receive(:invoke_resource).
100
+ and_return(double(:stdout => '', :return_value =>nil))
101
+ expect(provider).to receive(:return_dsc_resource_result).and_return(true)
102
+ expect(provider).to receive(:create_reboot_resource)
103
+ provider.run_action(:run)
104
+ end
105
+
106
+ it 'does not flag the resource as reboot required when not required' do
107
+ expect(provider).to receive(:dsc_refresh_mode_disabled?).and_return(true)
108
+ expect(provider).to receive(:test_resource).and_return(false)
109
+ expect(provider).to receive(:invoke_resource).
110
+ and_return(double(:stdout => '', :return_value =>nil))
111
+ expect(provider).to receive(:return_dsc_resource_result).and_return(false)
112
+ expect(provider).to_not receive(:create_reboot_resource)
113
+ provider.run_action(:run)
75
114
  end
76
115
  end
77
- end
116
+ end
@@ -25,28 +25,32 @@ describe Chef::Provider::Execute do
25
25
  let(:run_context) { Chef::RunContext.new(node, {}, events) }
26
26
  let(:provider) { Chef::Provider::Execute.new(new_resource, run_context) }
27
27
  let(:current_resource) { Chef::Resource::Ifconfig.new("foo_resource", run_context) }
28
+ # You will be the same object, I promise.
29
+ @live_stream = Chef::EventDispatch::EventsOutputStream.new(run_context.events, :name => :execute)
28
30
 
29
31
  let(:opts) do
30
32
  {
31
33
  timeout: 3600,
32
34
  returns: 0,
33
35
  log_level: :info,
34
- log_tag: new_resource.to_s,
35
- live_stream: STDOUT,
36
+ log_tag: new_resource.to_s
36
37
  }
37
38
  end
38
39
 
39
40
  let(:new_resource) { Chef::Resource::Execute.new("foo_resource", run_context) }
40
41
 
41
42
  before do
43
+ allow(Chef::EventDispatch::EventsOutputStream).to receive(:new) { @live_stream }
42
44
  allow(ChefConfig).to receive(:windows?) { false }
43
45
  @original_log_level = Chef::Log.level
44
46
  Chef::Log.level = :info
45
- allow(STDOUT).to receive(:tty?).and_return(true)
47
+ allow(STDOUT).to receive(:tty?).and_return(false)
46
48
  end
47
49
 
48
50
  after do
49
51
  Chef::Log.level = @original_log_level
52
+ Chef::Config[:always_stream_execute] = false
53
+ Chef::Config[:daemon] = false
50
54
  end
51
55
 
52
56
  describe "#initialize" do
@@ -142,35 +146,98 @@ describe Chef::Provider::Execute do
142
146
  expect(new_resource).not_to be_updated
143
147
  end
144
148
 
145
- it "should unset the live_stream if STDOUT is not a tty" do
146
- expect(STDOUT).to receive(:tty?).and_return(false)
149
+ it "should not include stdout/stderr in failure exception for sensitive resource" do
147
150
  opts.delete(:live_stream)
148
- expect(provider).to receive(:shell_out!).with(new_resource.name, opts)
149
- expect(provider).to receive(:converge_by).with("execute foo_resource").and_call_original
150
- expect(Chef::Log).not_to receive(:warn)
151
- provider.run_action(:run)
152
- expect(new_resource).to be_updated
151
+ new_resource.sensitive true
152
+ expect(provider).to receive(:shell_out!).and_raise(Mixlib::ShellOut::ShellCommandFailed)
153
+ expect do
154
+ provider.run_action(:run)
155
+ end.to raise_error(Mixlib::ShellOut::ShellCommandFailed, /suppressed for sensitive resource/)
153
156
  end
154
157
 
155
- it "should unset the live_stream if chef is running as a daemon" do
156
- allow(Chef::Config).to receive(:[]).and_call_original
157
- expect(Chef::Config).to receive(:[]).with(:daemon).and_return(true)
158
- opts.delete(:live_stream)
159
- expect(provider).to receive(:shell_out!).with(new_resource.name, opts)
160
- expect(provider).to receive(:converge_by).with("execute foo_resource").and_call_original
161
- expect(Chef::Log).not_to receive(:warn)
162
- provider.run_action(:run)
163
- expect(new_resource).to be_updated
164
- end
158
+ describe "streaming output" do
159
+ it "should not set the live_stream if sensitive is on" do
160
+ new_resource.sensitive true
161
+ expect(provider).to receive(:shell_out!).with(new_resource.name, opts)
162
+ expect(provider).to receive(:converge_by).with("execute sensitive resource").and_call_original
163
+ expect(Chef::Log).not_to receive(:warn)
164
+ provider.run_action(:run)
165
+ expect(new_resource).to be_updated
166
+ end
165
167
 
166
- it "should unset the live_stream if we are not running with a log level of at least :info" do
167
- expect(Chef::Log).to receive(:info?).and_return(false)
168
- opts.delete(:live_stream)
169
- expect(provider).to receive(:shell_out!).with(new_resource.name, opts)
170
- expect(provider).to receive(:converge_by).with("execute foo_resource").and_call_original
171
- expect(Chef::Log).not_to receive(:warn)
172
- provider.run_action(:run)
173
- expect(new_resource).to be_updated
168
+ describe "with an output formatter listening" do
169
+ let(:events) { d = Chef::EventDispatch::Dispatcher.new; d.register(Chef::Formatters::Doc.new(StringIO.new, StringIO.new)); d }
170
+
171
+ before do
172
+ Chef::Config[:stream_execute_output] = true
173
+ end
174
+
175
+ it "should set the live_stream if the log level is info or above" do
176
+ nopts = opts
177
+ nopts[:live_stream] = @live_stream
178
+ expect(provider).to receive(:shell_out!).with(new_resource.name, nopts)
179
+ expect(provider).to receive(:converge_by).with("execute foo_resource").and_call_original
180
+ expect(Chef::Log).not_to receive(:warn)
181
+ provider.run_action(:run)
182
+ expect(new_resource).to be_updated
183
+ end
184
+
185
+ it "should set the live_stream if the resource requests live streaming" do
186
+ Chef::Log.level = :warn
187
+ new_resource.live_stream true
188
+ nopts = opts
189
+ nopts[:live_stream] = @live_stream
190
+ expect(provider).to receive(:shell_out!).with(new_resource.name, nopts)
191
+ expect(provider).to receive(:converge_by).with("execute foo_resource").and_call_original
192
+ expect(Chef::Log).not_to receive(:warn)
193
+ provider.run_action(:run)
194
+ expect(new_resource).to be_updated
195
+ end
196
+
197
+ it "should not set the live_stream if the resource is sensitive" do
198
+ new_resource.sensitive true
199
+ expect(provider).to receive(:shell_out!).with(new_resource.name, opts)
200
+ expect(provider).to receive(:converge_by).with("execute sensitive resource").and_call_original
201
+ expect(Chef::Log).not_to receive(:warn)
202
+ provider.run_action(:run)
203
+ expect(new_resource).to be_updated
204
+ end
205
+ end
206
+
207
+ describe "with only logging enabled" do
208
+ it "should set the live_stream to STDOUT if we are a TTY, not daemonized, not sensitive, and info is enabled" do
209
+ nopts = opts
210
+ nopts[:live_stream] = STDOUT
211
+ allow(STDOUT).to receive(:tty?).and_return(true)
212
+ expect(provider).to receive(:shell_out!).with(new_resource.name, nopts)
213
+ expect(provider).to receive(:converge_by).with("execute foo_resource").and_call_original
214
+ expect(Chef::Log).not_to receive(:warn)
215
+ provider.run_action(:run)
216
+ expect(new_resource).to be_updated
217
+ end
218
+
219
+ it "should not set the live_stream to STDOUT if we are a TTY, not daemonized, but sensitive" do
220
+ new_resource.sensitive true
221
+ allow(STDOUT).to receive(:tty?).and_return(true)
222
+ expect(provider).to receive(:shell_out!).with(new_resource.name, opts)
223
+ expect(provider).to receive(:converge_by).with("execute sensitive resource").and_call_original
224
+ expect(Chef::Log).not_to receive(:warn)
225
+ provider.run_action(:run)
226
+ expect(new_resource).to be_updated
227
+ end
228
+
229
+ it "should not set the live_stream to STDOUT if we are a TTY, but daemonized" do
230
+ Chef::Config[:daemon] = true
231
+ allow(STDOUT).to receive(:tty?).and_return(true)
232
+ expect(provider).to receive(:shell_out!).with(new_resource.name, opts)
233
+ expect(provider).to receive(:converge_by).with("execute foo_resource").and_call_original
234
+ expect(Chef::Log).not_to receive(:warn)
235
+ provider.run_action(:run)
236
+ expect(new_resource).to be_updated
237
+ end
238
+
239
+ end
174
240
  end
241
+
175
242
  end
176
243
  end
@@ -1,4 +1,3 @@
1
- #
2
1
  # Author:: Bryan McLellan (btm@loftninjas.org)
3
2
  # Copyright:: Copyright (c) 2009 Bryan McLellan
4
3
  # License:: Apache License, Version 2.0
@@ -19,42 +18,109 @@
19
18
  require 'spec_helper'
20
19
 
21
20
  describe Chef::Provider::Package::Dpkg do
21
+ let(:node) { Chef::Node.new }
22
+ let(:events) { Chef::EventDispatch::Dispatcher.new }
23
+ let(:run_context) { Chef::RunContext.new(node, {}, events) }
24
+ let(:package) { "wget" }
25
+ let(:source) { "/tmp/wget_1.11.4-1ubuntu1_amd64.deb" }
26
+ let(:new_resource) do
27
+ new_resource = Chef::Resource::DpkgPackage.new(package)
28
+ new_resource.source source
29
+ new_resource
30
+ end
31
+ let(:provider) { Chef::Provider::Package::Dpkg.new(new_resource, run_context) }
32
+
33
+ let(:dpkg_deb_version) { "1.11.4" }
34
+ let(:dpkg_deb_status) { status = double(:stdout => "#{package}\t#{dpkg_deb_version}", :exitstatus => 0) }
35
+ let(:dpkg_s_version) { "1.11.4-1ubuntu1" }
36
+ let(:dpkg_s_status) do
37
+ stdout = <<-DPKG_S
38
+ Package: #{package}
39
+ Status: install ok installed
40
+ Priority: important
41
+ Section: web
42
+ Installed-Size: 1944
43
+ Maintainer: Ubuntu Core developers <ubuntu-devel-discuss@lists.ubuntu.com>
44
+ Architecture: amd64
45
+ Version: #{dpkg_s_version}
46
+ Config-Version: #{dpkg_s_version}
47
+ Depends: libc6 (>= 2.8~20080505), libssl0.9.8 (>= 0.9.8f-5)
48
+ Conflicts: wget-ssl
49
+ DPKG_S
50
+ status = double(:stdout => stdout, :exitstatus => 1)
51
+ end
52
+
22
53
  before(:each) do
23
- @node = Chef::Node.new
24
- @events = Chef::EventDispatch::Dispatcher.new
25
- @run_context = Chef::RunContext.new(@node, {}, @events)
26
- @new_resource = Chef::Resource::Package.new("wget")
27
- @new_resource.source "/tmp/wget_1.11.4-1ubuntu1_amd64.deb"
54
+ allow(provider).to receive(:shell_out!).with("dpkg-deb -W #{source}", timeout: 900).and_return(dpkg_deb_status)
55
+ allow(provider).to receive(:shell_out!).with("dpkg -s #{package}", timeout: 900, returns: [0,1]).and_return(double(stdout: "", exitstatus: 1))
56
+ allow(::File).to receive(:exist?).with(source).and_return(true)
57
+ end
28
58
 
29
- @provider = Chef::Provider::Package::Dpkg.new(@new_resource, @run_context)
59
+ describe "#define_resource_requirements" do
60
+ it "should raise an exception if a source is supplied but not found when :install" do
61
+ allow(::File).to receive(:exist?).with(source).and_return(false)
62
+ expect { provider.run_action(:install) }.to raise_error(Chef::Exceptions::Package)
63
+ end
64
+
65
+ it "should raise an exception if a source is supplied but not found when :upgrade" do
66
+ allow(::File).to receive(:exist?).with(source).and_return(false)
67
+ expect { provider.run_action(:upgrade) }.to raise_error(Chef::Exceptions::Package)
68
+ end
30
69
 
31
- @status = double(:stdout => "", :exitstatus => 0)
32
- allow(@provider).to receive(:shell_out).and_return(@status)
70
+ # FIXME? we're saying we ignore source, but should supplying source on :remove or :purge be an actual error?
71
+ it "should not raise an exception if a source is supplied but not found when :remove" do
72
+ allow(::File).to receive(:exist?).with(source).and_return(false)
73
+ expect(provider).to receive(:action_remove)
74
+ expect { provider.run_action(:remove) }.not_to raise_error
75
+ end
33
76
 
34
- allow(::File).to receive(:exists?).and_return(true)
77
+ it "should not raise an exception if a source is supplied but not found when :purge" do
78
+ allow(::File).to receive(:exist?).with(source).and_return(false)
79
+ expect(provider).to receive(:action_purge)
80
+ expect { provider.run_action(:purge) }.not_to raise_error
81
+ end
82
+
83
+ it "should raise an exception if a source is nil when :install" do
84
+ new_resource.source nil
85
+ allow(::File).to receive(:exist?).with(source).and_return(false)
86
+ expect { provider.run_action(:install) }.to raise_error(Chef::Exceptions::Package)
87
+ end
88
+
89
+ it "should raise an exception if a source is nil when :upgrade" do
90
+ new_resource.source nil
91
+ allow(::File).to receive(:exist?).with(source).and_return(false)
92
+ expect { provider.run_action(:upgrade) }.to raise_error(Chef::Exceptions::Package)
93
+ end
94
+
95
+ it "should not raise an exception if a source is nil when :remove" do
96
+ new_resource.source nil
97
+ allow(::File).to receive(:exist?).with(source).and_return(false)
98
+ expect(provider).to receive(:action_remove)
99
+ expect { provider.run_action(:remove) }.not_to raise_error
100
+ end
101
+
102
+ it "should not raise an exception if a source is nil when :purge" do
103
+ new_resource.source nil
104
+ allow(::File).to receive(:exist?).with(source).and_return(false)
105
+ expect(provider).to receive(:action_purge)
106
+ expect { provider.run_action(:purge) }.not_to raise_error
107
+ end
35
108
  end
36
109
 
37
110
  describe "when loading the current resource state" do
38
111
 
39
112
  it "should create a current resource with the name of the new_resource" do
40
- @provider.load_current_resource
41
- expect(@provider.current_resource.package_name).to eq("wget")
42
- end
43
-
44
- it "should raise an exception if a source is supplied but not found" do
45
- @provider.load_current_resource
46
- @provider.define_resource_requirements
47
- allow(::File).to receive(:exists?).and_return(false)
48
- expect { @provider.run_action(:install) }.to raise_error(Chef::Exceptions::Package)
113
+ provider.load_current_resource
114
+ expect(provider.current_resource.package_name).to eq(["wget"])
49
115
  end
50
116
 
51
117
  describe 'gets the source package version from dpkg-deb' do
52
118
  def check_version(version)
53
- @status = double(:stdout => "wget\t#{version}", :exitstatus => 0)
54
- allow(@provider).to receive(:shell_out).with("dpkg-deb -W #{@new_resource.source}", timeout: 900).and_return(@status)
55
- @provider.load_current_resource
56
- expect(@provider.current_resource.package_name).to eq("wget")
57
- expect(@provider.candidate_version).to eq(version)
119
+ status = double(:stdout => "wget\t#{version}", :exitstatus => 0)
120
+ expect(provider).to receive(:shell_out!).with("dpkg-deb -W #{source}", timeout: 900).and_return(status)
121
+ provider.load_current_resource
122
+ expect(provider.current_resource.package_name).to eq(["wget"])
123
+ expect(provider.candidate_version).to eq([version])
58
124
  end
59
125
 
60
126
  it 'if short version provided' do
@@ -74,129 +140,152 @@ describe Chef::Provider::Package::Dpkg do
74
140
  end
75
141
  end
76
142
 
77
- it "gets the source package name from dpkg-deb correctly when the package name has `-', `+' or `.' characters" do
78
- stdout = "f.o.o-pkg++2\t1.11.4-1ubuntu1"
79
- status = double(:stdout => stdout, :exitstatus => 1)
80
- allow(@provider).to receive(:shell_out).and_return(status)
81
- @provider.load_current_resource
82
- expect(@provider.current_resource.package_name).to eq("f.o.o-pkg++2")
143
+ describe "when the package name has `-', `+' or `.' characters" do
144
+ let(:package) { "f.o.o-pkg++2" }
145
+
146
+ it "gets the source package name from dpkg-deb correctly" do
147
+ provider.load_current_resource
148
+ expect(provider.current_resource.package_name).to eq(["f.o.o-pkg++2"])
149
+ end
83
150
  end
84
151
 
85
- it "gets the source package version from dpkg-deb correctly when the package version has `~', `-', `+' or `.' characters" do
86
- stdout = "b.a.r-pkg++1\t1.2.3+3141592-1ubuntu1~lucid"
87
- status = double(:stdout => stdout, :exitstatus => 1)
88
- allow(@provider).to receive(:shell_out).and_return(status)
89
- @provider.load_current_resource
90
- expect(@provider.candidate_version).to eq('1.2.3+3141592-1ubuntu1~lucid')
152
+ describe "when the package version has `~', `-', `+' or `.' characters" do
153
+ let(:package) { "b.a.r-pkg++1" }
154
+ let(:dpkg_deb_version) { "1.2.3+3141592-1ubuntu1~lucid" }
155
+ let(:dpkg_s_version) { "1.2.3+3141592-1ubuntu1~lucid" }
156
+
157
+ it "gets the source package version from dpkg-deb correctly when the package version has `~', `-', `+' or `.' characters" do
158
+ provider.load_current_resource
159
+ expect(provider.candidate_version).to eq(['1.2.3+3141592-1ubuntu1~lucid'])
160
+ end
91
161
  end
92
162
 
93
- it "should raise an exception if the source is not set but we are installing" do
94
- @new_resource = Chef::Resource::Package.new("wget")
95
- @provider.new_resource = @new_resource
96
- @provider.load_current_resource
97
- @provider.define_resource_requirements
98
- expect { @provider.run_action(:install)}.to raise_error(Chef::Exceptions::Package)
163
+ describe "when the source is not set" do
164
+ let(:source) { nil }
165
+
166
+ it "should raise an exception if the source is not set but we are installing" do
167
+ expect { provider.run_action(:install)}.to raise_error(Chef::Exceptions::Package)
168
+ end
99
169
  end
100
170
 
101
171
  it "should return the current version installed if found by dpkg" do
102
- stdout = <<-DPKG_S
103
- Package: wget
104
- Status: install ok installed
105
- Priority: important
106
- Section: web
107
- Installed-Size: 1944
108
- Maintainer: Ubuntu Core developers <ubuntu-devel-discuss@lists.ubuntu.com>
109
- Architecture: amd64
110
- Version: 1.11.4-1ubuntu1
111
- Config-Version: 1.11.4-1ubuntu1
112
- Depends: libc6 (>= 2.8~20080505), libssl0.9.8 (>= 0.9.8f-5)
113
- Conflicts: wget-ssl
114
- DPKG_S
115
- status = double(:stdout => stdout, :exitstatus => 1)
116
- allow(@provider).to receive(:shell_out).with("dpkg -s wget", timeout: 900).and_return(status)
172
+ allow(provider).to receive(:shell_out!).with("dpkg -s #{package}", timeout: 900, returns: [0,1]).and_return(dpkg_s_status)
173
+ provider.load_current_resource
174
+ expect(provider.current_resource.version).to eq(["1.11.4-1ubuntu1"])
175
+ end
117
176
 
118
- @provider.load_current_resource
119
- expect(@provider.current_resource.version).to eq("1.11.4-1ubuntu1")
177
+ it "on new debian/ubuntu we get an exit(1) and no stdout from dpkg -s for uninstalled" do
178
+ dpkg_s_status = double(
179
+ exitstatus: 1, stdout: "", stderr: <<-EOF
180
+ dpkg-query: package '#{package}' is not installed and no information is available
181
+ Use dpkg --info (= dpkg-deb --info) to examine archive files,
182
+ and dpkg --contents (= dpkg-deb --contents) to list their contents.
183
+ EOF
184
+ )
185
+ expect(provider).to receive(:shell_out!).with("dpkg -s #{package}", returns: [0, 1], timeout: 900).and_return(dpkg_s_status)
186
+ provider.load_current_resource
187
+ expect(provider.current_resource.version).to eq([nil])
120
188
  end
121
189
 
122
- it "should raise an exception if dpkg fails to run" do
190
+ it "on old debian/ubuntu we get an exit(0) and we get info on stdout from dpkg -s for uninstalled" do
191
+ dpkg_s_status = double(
192
+ exitstatus: 0, stderr: "", stdout: <<-EOF
193
+ Package: #{package}
194
+ Status: unknown ok not-installed
195
+ Priority: extra
196
+ Section: ruby
197
+ EOF
198
+ )
199
+ expect(provider).to receive(:shell_out!).with("dpkg -s #{package}", returns: [0, 1], timeout: 900).and_return(dpkg_s_status)
200
+ provider.load_current_resource
201
+ expect(provider.current_resource.version).to eq([nil])
202
+ end
203
+
204
+ it "and we should raise if we get any other exit codes from dpkg -s" do
205
+ dpkg_s_status = double(
206
+ exitstatus: 3, stderr: "i am very, very angry with you. i'm very, very cross. go to your room.", stdout: ""
207
+ )
208
+ expect(provider).to receive(:shell_out!).with("dpkg -s #{package}", returns: [0, 1], timeout: 900).and_raise(Mixlib::ShellOut::ShellCommandFailed)
209
+ expect { provider.load_current_resource }.to raise_error(Mixlib::ShellOut::ShellCommandFailed)
210
+ end
211
+
212
+ it "should raise an exception if dpkg-deb -W fails to run" do
123
213
  status = double(:stdout => "", :exitstatus => -1)
124
- allow(@provider).to receive(:shell_out).and_return(status)
125
- expect { @provider.load_current_resource }.to raise_error(Chef::Exceptions::Package)
214
+ expect(provider).to receive(:shell_out_with_timeout!).with("dpkg-deb -W /tmp/wget_1.11.4-1ubuntu1_amd64.deb").and_raise(Mixlib::ShellOut::ShellCommandFailed)
215
+ expect { provider.load_current_resource }.to raise_error(Mixlib::ShellOut::ShellCommandFailed)
126
216
  end
127
217
  end
128
218
 
129
219
  describe Chef::Provider::Package::Dpkg, "install and upgrade" do
130
220
  it "should run dpkg -i with the package source" do
131
- expect(@provider).to receive(:run_noninteractive).with(
132
- "dpkg -i /tmp/wget_1.11.4-1ubuntu1_amd64.deb"
221
+ expect(provider).to receive(:run_noninteractive).with(
222
+ "dpkg -i", nil, "/tmp/wget_1.11.4-1ubuntu1_amd64.deb"
133
223
  )
134
- @provider.install_package("wget", "1.11.4-1ubuntu1")
224
+ provider.load_current_resource
225
+ provider.run_action(:install)
135
226
  end
136
227
 
137
228
  it "should run dpkg -i if the package is a path and the source is nil" do
138
- @new_resource = Chef::Resource::Package.new("/tmp/wget_1.11.4-1ubuntu1_amd64.deb")
139
- @provider = Chef::Provider::Package::Dpkg.new(@new_resource, @run_context)
140
- expect(@provider).to receive(:run_noninteractive).with(
141
- "dpkg -i /tmp/wget_1.11.4-1ubuntu1_amd64.deb"
229
+ new_resource.name "/tmp/wget_1.11.4-1ubuntu1_amd64.deb"
230
+ expect(provider).to receive(:run_noninteractive).with(
231
+ "dpkg -i", nil, "/tmp/wget_1.11.4-1ubuntu1_amd64.deb"
142
232
  )
143
- @provider.install_package("/tmp/wget_1.11.4-1ubuntu1_amd64.deb", "1.11.4-1ubuntu1")
233
+ provider.run_action(:install)
144
234
  end
145
235
 
146
236
  it "should run dpkg -i if the package is a path and the source is nil for an upgrade" do
147
- @new_resource = Chef::Resource::Package.new("/tmp/wget_1.11.4-1ubuntu1_amd64.deb")
148
- @provider = Chef::Provider::Package::Dpkg.new(@new_resource, @run_context)
149
- expect(@provider).to receive(:run_noninteractive).with(
150
- "dpkg -i /tmp/wget_1.11.4-1ubuntu1_amd64.deb"
237
+ new_resource.name "/tmp/wget_1.11.4-1ubuntu1_amd64.deb"
238
+ expect(provider).to receive(:run_noninteractive).with(
239
+ "dpkg -i", nil, "/tmp/wget_1.11.4-1ubuntu1_amd64.deb"
151
240
  )
152
- @provider.upgrade_package("/tmp/wget_1.11.4-1ubuntu1_amd64.deb", "1.11.4-1ubuntu1")
241
+ provider.run_action(:upgrade)
153
242
  end
154
243
 
155
244
  it "should run dpkg -i with the package source and options if specified" do
156
- expect(@provider).to receive(:run_noninteractive).with(
157
- "dpkg -i --force-yes /tmp/wget_1.11.4-1ubuntu1_amd64.deb"
245
+ new_resource.options "--force-yes"
246
+ expect(provider).to receive(:run_noninteractive).with(
247
+ "dpkg -i", "--force-yes", "/tmp/wget_1.11.4-1ubuntu1_amd64.deb"
158
248
  )
159
- allow(@new_resource).to receive(:options).and_return("--force-yes")
160
-
161
- @provider.install_package("wget", "1.11.4-1ubuntu1")
249
+ provider.run_action(:install)
162
250
  end
251
+
163
252
  it "should upgrade by running install_package" do
164
- expect(@provider).to receive(:install_package).with("wget", "1.11.4-1ubuntu1")
165
- @provider.upgrade_package("wget", "1.11.4-1ubuntu1")
253
+ expect(provider).to receive(:install_package).with(["wget"], ["1.11.4-1ubuntu1"])
254
+ provider.upgrade_package(["wget"], ["1.11.4-1ubuntu1"])
166
255
  end
167
256
  end
168
257
 
169
258
  describe Chef::Provider::Package::Dpkg, "remove and purge" do
170
259
  it "should run dpkg -r to remove the package" do
171
- expect(@provider).to receive(:run_noninteractive).with(
172
- "dpkg -r wget"
260
+ expect(provider).to receive(:run_noninteractive).with(
261
+ "dpkg -r", nil, "wget"
173
262
  )
174
- @provider.remove_package("wget", "1.11.4-1ubuntu1")
263
+ provider.remove_package(["wget"], ["1.11.4-1ubuntu1"])
175
264
  end
176
265
 
177
266
  it "should run dpkg -r to remove the package with options if specified" do
178
- expect(@provider).to receive(:run_noninteractive).with(
179
- "dpkg -r --force-yes wget"
267
+ expect(provider).to receive(:run_noninteractive).with(
268
+ "dpkg -r", "--force-yes", "wget"
180
269
  )
181
- allow(@new_resource).to receive(:options).and_return("--force-yes")
270
+ allow(new_resource).to receive(:options).and_return("--force-yes")
182
271
 
183
- @provider.remove_package("wget", "1.11.4-1ubuntu1")
272
+ provider.remove_package(["wget"], ["1.11.4-1ubuntu1"])
184
273
  end
185
274
 
186
275
  it "should run dpkg -P to purge the package" do
187
- expect(@provider).to receive(:run_noninteractive).with(
188
- "dpkg -P wget"
276
+ expect(provider).to receive(:run_noninteractive).with(
277
+ "dpkg -P", nil, "wget"
189
278
  )
190
- @provider.purge_package("wget", "1.11.4-1ubuntu1")
279
+ provider.purge_package(["wget"], ["1.11.4-1ubuntu1"])
191
280
  end
192
281
 
193
282
  it "should run dpkg -P to purge the package with options if specified" do
194
- expect(@provider).to receive(:run_noninteractive).with(
195
- "dpkg -P --force-yes wget"
283
+ expect(provider).to receive(:run_noninteractive).with(
284
+ "dpkg -P", "--force-yes", "wget"
196
285
  )
197
- allow(@new_resource).to receive(:options).and_return("--force-yes")
286
+ allow(new_resource).to receive(:options).and_return("--force-yes")
198
287
 
199
- @provider.purge_package("wget", "1.11.4-1ubuntu1")
288
+ provider.purge_package(["wget"], ["1.11.4-1ubuntu1"])
200
289
  end
201
290
  end
202
291
  end