chef 13.6.4 → 13.7.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (257) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/acceptance/Gemfile +2 -2
  4. data/acceptance/top-cookbooks/.acceptance/acceptance-cookbook/libraries/top_cookbooks.rb +1 -6
  5. data/distro/powershell/chef/chef.psm1 +1 -5
  6. data/lib/chef/api_client.rb +5 -5
  7. data/lib/chef/api_client_v1.rb +6 -6
  8. data/lib/chef/application.rb +3 -2
  9. data/lib/chef/application/knife.rb +4 -0
  10. data/lib/chef/chef_class.rb +2 -2
  11. data/lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb +1 -1
  12. data/lib/chef/chef_fs/data_handler/data_handler_base.rb +2 -4
  13. data/lib/chef/client.rb +3 -3
  14. data/lib/chef/cookbook/chefignore.rb +4 -0
  15. data/lib/chef/cookbook/cookbook_collection.rb +2 -2
  16. data/lib/chef/cookbook/metadata.rb +2 -2
  17. data/lib/chef/data_bag.rb +1 -1
  18. data/lib/chef/deprecated.rb +10 -0
  19. data/lib/chef/event_dispatch/base.rb +2 -2
  20. data/lib/chef/http.rb +10 -10
  21. data/lib/chef/knife.rb +16 -15
  22. data/lib/chef/knife/configure.rb +12 -36
  23. data/lib/chef/knife/cookbook_upload.rb +4 -4
  24. data/lib/chef/knife/core/bootstrap_context.rb +1 -1
  25. data/lib/chef/knife/core/status_presenter.rb +6 -2
  26. data/lib/chef/knife/core/ui.rb +1 -1
  27. data/lib/chef/knife/data_bag_secret_options.rb +1 -1
  28. data/lib/chef/knife/data_bag_show.rb +1 -1
  29. data/lib/chef/knife/edit.rb +1 -1
  30. data/lib/chef/knife/ssh.rb +47 -35
  31. data/lib/chef/knife/user_create.rb +2 -0
  32. data/lib/chef/knife/user_delete.rb +2 -0
  33. data/lib/chef/knife/user_edit.rb +2 -0
  34. data/lib/chef/knife/user_reregister.rb +2 -0
  35. data/lib/chef/knife/user_show.rb +2 -0
  36. data/lib/chef/mixin/powershell_out.rb +1 -1
  37. data/lib/chef/node/attribute.rb +46 -70
  38. data/lib/chef/node/attribute_collections.rb +5 -5
  39. data/lib/chef/node/common_api.rb +1 -1
  40. data/lib/chef/node/immutable_collections.rb +180 -23
  41. data/lib/chef/node/mixin/state_tracking.rb +6 -6
  42. data/lib/chef/node_map.rb +63 -45
  43. data/lib/chef/property.rb +8 -8
  44. data/lib/chef/provider.rb +9 -3
  45. data/lib/chef/provider/apt_preference.rb +1 -1
  46. data/lib/chef/provider/apt_repository.rb +1 -1
  47. data/lib/chef/provider/apt_update.rb +1 -1
  48. data/lib/chef/provider/file.rb +1 -1
  49. data/lib/chef/provider/group/dscl.rb +6 -2
  50. data/lib/chef/provider/ifconfig.rb +96 -34
  51. data/lib/chef/provider/launchd.rb +0 -1
  52. data/lib/chef/provider/log.rb +3 -13
  53. data/lib/chef/provider/package/dnf.rb +1 -1
  54. data/lib/chef/provider/package/smartos.rb +2 -2
  55. data/lib/chef/provider/reboot.rb +12 -0
  56. data/lib/chef/provider/remote_directory.rb +1 -1
  57. data/lib/chef/provider/remote_file/http.rb +3 -2
  58. data/lib/chef/provider/service/solaris.rb +6 -2
  59. data/lib/chef/provider/systemd_unit.rb +34 -33
  60. data/lib/chef/provider/user/dscl.rb +1 -1
  61. data/lib/chef/provider/windows_path.rb +6 -7
  62. data/lib/chef/provider/windows_task.rb +89 -33
  63. data/lib/chef/provider/yum_repository.rb +24 -9
  64. data/lib/chef/resource/apt_package.rb +1 -0
  65. data/lib/chef/resource/apt_preference.rb +4 -0
  66. data/lib/chef/resource/apt_repository.rb +4 -0
  67. data/lib/chef/resource/apt_update.rb +3 -0
  68. data/lib/chef/resource/bash.rb +4 -0
  69. data/lib/chef/resource/batch.rb +5 -0
  70. data/lib/chef/resource/bff_package.rb +4 -0
  71. data/lib/chef/resource/breakpoint.rb +6 -0
  72. data/lib/chef/resource/cab_package.rb +6 -6
  73. data/lib/chef/resource/chef_gem.rb +13 -0
  74. data/lib/chef/resource/chocolatey_package.rb +4 -6
  75. data/lib/chef/resource/cookbook_file.rb +13 -15
  76. data/lib/chef/resource/cron.rb +2 -0
  77. data/lib/chef/resource/csh.rb +4 -0
  78. data/lib/chef/resource/directory.rb +8 -26
  79. data/lib/chef/resource/dnf_package.rb +5 -0
  80. data/lib/chef/resource/dpkg_package.rb +2 -0
  81. data/lib/chef/resource/dsc_resource.rb +5 -0
  82. data/lib/chef/resource/dsc_script.rb +6 -0
  83. data/lib/chef/resource/env.rb +3 -0
  84. data/lib/chef/resource/erl_call.rb +5 -0
  85. data/lib/chef/resource/execute.rb +5 -1
  86. data/lib/chef/resource/file.rb +2 -1
  87. data/lib/chef/resource/file/verification.rb +10 -0
  88. data/lib/chef/resource/freebsd_package.rb +10 -2
  89. data/lib/chef/resource/gem_package.rb +2 -0
  90. data/lib/chef/resource/git.rb +2 -0
  91. data/lib/chef/resource/group.rb +1 -0
  92. data/lib/chef/resource/homebrew_package.rb +3 -0
  93. data/lib/chef/resource/http_request.rb +2 -0
  94. data/lib/chef/resource/ifconfig.rb +23 -150
  95. data/lib/chef/resource/ips_package.rb +1 -0
  96. data/lib/chef/resource/ksh.rb +6 -0
  97. data/lib/chef/resource/launchd.rb +5 -4
  98. data/lib/chef/resource/link.rb +10 -0
  99. data/lib/chef/resource/log.rb +19 -46
  100. data/lib/chef/resource/macports_package.rb +1 -0
  101. data/lib/chef/resource/mdadm.rb +4 -0
  102. data/lib/chef/resource/mount.rb +1 -0
  103. data/lib/chef/resource/msu_package.rb +7 -8
  104. data/lib/chef/resource/ohai.rb +2 -0
  105. data/lib/chef/resource/openbsd_package.rb +3 -0
  106. data/lib/chef/resource/osx_profile.rb +10 -40
  107. data/lib/chef/resource/package.rb +6 -0
  108. data/lib/chef/resource/pacman_package.rb +1 -0
  109. data/lib/chef/resource/paludis_package.rb +3 -0
  110. data/lib/chef/resource/perl.rb +4 -0
  111. data/lib/chef/resource/portage_package.rb +1 -0
  112. data/lib/chef/resource/powershell_package.rb +5 -0
  113. data/lib/chef/resource/powershell_script.rb +8 -0
  114. data/lib/chef/resource/python.rb +4 -0
  115. data/lib/chef/resource/reboot.rb +14 -20
  116. data/lib/chef/resource/registry_key.rb +1 -0
  117. data/lib/chef/resource/remote_directory.rb +3 -0
  118. data/lib/chef/resource/remote_file.rb +2 -0
  119. data/lib/chef/resource/resource_notification.rb +17 -0
  120. data/lib/chef/resource/route.rb +1 -0
  121. data/lib/chef/resource/rpm_package.rb +1 -0
  122. data/lib/chef/resource/ruby.rb +4 -0
  123. data/lib/chef/resource/ruby_block.rb +3 -0
  124. data/lib/chef/resource/script.rb +4 -0
  125. data/lib/chef/resource/service.rb +1 -0
  126. data/lib/chef/resource/smartos_package.rb +1 -0
  127. data/lib/chef/resource/solaris_package.rb +1 -0
  128. data/lib/chef/resource/subversion.rb +1 -0
  129. data/lib/chef/resource/systemd_unit.rb +6 -0
  130. data/lib/chef/resource/template.rb +9 -0
  131. data/lib/chef/resource/user.rb +1 -0
  132. data/lib/chef/resource/windows_package.rb +2 -0
  133. data/lib/chef/resource/windows_path.rb +5 -10
  134. data/lib/chef/resource/windows_service.rb +3 -0
  135. data/lib/chef/resource/windows_task.rb +66 -87
  136. data/lib/chef/resource/yum_repository.rb +26 -22
  137. data/lib/chef/resource/zypper_package.rb +2 -0
  138. data/lib/chef/resource/zypper_repository.rb +6 -1
  139. data/lib/chef/run_context.rb +8 -2
  140. data/lib/chef/server_api.rb +1 -0
  141. data/lib/chef/util/selinux.rb +5 -4
  142. data/lib/chef/version.rb +1 -1
  143. data/lib/chef/version/platform.rb +18 -0
  144. data/lib/chef/version_constraint/platform.rb +2 -0
  145. data/spec/data/client.d_00/02-strings.rb +2 -0
  146. data/spec/functional/assets/chefinittest +6 -4
  147. data/spec/functional/knife/ssh_spec.rb +54 -7
  148. data/spec/functional/resource/bff_spec.rb +3 -3
  149. data/spec/functional/resource/ifconfig_spec.rb +1 -1
  150. data/spec/functional/resource/mount_spec.rb +7 -3
  151. data/spec/functional/resource/user/useradd_spec.rb +4 -4
  152. data/spec/functional/resource/windows_task_spec.rb +6 -6
  153. data/spec/functional/win32/security_spec.rb +7 -33
  154. data/spec/integration/knife/data_bag_show_spec.rb +1 -1
  155. data/spec/integration/recipes/noop_resource_spec.rb +1 -1
  156. data/spec/integration/recipes/recipe_dsl_spec.rb +30 -30
  157. data/spec/integration/recipes/resource_action_spec.rb +2 -2
  158. data/spec/integration/recipes/resource_converge_if_changed_spec.rb +71 -15
  159. data/spec/spec_helper.rb +19 -0
  160. data/spec/support/shared/functional/execute_resource.rb +1 -1
  161. data/spec/support/shared/unit/application_dot_d.rb +2 -0
  162. data/spec/support/shared/unit/execute_resource.rb +8 -1
  163. data/spec/support/shared/unit/provider/file.rb +9 -1
  164. data/spec/unit/chef_fs/data_handler/data_bag_item_data_handler.rb +10 -7
  165. data/spec/unit/chef_fs/file_system/repository/directory_spec.rb +2 -2
  166. data/spec/unit/client_spec.rb +1 -1
  167. data/spec/unit/deprecated_spec.rb +4 -4
  168. data/spec/unit/http_spec.rb +9 -0
  169. data/spec/unit/knife/bootstrap_spec.rb +5 -0
  170. data/spec/unit/knife/configure_spec.rb +10 -60
  171. data/spec/unit/knife/data_bag_create_spec.rb +40 -2
  172. data/spec/unit/knife/data_bag_show_spec.rb +16 -2
  173. data/spec/unit/knife/ssh_spec.rb +85 -39
  174. data/spec/unit/knife_spec.rb +2 -0
  175. data/spec/unit/lwrp_spec.rb +5 -3
  176. data/spec/unit/mixin/powershell_type_coercions_spec.rb +7 -6
  177. data/spec/unit/node/attribute_spec.rb +55 -24
  178. data/spec/unit/node/immutable_collections_spec.rb +28 -14
  179. data/spec/unit/node/vivid_mash_spec.rb +27 -10
  180. data/spec/unit/node_map_spec.rb +34 -0
  181. data/spec/unit/property_spec.rb +13 -13
  182. data/spec/unit/provider/group/dscl_spec.rb +14 -5
  183. data/spec/unit/provider/ifconfig_spec.rb +10 -3
  184. data/spec/unit/provider/remote_file/http_spec.rb +23 -19
  185. data/spec/unit/provider/service/solaris_smf_service_spec.rb +6 -5
  186. data/spec/unit/provider/user/dscl_spec.rb +26 -0
  187. data/spec/unit/provider/windows_task_spec.rb +148 -4
  188. data/spec/unit/provider_spec.rb +1 -1
  189. data/spec/unit/resource/apt_package_spec.rb +1 -1
  190. data/spec/unit/resource/bash_spec.rb +8 -10
  191. data/spec/unit/resource/batch_spec.rb +1 -1
  192. data/spec/unit/resource/cab_package_spec.rb +19 -1
  193. data/spec/unit/resource/chef_gem_spec.rb +3 -3
  194. data/spec/unit/resource/chocolatey_package_spec.rb +10 -10
  195. data/spec/unit/resource/conditional_spec.rb +2 -2
  196. data/spec/unit/resource/cookbook_file_spec.rb +24 -30
  197. data/spec/unit/resource/cron_spec.rb +79 -82
  198. data/spec/unit/resource/csh_spec.rb +8 -10
  199. data/spec/unit/resource/deploy_spec.rb +1 -1
  200. data/spec/unit/resource/directory_spec.rb +28 -31
  201. data/spec/unit/resource/dnf_package_spec.rb +9 -9
  202. data/spec/unit/resource/env_spec.rb +7 -7
  203. data/spec/unit/resource/erl_call_spec.rb +9 -9
  204. data/spec/unit/resource/execute_spec.rb +6 -6
  205. data/spec/unit/resource/file/verification_spec.rb +18 -4
  206. data/spec/unit/resource/file_spec.rb +53 -56
  207. data/spec/unit/resource/freebsd_package_spec.rb +7 -7
  208. data/spec/unit/resource/gem_package_spec.rb +1 -1
  209. data/spec/unit/resource/git_spec.rb +7 -9
  210. data/spec/unit/resource/group_spec.rb +60 -70
  211. data/spec/unit/resource/http_request_spec.rb +16 -19
  212. data/spec/unit/resource/ifconfig_spec.rb +3 -3
  213. data/spec/unit/resource/ips_package_spec.rb +3 -5
  214. data/spec/unit/resource/ksh_spec.rb +8 -10
  215. data/spec/unit/resource/launchd_spec.rb +17 -10
  216. data/spec/unit/resource/link_spec.rb +53 -53
  217. data/spec/unit/resource/log_spec.rb +24 -28
  218. data/spec/unit/resource/mdadm_spec.rb +42 -44
  219. data/spec/unit/resource/mount_spec.rb +97 -99
  220. data/spec/unit/resource/msu_package_spec.rb +14 -8
  221. data/spec/unit/resource/ohai_spec.rb +15 -17
  222. data/spec/unit/resource/openbsd_package_spec.rb +3 -3
  223. data/spec/unit/resource/osx_profile_spec.rb +7 -7
  224. data/spec/unit/resource/package_spec.rb +36 -40
  225. data/spec/unit/resource/perl_spec.rb +8 -11
  226. data/spec/unit/resource/portage_package_spec.rb +8 -10
  227. data/spec/unit/resource/powershell_package_spec.rb +9 -9
  228. data/spec/unit/resource/python_spec.rb +8 -11
  229. data/spec/unit/resource/reboot_spec.rb +50 -0
  230. data/spec/unit/resource/registry_key_spec.rb +84 -98
  231. data/spec/unit/resource/remote_directory_spec.rb +40 -42
  232. data/spec/unit/resource/remote_file_spec.rb +78 -80
  233. data/spec/unit/resource/route_spec.rb +42 -44
  234. data/spec/unit/resource/rpm_package_spec.rb +5 -7
  235. data/spec/unit/resource/ruby_block_spec.rb +14 -16
  236. data/spec/unit/resource/ruby_spec.rb +8 -12
  237. data/spec/unit/resource/scm_spec.rb +66 -69
  238. data/spec/unit/resource/script_spec.rb +1 -1
  239. data/spec/unit/resource/service_spec.rb +80 -83
  240. data/spec/unit/resource/smartos_package_spec.rb +5 -0
  241. data/spec/unit/resource/solaris_package_spec.rb +3 -5
  242. data/spec/unit/resource/subversion_spec.rb +18 -16
  243. data/spec/unit/resource/systemd_unit_spec.rb +50 -54
  244. data/spec/unit/resource/template_spec.rb +56 -61
  245. data/spec/unit/resource/user_spec.rb +47 -53
  246. data/spec/unit/resource/windows_package_spec.rb +1 -1
  247. data/spec/unit/resource/windows_path_spec.rb +11 -8
  248. data/spec/unit/resource/windows_task_spec.rb +129 -33
  249. data/spec/unit/resource/yum_package_spec.rb +1 -1
  250. data/spec/unit/resource/yum_repository_spec.rb +61 -8
  251. data/spec/unit/resource/zypper_repository_spec.rb +17 -18
  252. data/spec/unit/util/selinux_spec.rb +3 -6
  253. data/tasks/dependencies.rb +0 -5
  254. data/tasks/rspec.rb +1 -1
  255. metadata +6 -6
  256. data/acceptance/top-cookbooks/.kitchen.docker.yml +0 -13
  257. data/acceptance/top-cookbooks/.kitchen.git.yml +0 -11
@@ -20,13 +20,18 @@ require "spec_helper"
20
20
  require "chef/node/immutable_collections"
21
21
 
22
22
  describe Chef::Node::ImmutableMash do
23
+
23
24
  before do
24
- @data_in = { "top" => { "second_level" => "some value" },
25
- "top_level_2" => %w{array of values},
26
- "top_level_3" => [{ "hash_array" => 1, "hash_array_b" => 2 }],
27
- "top_level_4" => { "level2" => { "key" => "value" } },
25
+ @data_in = { "key" =>
26
+ { "top" => { "second_level" => "some value" },
27
+ "top_level_2" => %w{array of values},
28
+ "top_level_3" => [{ "hash_array" => 1, "hash_array_b" => 2 }],
29
+ "top_level_4" => { "level2" => { "key" => "value" } },
30
+ },
28
31
  }
29
- @immutable_mash = Chef::Node::ImmutableMash.new(@data_in)
32
+ @node = Chef::Node.new()
33
+ @node.attributes.default = @data_in
34
+ @immutable_mash = @node["key"]
30
35
  end
31
36
 
32
37
  it "element references like regular hash" do
@@ -57,9 +62,9 @@ describe Chef::Node::ImmutableMash do
57
62
  # we only ever absorb VividMashes from other precedence levels, which already have
58
63
  # been coerced to only have string keys, so we do not need to do that work twice (performance).
59
64
  it "does not call convert_value like Mash/VividMash" do
60
- @mash = Chef::Node::ImmutableMash.new({ test: "foo", "test2" => "bar" })
61
- expect(@mash[:test]).to eql("foo")
62
- expect(@mash["test2"]).to eql("bar")
65
+ @node.attributes.default = { test: "foo", "test2" => "bar" }
66
+ expect(@node[:test]).to eql("foo")
67
+ expect(@node["test2"]).to eql("bar")
63
68
  end
64
69
 
65
70
  describe "to_hash" do
@@ -80,7 +85,7 @@ describe Chef::Node::ImmutableMash do
80
85
  end
81
86
 
82
87
  it "should create a mash with the same content" do
83
- expect(@copy).to eq(@immutable_mash)
88
+ expect(@copy).to eql(@immutable_mash)
84
89
  end
85
90
 
86
91
  it "should allow mutation" do
@@ -175,9 +180,11 @@ end
175
180
  describe Chef::Node::ImmutableArray do
176
181
 
177
182
  before do
178
- @immutable_array = Chef::Node::ImmutableArray.new(%w{foo bar baz} + Array(1..3) + [nil, true, false, [ "el", 0, nil ] ])
179
- immutable_mash = Chef::Node::ImmutableMash.new({ "m" => "m" })
180
- @immutable_nested_array = Chef::Node::ImmutableArray.new(["level1", @immutable_array, immutable_mash])
183
+ @node = Chef::Node.new()
184
+ @node.attributes.default = { "key" => ["level1", %w{foo bar baz} + Array(1..3) + [nil, true, false, [ "el", 0, nil ] ], { "m" => "m" }] }
185
+ @immutable_array = @node["key"][1]
186
+ @immutable_mash = @node["key"][2]
187
+ @immutable_nested_array = @node["key"]
181
188
  end
182
189
 
183
190
  ##
@@ -249,7 +256,7 @@ describe Chef::Node::ImmutableArray do
249
256
  end
250
257
 
251
258
  it "should create an array with the same content" do
252
- expect(@copy).to eq(@immutable_nested_array)
259
+ expect(@immutable_nested_array).to eq(@copy)
253
260
  end
254
261
 
255
262
  it "should allow mutation" do
@@ -301,7 +308,7 @@ describe Chef::Node::ImmutableArray do
301
308
  end
302
309
 
303
310
  it "should create an array with the same content" do
304
- expect(@copy).to eq(@immutable_nested_array)
311
+ expect(@immutable_nested_array).to eq(@copy)
305
312
  end
306
313
 
307
314
  it "should allow mutation" do
@@ -314,4 +321,11 @@ describe Chef::Node::ImmutableArray do
314
321
  expect(@immutable_array[1, 2]).to eql(%w{bar baz})
315
322
  end
316
323
  end
324
+
325
+ describe "uniq" do
326
+ it "works" do
327
+ @node.attributes.default = { "key" => %w{foo bar foo baz bar} }
328
+ expect(@node["key"].uniq).to eql(%w{foo bar baz})
329
+ end
330
+ end
317
331
  end
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright:: Copyright 2016, Chef Software Inc.
2
+ # Copyright:: Copyright 2016-2017, Chef Software Inc.
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -60,7 +60,7 @@ describe Chef::Node::VividMash do
60
60
  end
61
61
 
62
62
  it "deep converts values through arrays" do
63
- expect(root).to receive(:reset_cache).with("foo")
63
+ expect(root).to receive(:reset_cache).with(no_args)
64
64
  vivid["foo"] = [ { :bar => true } ]
65
65
  expect(vivid["foo"].class).to eql(Chef::Node::AttrArray)
66
66
  expect(vivid["foo"][0].class).to eql(Chef::Node::VividMash)
@@ -68,7 +68,7 @@ describe Chef::Node::VividMash do
68
68
  end
69
69
 
70
70
  it "deep converts values through nested arrays" do
71
- expect(root).to receive(:reset_cache).with("foo")
71
+ expect(root).to receive(:reset_cache).with(no_args)
72
72
  vivid["foo"] = [ [ { :bar => true } ] ]
73
73
  expect(vivid["foo"].class).to eql(Chef::Node::AttrArray)
74
74
  expect(vivid["foo"][0].class).to eql(Chef::Node::AttrArray)
@@ -77,7 +77,7 @@ describe Chef::Node::VividMash do
77
77
  end
78
78
 
79
79
  it "deep converts values through hashes" do
80
- expect(root).to receive(:reset_cache).with("foo")
80
+ expect(root).to receive(:reset_cache).with(no_args)
81
81
  vivid["foo"] = { baz: { :bar => true } }
82
82
  expect(vivid["foo"]).to be_an_instance_of(Chef::Node::VividMash)
83
83
  expect(vivid["foo"]["baz"]).to be_an_instance_of(Chef::Node::VividMash)
@@ -184,42 +184,55 @@ describe Chef::Node::VividMash do
184
184
 
185
185
  it "should deeply autovivify" do
186
186
  expect(root).to receive(:reset_cache).at_least(:once).with("one")
187
+ expect(root).to receive(:reset_cache).at_least(:once).with("one", "five")
188
+ expect(root).to receive(:reset_cache).at_least(:once).with("one", "five", "six")
189
+ expect(root).to receive(:reset_cache).at_least(:once).with("one", "five", "six", "seven")
190
+ expect(root).to receive(:reset_cache).at_least(:once).with("one", "five", "six", "seven", "eight")
187
191
  vivid.write("one", "five", "six", "seven", "eight", "nine", "ten")
188
192
  expect(vivid["one"]["five"]["six"]["seven"]["eight"]["nine"]).to eql("ten")
189
193
  end
190
194
 
191
195
  it "should raise an exception if you overwrite an array with a hash" do
196
+ expect(root).to receive(:reset_cache).at_least(:once).with(no_args)
192
197
  expect(root).to receive(:reset_cache).at_least(:once).with("array")
193
198
  vivid.write("array", "five", "six")
194
199
  expect(vivid).to eql({ "one" => { "two" => { "three" => "four" } }, "array" => { "five" => "six" }, "nil" => nil })
195
200
  end
196
201
 
197
202
  it "should raise an exception if you traverse through an array with a hash" do
203
+ expect(root).to receive(:reset_cache).at_least(:once).with(no_args)
198
204
  expect(root).to receive(:reset_cache).at_least(:once).with("array")
205
+ expect(root).to receive(:reset_cache).at_least(:once).with("array", "five")
199
206
  vivid.write("array", "five", "six", "seven")
200
207
  expect(vivid).to eql({ "one" => { "two" => { "three" => "four" } }, "array" => { "five" => { "six" => "seven" } }, "nil" => nil })
201
208
  end
202
209
 
203
210
  it "should raise an exception if you overwrite a string with a hash" do
204
- expect(root).to receive(:reset_cache).at_least(:once).with("one")
211
+ expect(root).to receive(:reset_cache).at_least(:once).with("one", "two")
212
+ expect(root).to receive(:reset_cache).at_least(:once).with("one", "two", "three")
205
213
  vivid.write("one", "two", "three", "four", "five")
206
214
  expect(vivid).to eql({ "one" => { "two" => { "three" => { "four" => "five" } } }, "array" => [ 0, 1, 2 ], "nil" => nil })
207
215
  end
208
216
 
209
217
  it "should raise an exception if you traverse through a string with a hash" do
210
- expect(root).to receive(:reset_cache).at_least(:once).with("one")
218
+ expect(root).to receive(:reset_cache).at_least(:once).with("one", "two")
219
+ expect(root).to receive(:reset_cache).at_least(:once).with("one", "two", "three")
220
+ expect(root).to receive(:reset_cache).at_least(:once).with("one", "two", "three", "four")
211
221
  vivid.write("one", "two", "three", "four", "five", "six")
212
222
  expect(vivid).to eql({ "one" => { "two" => { "three" => { "four" => { "five" => "six" } } } }, "array" => [ 0, 1, 2 ], "nil" => nil })
213
223
  end
214
224
 
215
225
  it "should raise an exception if you overwrite a nil with a hash" do
226
+ expect(root).to receive(:reset_cache).at_least(:once).with(no_args)
216
227
  expect(root).to receive(:reset_cache).at_least(:once).with("nil")
217
228
  vivid.write("nil", "one", "two")
218
229
  expect(vivid).to eql({ "one" => { "two" => { "three" => "four" } }, "array" => [ 0, 1, 2 ], "nil" => { "one" => "two" } })
219
230
  end
220
231
 
221
232
  it "should raise an exception if you traverse through a nil with a hash" do
233
+ expect(root).to receive(:reset_cache).at_least(:once).with(no_args)
222
234
  expect(root).to receive(:reset_cache).at_least(:once).with("nil")
235
+ expect(root).to receive(:reset_cache).at_least(:once).with("nil", "one")
223
236
  vivid.write("nil", "one", "two", "three")
224
237
  expect(vivid).to eql({ "one" => { "two" => { "three" => "four" } }, "array" => [ 0, 1, 2 ], "nil" => { "one" => { "two" => "three" } } })
225
238
  end
@@ -240,6 +253,10 @@ describe Chef::Node::VividMash do
240
253
 
241
254
  it "should deeply autovivify" do
242
255
  expect(root).to receive(:reset_cache).at_least(:once).with("one")
256
+ expect(root).to receive(:reset_cache).at_least(:once).with("one", "five")
257
+ expect(root).to receive(:reset_cache).at_least(:once).with("one", "five", "six")
258
+ expect(root).to receive(:reset_cache).at_least(:once).with("one", "five", "six", "seven")
259
+ expect(root).to receive(:reset_cache).at_least(:once).with("one", "five", "six", "seven", "eight")
243
260
  vivid.write!("one", "five", "six", "seven", "eight", "nine", "ten")
244
261
  expect(vivid["one"]["five"]["six"]["seven"]["eight"]["nine"]).to eql("ten")
245
262
  end
@@ -295,7 +312,7 @@ describe Chef::Node::VividMash do
295
312
  end
296
313
 
297
314
  it "should unlink hashes" do
298
- expect(root).to receive(:reset_cache).at_least(:once).with("one")
315
+ expect(root).to receive(:reset_cache).at_least(:once).with(no_args)
299
316
  expect( vivid.unlink("one") ).to eql({ "two" => { "three" => "four" } })
300
317
  expect(vivid).to eql({ "array" => [ 0, 1, 2 ], "nil" => nil })
301
318
  end
@@ -307,7 +324,7 @@ describe Chef::Node::VividMash do
307
324
  end
308
325
 
309
326
  it "should unlink nil" do
310
- expect(root).to receive(:reset_cache).at_least(:once).with("nil")
327
+ expect(root).to receive(:reset_cache).at_least(:once).with(no_args)
311
328
  expect(vivid.unlink("nil")).to eql(nil)
312
329
  expect(vivid).to eql({ "one" => { "two" => { "three" => "four" } }, "array" => [ 0, 1, 2 ] })
313
330
  end
@@ -327,7 +344,7 @@ describe Chef::Node::VividMash do
327
344
  end
328
345
 
329
346
  it "should unlink! hashes" do
330
- expect(root).to receive(:reset_cache).at_least(:once).with("one")
347
+ expect(root).to receive(:reset_cache).at_least(:once).with(no_args)
331
348
  expect( vivid.unlink!("one") ).to eql({ "two" => { "three" => "four" } })
332
349
  expect(vivid).to eql({ "array" => [ 0, 1, 2 ], "nil" => nil })
333
350
  end
@@ -339,7 +356,7 @@ describe Chef::Node::VividMash do
339
356
  end
340
357
 
341
358
  it "should unlink! nil" do
342
- expect(root).to receive(:reset_cache).at_least(:once).with("nil")
359
+ expect(root).to receive(:reset_cache).at_least(:once).with(no_args)
343
360
  expect(vivid.unlink!("nil")).to eql(nil)
344
361
  expect(vivid).to eql({ "one" => { "two" => { "three" => "four" } }, "array" => [ 0, 1, 2 ] })
345
362
  end
@@ -101,6 +101,40 @@ describe Chef::NodeMap do
101
101
  end
102
102
  end
103
103
 
104
+ describe "platform version checks" do
105
+ before do
106
+ node_map.set(:thing, :foo, platform_family: "rhel", platform_version: ">= 7")
107
+ end
108
+
109
+ it "handles non-x.y.z platform versions without throwing an exception" do
110
+ allow(node).to receive(:[]).with(:platform_family).and_return("rhel")
111
+ allow(node).to receive(:[]).with(:platform_version).and_return("7.19.2.2F")
112
+ expect(node_map.get(node, :thing)).to eql(:foo)
113
+ end
114
+
115
+ it "handles non-x.y.z platform versions without throwing an exception when the match fails" do
116
+ allow(node).to receive(:[]).with(:platform_family).and_return("rhel")
117
+ allow(node).to receive(:[]).with(:platform_version).and_return("4.19.2.2F")
118
+ expect(node_map.get(node, :thing)).to eql(nil)
119
+ end
120
+ end
121
+
122
+ describe "ordering classes" do
123
+ class Foo; end
124
+ class Bar; end
125
+ it "orders them alphabetically when they're set in the reverse order" do
126
+ node_map.set(:thing, Foo)
127
+ node_map.set(:thing, Bar)
128
+ expect(node_map.get(node, :thing)).to eql(Bar)
129
+ end
130
+
131
+ it "orders them alphabetically when they're set in alphabetic order" do
132
+ node_map.set(:thing, Bar)
133
+ node_map.set(:thing, Foo)
134
+ expect(node_map.get(node, :thing)).to eql(Bar)
135
+ end
136
+ end
137
+
104
138
  describe "with a block doing platform_version checks" do
105
139
  before do
106
140
  node_map.set(:thing, :foo, platform_family: "rhel") do |node|
@@ -93,7 +93,7 @@ describe "Chef::Resource.property" do
93
93
  expect(resource.bare_property).to eq 20
94
94
  end
95
95
  it "can be set with =" do
96
- expect(resource.bare_property 10).to eq 10
96
+ expect(resource.bare_property = 10).to eq 10
97
97
  expect(resource.bare_property).to eq 10
98
98
  end
99
99
  it "can be set to nil with =" do
@@ -1037,20 +1037,20 @@ describe "Chef::Resource.property" do
1037
1037
 
1038
1038
  context "default ordering deprecation warnings" do
1039
1039
  it "emits an error for property :x, default: 10, #{name}: true" do
1040
- expect { resource_class.property :x, :default => 10, name.to_sym => true }.to raise_error Chef::Exceptions::ArgumentError,
1041
- /Cannot specify both default and name_property\/name_attribute together on property x of resource chef_resource_property_spec_(\d+)/
1040
+ expect { resource_class.property :x, :default => 10, name.to_sym => true }.to raise_error ArgumentError,
1041
+ /A property cannot be both a name_property\/name_attribute and have a default value. Use one or the other on property x of resource chef_resource_property_spec_(\d+)/
1042
1042
  end
1043
1043
  it "emits an error for property :x, default: nil, #{name}: true" do
1044
- expect { resource_class.property :x, :default => nil, name.to_sym => true }.to raise_error Chef::Exceptions::ArgumentError,
1045
- /Cannot specify both default and name_property\/name_attribute together on property x of resource chef_resource_property_spec_(\d+)/
1044
+ expect { resource_class.property :x, :default => nil, name.to_sym => true }.to raise_error ArgumentError,
1045
+ /A property cannot be both a name_property\/name_attribute and have a default value. Use one or the other on property x of resource chef_resource_property_spec_(\d+)/
1046
1046
  end
1047
1047
  it "emits an error for property :x, #{name}: true, default: 10" do
1048
- expect { resource_class.property :x, name.to_sym => true, :default => 10 }.to raise_error Chef::Exceptions::ArgumentError,
1049
- /Cannot specify both default and name_property\/name_attribute together on property x of resource chef_resource_property_spec_(\d+)/
1048
+ expect { resource_class.property :x, name.to_sym => true, :default => 10 }.to raise_error ArgumentError,
1049
+ /A property cannot be both a name_property\/name_attribute and have a default value. Use one or the other on property x of resource chef_resource_property_spec_(\d+)/
1050
1050
  end
1051
1051
  it "emits an error for property :x, #{name}: true, default: nil" do
1052
- expect { resource_class.property :x, name.to_sym => true, :default => nil }.to raise_error Chef::Exceptions::ArgumentError,
1053
- /Cannot specify both default and name_property\/name_attribute together on property x of resource chef_resource_property_spec_(\d+)/
1052
+ expect { resource_class.property :x, name.to_sym => true, :default => nil }.to raise_error ArgumentError,
1053
+ /A property cannot be both a name_property\/name_attribute and have a default value. Use one or the other on property x of resource chef_resource_property_spec_(\d+)/
1054
1054
  end
1055
1055
  end
1056
1056
  end
@@ -1058,13 +1058,13 @@ describe "Chef::Resource.property" do
1058
1058
 
1059
1059
  it "raises an error if both name_property and name_attribute are specified" do
1060
1060
  expect { resource_class.property :x, :name_property => false, :name_attribute => 1 }.to raise_error ArgumentError,
1061
- /Cannot specify both name_property and name_attribute together on property x of resource chef_resource_property_spec_(\d+)./
1061
+ /name_attribute and name_property are functionally identical and both cannot be specified on a property at once. Use just one on property x of resource chef_resource_property_spec_(\d+)./
1062
1062
  expect { resource_class.property :x, :name_property => false, :name_attribute => nil }.to raise_error ArgumentError,
1063
- /Cannot specify both name_property and name_attribute together on property x of resource chef_resource_property_spec_(\d+)./
1063
+ /name_attribute and name_property are functionally identical and both cannot be specified on a property at once. Use just one on property x of resource chef_resource_property_spec_(\d+)./
1064
1064
  expect { resource_class.property :x, :name_property => false, :name_attribute => false }.to raise_error ArgumentError,
1065
- /Cannot specify both name_property and name_attribute together on property x of resource chef_resource_property_spec_(\d+)./
1065
+ /name_attribute and name_property are functionally identical and both cannot be specified on a property at once. Use just one on property x of resource chef_resource_property_spec_(\d+)./
1066
1066
  expect { resource_class.property :x, :name_property => true, :name_attribute => true }.to raise_error ArgumentError,
1067
- /Cannot specify both name_property and name_attribute together on property x of resource chef_resource_property_spec_(\d+)./
1067
+ /name_attribute and name_property are functionally identical and both cannot be specified on a property at once. Use just one on property x of resource chef_resource_property_spec_(\d+)./
1068
1068
  end
1069
1069
 
1070
1070
  context "property_type" do
@@ -117,11 +117,16 @@ describe Chef::Provider::Group::Dscl do
117
117
  before do
118
118
  @node = Chef::Node.new
119
119
  @provider = Chef::Provider::Group::Dscl.new(@node, @new_resource)
120
- allow(@provider).to receive(:safe_dscl).and_return("\naj 500\n")
120
+ allow(@provider).to receive(:safe_dscl).and_return(<<-eos
121
+ someprogram somethingElse:gid = (
122
+ 500
123
+ )
124
+ eos
125
+ )
121
126
  end
122
127
 
123
- it "should run safe_dscl with list /Groups gid" do
124
- expect(@provider).to receive(:safe_dscl).with(*"list /Groups gid".split(" "))
128
+ it "should run safe_dscl with search /Groups gid" do
129
+ expect(@provider).to receive(:safe_dscl).with(*"search /Groups PrimaryGroupID 500".split(" "))
125
130
  @provider.gid_used?(500)
126
131
  end
127
132
 
@@ -130,7 +135,11 @@ describe Chef::Provider::Group::Dscl do
130
135
  end
131
136
 
132
137
  it "should return false for an unused gid number" do
133
- expect(@provider.gid_used?(501)).to be_falsey
138
+ expect(@provider.gid_used?(0)).to be_falsey
139
+ expect(@provider.gid_used?(50)).to be_falsey
140
+ expect(@provider.gid_used?(5000)).to be_falsey
141
+ expect(@provider.gid_used?(1500)).to be_falsey
142
+ expect(@provider.gid_used?(18)).to be_falsey
134
143
  end
135
144
 
136
145
  it "should return false if not given any valid gid number" do
@@ -171,7 +180,7 @@ describe Chef::Provider::Group::Dscl do
171
180
  describe "with a valid gid number which is not already in use" do
172
181
  it "should run safe_dscl with create /Groups/group PrimaryGroupID gid" do
173
182
  allow(@provider).to receive(:get_free_gid).and_return(50)
174
- expect(@provider).to receive(:safe_dscl).with(*"list /Groups gid".split(" "))
183
+ expect(@provider).to receive(:safe_dscl).with(*"search /Groups PrimaryGroupID 50".split(" ")).and_return("")
175
184
  expect(@provider).to receive(:safe_dscl).with("create", "/Groups/aj", "PrimaryGroupID", 50).and_return(true)
176
185
  @provider.set_gid
177
186
  end
@@ -38,12 +38,19 @@ describe Chef::Provider::Ifconfig do
38
38
  status = double("Status", exitstatus: 0)
39
39
  @provider.instance_variable_set("@status", status)
40
40
  @provider.current_resource = @current_resource
41
-
42
41
  end
42
+
43
43
  describe Chef::Provider::Ifconfig, "load_current_resource" do
44
+ let(:net_tools_version) { StringIO.new <<-EOS }
45
+ net-tools 1.60
46
+ ifconfig 1.42 (2001-04-13)
47
+ EOS
48
+
44
49
  before do
45
- @status = double(stdout: "", exitstatus: 1)
46
- allow(@provider).to receive(:shell_out).and_return(@status)
50
+ ifconfig = double(stdout: "", exitstatus: 1)
51
+ allow(@provider).to receive(:shell_out).and_return(ifconfig)
52
+ ifconfig_version = double(stdout: "", stderr: net_tools_version, exitstatus: 4)
53
+ allow(@provider).to receive(:shell_out).with("ifconfig --version").and_return(ifconfig_version)
47
54
  @provider.load_current_resource
48
55
  end
49
56
  it "should track state of ifconfig failure" do
@@ -157,9 +157,9 @@ describe Chef::Provider::RemoteFile::HTTP do
157
157
  let(:expected_http_opts) { {} }
158
158
  let(:expected_http_args) { [uri, expected_http_opts] }
159
159
 
160
- let(:tempfile_path) { "/tmp/chef-mock-tempfile-abc123" }
160
+ let(:tempfile_path) { tempfile.path }
161
161
 
162
- let(:tempfile) { double(Tempfile, :path => tempfile_path, :close => nil) }
162
+ let(:tempfile) { Tempfile.open("muhtempfile") }
163
163
 
164
164
  let(:last_response) { {} }
165
165
 
@@ -171,7 +171,7 @@ describe Chef::Provider::RemoteFile::HTTP do
171
171
 
172
172
  let(:rest) do
173
173
  rest = double(Chef::HTTP::Simple)
174
- allow(rest).to receive(:streaming_request).and_return(tempfile)
174
+ allow_any_instance_of(Chef::FileContentManagement::Tempfile).to receive(:tempfile).and_return(tempfile)
175
175
  allow(rest).to receive(:last_response).and_return(last_response)
176
176
  rest
177
177
  end
@@ -189,17 +189,35 @@ describe Chef::Provider::RemoteFile::HTTP do
189
189
 
190
190
  it "should return a nil tempfile for a 304 HTTPNotModifed" do
191
191
  # Streaming request returns nil for 304 errors
192
- allow(rest).to receive(:streaming_request).and_return(nil)
192
+ expect(rest).to receive(:streaming_request).with(uri, {}, tempfile).and_return(nil)
193
193
  expect(fetcher.fetch).to be_nil
194
194
  end
195
195
 
196
196
  end
197
197
 
198
- describe "and the request returns new content" do
198
+ context "with progress reports" do
199
+ let(:fetched_content_checksum) { "e2a8938cc31754f6c067b35aab1d0d4864272e9bf8504536ef3e79ebf8432305" }
200
+
201
+ before do
202
+ expect(cache_control_data).to receive(:save)
203
+ expect(Chef::Digester).to receive(:checksum_for_file).with(tempfile_path).and_return(fetched_content_checksum)
204
+ Chef::Config[:show_download_progress] = true
205
+ end
206
+
207
+ it "should yield its progress" do
208
+ expect(rest).to receive(:streaming_request_with_progress).with(uri, {}, tempfile).and_yield(50, 100).and_yield(70, 100).and_return(tempfile)
209
+ expect(event_dispatcher).to receive(:formatter?).and_return(true)
210
+ expect(event_dispatcher).to receive(:resource_update_progress).with(new_resource, 50, 100, 10).ordered
211
+ expect(event_dispatcher).to receive(:resource_update_progress).with(new_resource, 70, 100, 10).ordered
212
+ fetcher.fetch
213
+ end
214
+ end
199
215
 
216
+ describe "and the request returns new content" do
200
217
  let(:fetched_content_checksum) { "e2a8938cc31754f6c067b35aab1d0d4864272e9bf8504536ef3e79ebf8432305" }
201
218
 
202
219
  before do
220
+ expect(rest).to receive(:streaming_request).with(uri, {}, tempfile).and_return(tempfile)
203
221
  expect(cache_control_data).to receive(:save)
204
222
  expect(Chef::Digester).to receive(:checksum_for_file).with(tempfile_path).and_return(fetched_content_checksum)
205
223
  end
@@ -212,20 +230,6 @@ describe Chef::Provider::RemoteFile::HTTP do
212
230
  expect(cache_control_data.checksum).to eq(fetched_content_checksum)
213
231
  end
214
232
 
215
- context "with progress reports" do
216
- before do
217
- Chef::Config[:show_download_progress] = true
218
- end
219
-
220
- it "should yield its progress" do
221
- allow(rest).to receive(:streaming_request_with_progress).and_yield(50, 100).and_yield(70, 100).and_return(tempfile)
222
- expect(event_dispatcher).to receive(:formatter?).and_return(true)
223
- expect(event_dispatcher).to receive(:resource_update_progress).with(new_resource, 50, 100, 10).ordered
224
- expect(event_dispatcher).to receive(:resource_update_progress).with(new_resource, 70, 100, 10).ordered
225
- fetcher.fetch
226
- end
227
- end
228
-
229
233
  context "and the response does not contain an etag" do
230
234
  let(:last_response) { { "etag" => nil } }
231
235
  it "does not include an etag in the result" do