microwave 1.0.4 → 11.400.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (249) hide show
  1. data/CONTRIBUTING.md +155 -0
  2. data/README.md +89 -0
  3. data/Rakefile +2 -2
  4. data/bin/chef-apply +25 -0
  5. data/bin/chef-shell +34 -0
  6. data/bin/chef-solo +0 -2
  7. data/bin/shef +6 -5
  8. data/lib/chef.rb +2 -4
  9. data/spec/data/big_json.json +2 -1
  10. data/spec/data/big_json_plus_one.json +2 -1
  11. data/spec/data/cookbooks/chefignore +2 -0
  12. data/spec/data/cookbooks/openldap/attributes/default.rb +10 -9
  13. data/spec/data/cookbooks/openldap/attributes/smokey.rb +1 -1
  14. data/spec/data/git_bundles/sinatra-test-app-with-callback-files.gitbundle +0 -0
  15. data/spec/data/git_bundles/sinatra-test-app-with-symlinks.gitbundle +0 -0
  16. data/spec/data/git_bundles/sinatra-test-app.gitbundle +0 -0
  17. data/spec/data/lwrp/providers/inline_compiler.rb +26 -0
  18. data/spec/data/nodes/default.rb +3 -3
  19. data/spec/data/nodes/test.example.com.rb +3 -3
  20. data/spec/data/nodes/test.rb +3 -3
  21. data/spec/data/partial_one.erb +1 -0
  22. data/spec/data/run_context/cookbooks/circular-dep1/attributes/default.rb +4 -0
  23. data/spec/data/run_context/cookbooks/circular-dep1/definitions/circular_dep1_res.rb +1 -0
  24. data/spec/data/run_context/cookbooks/circular-dep1/libraries/lib.rb +2 -0
  25. data/spec/data/run_context/cookbooks/circular-dep1/metadata.rb +2 -0
  26. data/spec/data/run_context/cookbooks/circular-dep1/providers/provider.rb +1 -0
  27. data/spec/data/run_context/cookbooks/circular-dep1/recipes/default.rb +0 -0
  28. data/spec/data/run_context/cookbooks/circular-dep1/resources/resource.rb +1 -0
  29. data/spec/data/run_context/cookbooks/circular-dep2/attributes/default.rb +3 -0
  30. data/spec/data/run_context/cookbooks/circular-dep2/definitions/circular_dep2_res.rb +1 -0
  31. data/spec/data/run_context/cookbooks/circular-dep2/libraries/lib.rb +2 -0
  32. data/spec/data/run_context/cookbooks/circular-dep2/metadata.rb +2 -0
  33. data/spec/data/run_context/cookbooks/circular-dep2/providers/provider.rb +1 -0
  34. data/spec/data/run_context/cookbooks/circular-dep2/recipes/default.rb +0 -0
  35. data/spec/data/run_context/cookbooks/circular-dep2/resources/resource.rb +1 -0
  36. data/spec/data/run_context/cookbooks/dependency1/attributes/aa_first.rb +2 -0
  37. data/spec/data/run_context/cookbooks/dependency1/attributes/default.rb +2 -0
  38. data/spec/data/run_context/cookbooks/dependency1/attributes/zz_last.rb +3 -0
  39. data/spec/data/run_context/cookbooks/dependency1/definitions/dependency1_res.rb +1 -0
  40. data/spec/data/run_context/cookbooks/dependency1/libraries/lib.rb +2 -0
  41. data/spec/data/run_context/cookbooks/dependency1/providers/provider.rb +1 -0
  42. data/spec/data/run_context/cookbooks/dependency1/recipes/default.rb +0 -0
  43. data/spec/data/run_context/cookbooks/dependency1/resources/resource.rb +1 -0
  44. data/spec/data/run_context/cookbooks/dependency2/attributes/default.rb +3 -0
  45. data/spec/data/run_context/cookbooks/dependency2/definitions/dependency2_res.rb +1 -0
  46. data/spec/data/run_context/cookbooks/dependency2/libraries/lib.rb +2 -0
  47. data/spec/data/run_context/cookbooks/dependency2/providers/provider.rb +1 -0
  48. data/spec/data/run_context/cookbooks/dependency2/recipes/default.rb +0 -0
  49. data/spec/data/run_context/cookbooks/dependency2/resources/resource.rb +1 -0
  50. data/spec/data/run_context/cookbooks/no-default-attr/attributes/server.rb +3 -0
  51. data/spec/data/run_context/cookbooks/no-default-attr/definitions/no_default-attr_res.rb +1 -0
  52. data/spec/data/run_context/cookbooks/no-default-attr/providers/provider.rb +1 -0
  53. data/spec/data/run_context/cookbooks/no-default-attr/recipes/default.rb +0 -0
  54. data/spec/data/run_context/cookbooks/no-default-attr/resources/resource.rb +1 -0
  55. data/spec/data/run_context/cookbooks/test-with-circular-deps/attributes/default.rb +3 -0
  56. data/spec/data/run_context/cookbooks/test-with-circular-deps/definitions/test_with-circular-deps_res.rb +1 -0
  57. data/spec/data/run_context/cookbooks/test-with-circular-deps/libraries/lib.rb +2 -0
  58. data/spec/data/run_context/cookbooks/test-with-circular-deps/metadata.rb +2 -0
  59. data/spec/data/run_context/cookbooks/test-with-circular-deps/providers/provider.rb +1 -0
  60. data/spec/data/run_context/cookbooks/test-with-circular-deps/recipes/default.rb +0 -0
  61. data/spec/data/run_context/cookbooks/test-with-circular-deps/resources/resource.rb +1 -0
  62. data/spec/data/run_context/cookbooks/test-with-deps/attributes/default.rb +3 -0
  63. data/spec/data/run_context/cookbooks/test-with-deps/definitions/test_with-deps_res.rb +1 -0
  64. data/spec/data/run_context/cookbooks/test-with-deps/libraries/lib.rb +1 -0
  65. data/spec/data/run_context/cookbooks/test-with-deps/metadata.rb +3 -0
  66. data/spec/data/run_context/cookbooks/test-with-deps/providers/provider.rb +1 -0
  67. data/spec/data/run_context/cookbooks/test-with-deps/recipes/default.rb +0 -0
  68. data/spec/data/run_context/cookbooks/test-with-deps/recipes/server.rb +0 -0
  69. data/spec/data/run_context/cookbooks/test-with-deps/resources/resource.rb +1 -0
  70. data/spec/data/run_context/cookbooks/test/attributes/default.rb +0 -0
  71. data/spec/data/run_context/cookbooks/test/attributes/george.rb +1 -1
  72. data/spec/data/run_context/cookbooks/test/definitions/test_res.rb +1 -0
  73. data/spec/data/run_context/cookbooks/test/providers/provider.rb +1 -0
  74. data/spec/data/run_context/cookbooks/test/resources/resource.rb +1 -0
  75. data/spec/data/shef-config.rb +10 -0
  76. data/spec/functional/dsl/registry_helper_spec.rb +63 -0
  77. data/spec/functional/knife/cookbook_delete_spec.rb +0 -2
  78. data/spec/functional/knife/exec_spec.rb +4 -6
  79. data/spec/functional/knife/smoke_test.rb +34 -0
  80. data/spec/functional/knife/ssh_spec.rb +64 -3
  81. data/spec/functional/resource/cookbook_file_spec.rb +33 -2
  82. data/spec/functional/resource/deploy_revision_spec.rb +515 -0
  83. data/spec/functional/resource/directory_spec.rb +4 -0
  84. data/spec/functional/resource/file_spec.rb +56 -22
  85. data/spec/functional/resource/link_spec.rb +12 -10
  86. data/spec/functional/resource/registry_spec.rb +572 -0
  87. data/spec/functional/resource/remote_directory_spec.rb +142 -36
  88. data/spec/functional/resource/remote_file_spec.rb +28 -3
  89. data/spec/functional/resource/template_spec.rb +23 -2
  90. data/spec/functional/run_lock_spec.rb +238 -0
  91. data/spec/functional/shell_spec.rb +101 -0
  92. data/spec/functional/tiny_server_spec.rb +5 -4
  93. data/spec/functional/win32/registry_helper_spec.rb +632 -0
  94. data/spec/functional/win32/security_spec.rb +37 -0
  95. data/spec/spec_helper.rb +15 -3
  96. data/spec/stress/win32/security_spec.rb +5 -5
  97. data/spec/support/chef_helpers.rb +14 -3
  98. data/spec/support/lib/chef/resource/cat.rb +3 -5
  99. data/spec/support/lib/chef/resource/one_two_three_four.rb +8 -10
  100. data/spec/support/lib/chef/resource/zen_master.rb +8 -10
  101. data/spec/support/matchers/leak.rb +1 -1
  102. data/spec/support/platform_helpers.rb +18 -0
  103. data/spec/support/shared/functional/directory_resource.rb +85 -23
  104. data/spec/support/shared/functional/file_resource.rb +198 -53
  105. data/spec/support/shared/functional/securable_resource.rb +140 -105
  106. data/spec/support/shared/functional/securable_resource_with_reporting.rb +375 -0
  107. data/spec/support/shared/unit/file_system_support.rb +110 -0
  108. data/spec/support/shared/unit/platform_introspector.rb +162 -0
  109. data/spec/tiny_server.rb +29 -10
  110. data/spec/unit/api_client/registration_spec.rb +172 -0
  111. data/spec/unit/api_client_spec.rb +156 -103
  112. data/spec/unit/application/apply.rb +84 -0
  113. data/spec/unit/application/knife_spec.rb +5 -0
  114. data/spec/unit/application_spec.rb +57 -2
  115. data/spec/unit/chef_fs/diff_spec.rb +329 -0
  116. data/spec/unit/chef_fs/file_pattern_spec.rb +526 -0
  117. data/spec/unit/chef_fs/file_system/chef_server_root_dir_spec.rb +237 -0
  118. data/spec/unit/chef_fs/file_system/cookbooks_dir_spec.rb +568 -0
  119. data/spec/unit/chef_fs/file_system/data_bags_dir_spec.rb +220 -0
  120. data/spec/unit/chef_fs/file_system_spec.rb +136 -0
  121. data/spec/unit/client_spec.rb +188 -16
  122. data/spec/unit/config_spec.rb +54 -4
  123. data/spec/unit/cookbook/chefignore_spec.rb +2 -1
  124. data/spec/unit/cookbook/syntax_check_spec.rb +48 -109
  125. data/spec/unit/cookbook_loader_spec.rb +153 -91
  126. data/spec/unit/cookbook_manifest_spec.rb +81 -81
  127. data/spec/unit/cookbook_spec.rb +3 -20
  128. data/spec/unit/cookbook_version_spec.rb +23 -122
  129. data/spec/unit/digester_spec.rb +50 -0
  130. data/spec/unit/dsl/data_query_spec.rb +66 -0
  131. data/spec/unit/dsl/platform_introspection_spec.rb +130 -0
  132. data/spec/unit/dsl/regsitry_helper_spec.rb +55 -0
  133. data/spec/unit/encrypted_data_bag_item_spec.rb +126 -10
  134. data/spec/unit/environment_spec.rb +0 -130
  135. data/spec/unit/exceptions_spec.rb +2 -3
  136. data/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb +23 -3
  137. data/spec/unit/json_compat_spec.rb +69 -0
  138. data/spec/unit/knife/bootstrap_spec.rb +81 -28
  139. data/spec/unit/knife/client_reregister_spec.rb +23 -22
  140. data/spec/unit/knife/configure_spec.rb +29 -26
  141. data/spec/unit/knife/cookbook_metadata_spec.rb +11 -4
  142. data/spec/unit/knife/cookbook_site_install_spec.rb +12 -2
  143. data/spec/unit/knife/cookbook_test_spec.rb +1 -0
  144. data/spec/unit/knife/cookbook_upload_spec.rb +41 -2
  145. data/spec/unit/knife/core/bootstrap_context_spec.rb +8 -1
  146. data/spec/unit/knife/core/ui_spec.rb +156 -7
  147. data/spec/unit/knife/data_bag_create_spec.rb +14 -0
  148. data/spec/unit/knife/data_bag_edit_spec.rb +14 -4
  149. data/spec/unit/knife/data_bag_from_file_spec.rb +17 -5
  150. data/spec/unit/knife/data_bag_show_spec.rb +11 -4
  151. data/spec/unit/knife/index_rebuild_spec.rb +96 -33
  152. data/spec/unit/knife/knife_help.rb +7 -7
  153. data/spec/unit/knife/node_run_list_remove_spec.rb +2 -1
  154. data/spec/unit/knife/ssh_spec.rb +121 -15
  155. data/spec/unit/knife/status_spec.rb +2 -2
  156. data/spec/unit/knife/user_create_spec.rb +86 -0
  157. data/spec/unit/knife/user_delete_spec.rb +39 -0
  158. data/spec/unit/knife/user_edit_spec.rb +42 -0
  159. data/spec/unit/knife/user_list_spec.rb +32 -0
  160. data/spec/unit/knife/user_reregister_spec.rb +53 -0
  161. data/spec/unit/knife/user_show_spec.rb +41 -0
  162. data/spec/unit/knife_spec.rb +53 -0
  163. data/spec/unit/lwrp_spec.rb +59 -17
  164. data/spec/unit/mixin/checksum_spec.rb +2 -2
  165. data/spec/unit/mixin/deep_merge_spec.rb +56 -491
  166. data/spec/unit/mixin/deprecation_spec.rb +23 -0
  167. data/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb +6 -1
  168. data/spec/unit/mixin/params_validate_spec.rb +4 -2
  169. data/spec/unit/mixin/securable_spec.rb +5 -3
  170. data/spec/unit/mixin/template_spec.rb +119 -0
  171. data/spec/unit/node/attribute_spec.rb +272 -137
  172. data/spec/unit/node/immutable_collections_spec.rb +139 -0
  173. data/spec/unit/node_spec.rb +411 -339
  174. data/spec/unit/platform_spec.rb +8 -8
  175. data/spec/unit/provider/breakpoint_spec.rb +8 -8
  176. data/spec/unit/provider/cookbook_file_spec.rb +4 -8
  177. data/spec/unit/provider/deploy/revision_spec.rb +2 -8
  178. data/spec/unit/provider/deploy_spec.rb +6 -40
  179. data/spec/unit/provider/directory_spec.rb +103 -68
  180. data/spec/unit/provider/erl_call_spec.rb +0 -2
  181. data/spec/unit/provider/file_spec.rb +69 -59
  182. data/spec/unit/provider/git_spec.rb +0 -10
  183. data/spec/unit/provider/group/groupadd_spec.rb +1 -1
  184. data/spec/unit/provider/group/usermod_spec.rb +2 -2
  185. data/spec/unit/provider/http_request_spec.rb +28 -69
  186. data/spec/unit/provider/ifconfig_spec.rb +2 -2
  187. data/spec/unit/provider/link_spec.rb +1 -1
  188. data/spec/unit/provider/ohai_spec.rb +4 -4
  189. data/spec/unit/provider/package/apt_spec.rb +0 -1
  190. data/spec/unit/provider/package/ips_spec.rb +0 -1
  191. data/spec/unit/provider/package/rubygems_spec.rb +0 -18
  192. data/spec/unit/provider/package/yum_spec.rb +79 -15
  193. data/spec/unit/provider/package_spec.rb +7 -5
  194. data/spec/unit/provider/registry_key_spec.rb +269 -0
  195. data/spec/unit/provider/remote_directory_spec.rb +24 -7
  196. data/spec/unit/provider/remote_file_spec.rb +36 -0
  197. data/spec/unit/provider/route_spec.rb +3 -6
  198. data/spec/unit/provider/ruby_block_spec.rb +8 -0
  199. data/spec/unit/provider/service/arch_service_spec.rb +4 -4
  200. data/spec/unit/provider/service/debian_service_spec.rb +1 -1
  201. data/spec/unit/provider/service/freebsd_service_spec.rb +4 -4
  202. data/spec/unit/provider/service/init_service_spec.rb +26 -3
  203. data/spec/unit/provider/service/insserv_service_spec.rb +1 -1
  204. data/spec/unit/provider/service/invokercd_service_spec.rb +3 -3
  205. data/spec/unit/provider/service/redhat_spec.rb +1 -1
  206. data/spec/unit/provider/service/simple_service_spec.rb +3 -3
  207. data/spec/unit/provider/service/upstart_service_spec.rb +7 -7
  208. data/spec/unit/provider/service_spec.rb +2 -2
  209. data/spec/unit/provider/subversion_spec.rb +1 -1
  210. data/spec/unit/provider/template_spec.rb +35 -11
  211. data/spec/unit/provider/user/dscl_spec.rb +57 -31
  212. data/spec/unit/provider/user_spec.rb +7 -16
  213. data/spec/unit/provider_spec.rb +4 -3
  214. data/spec/unit/recipe_spec.rb +10 -8
  215. data/spec/unit/registry_helper_spec.rb +376 -0
  216. data/spec/unit/resource/log_spec.rb +9 -0
  217. data/spec/unit/resource/registry_key_spec.rb +171 -0
  218. data/spec/unit/resource/remote_file_spec.rb +21 -23
  219. data/spec/unit/resource/ruby_block_spec.rb +7 -3
  220. data/spec/unit/resource/service_spec.rb +11 -0
  221. data/spec/unit/resource_spec.rb +27 -4
  222. data/spec/unit/rest/auth_credentials_spec.rb +2 -14
  223. data/spec/unit/rest_spec.rb +122 -187
  224. data/spec/unit/run_context/cookbook_compiler_spec.rb +181 -0
  225. data/spec/unit/run_context_spec.rb +18 -4
  226. data/spec/unit/run_list_spec.rb +0 -209
  227. data/spec/unit/run_lock_spec.rb +37 -0
  228. data/spec/unit/runner_spec.rb +101 -2
  229. data/spec/unit/scan_access_control_spec.rb +4 -4
  230. data/spec/unit/{shef → shell}/model_wrapper_spec.rb +5 -5
  231. data/spec/unit/{shef/shef_ext_spec.rb → shell/shell_ext_spec.rb} +21 -21
  232. data/spec/unit/{shef/shef_session_spec.rb → shell/shell_session_spec.rb} +12 -12
  233. data/spec/unit/shell_out_spec.rb +18 -0
  234. data/spec/unit/{shef_spec.rb → shell_spec.rb} +20 -20
  235. data/spec/unit/user_spec.rb +255 -0
  236. metadata +162 -157
  237. data/README.rdoc +0 -177
  238. data/spec/unit/certificate_spec.rb +0 -76
  239. data/spec/unit/checksum_cache_spec.rb +0 -209
  240. data/spec/unit/checksum_spec.rb +0 -94
  241. data/spec/unit/couchdb_spec.rb +0 -274
  242. data/spec/unit/index_queue_spec.rb +0 -391
  243. data/spec/unit/json_compat_spect.rb +0 -53
  244. data/spec/unit/mixin/language_spec.rb +0 -305
  245. data/spec/unit/openid_registration_spec.rb +0 -153
  246. data/spec/unit/solr_query/query_transform_spec.rb +0 -454
  247. data/spec/unit/solr_query/solr_http_request_spec.rb +0 -244
  248. data/spec/unit/solr_query_spec.rb +0 -203
  249. data/spec/unit/webui_user_spec.rb +0 -238
@@ -22,8 +22,8 @@ require 'highline'
22
22
  describe Chef::Knife::Status do
23
23
  before(:each) do
24
24
  node = Chef::Node.new.tap do |n|
25
- n["fqdn"] = "foobar"
26
- n["ohai_time"] = 1343845969
25
+ n.automatic_attrs["fqdn"] = "foobar"
26
+ n.automatic_attrs["ohai_time"] = 1343845969
27
27
  end
28
28
  query = mock("Chef::Search::Query")
29
29
  query.stub!(:search).and_yield(node)
@@ -0,0 +1,86 @@
1
+ #
2
+ # Author:: Steven Danna (<steve@opscode.com>)
3
+ # Copyright:: Copyright (c) 2012 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'spec_helper'
20
+
21
+ Chef::Knife::UserCreate.load_deps
22
+
23
+ describe Chef::Knife::UserCreate do
24
+ before(:each) do
25
+ @knife = Chef::Knife::UserCreate.new
26
+ @knife.name_args = [ 'a_user' ]
27
+ @knife.config[:user_password] = "foobar"
28
+ @user = Chef::User.new
29
+ @user.name "a_user"
30
+ @user_with_private_key = Chef::User.new
31
+ @user_with_private_key.name "a_user"
32
+ @user_with_private_key.private_key 'private_key'
33
+ @user.stub!(:create).and_return(@user_with_private_key)
34
+ Chef::User.stub!(:new).and_return(@user)
35
+ Chef::User.stub!(:from_hash).and_return(@user)
36
+ @knife.stub!(:edit_data).and_return(@user.to_hash)
37
+ @stdout = StringIO.new
38
+ @stderr = StringIO.new
39
+ @knife.ui.stub!(:stdout).and_return(@stdout)
40
+ @knife.ui.stub!(:stderr).and_return(@stderr)
41
+ end
42
+
43
+ it "creates a new user" do
44
+ Chef::User.should_receive(:new).and_return(@user)
45
+ @user.should_receive(:create)
46
+ @knife.run
47
+ @stdout.string.should match /created user.+a_user/i
48
+ end
49
+
50
+ it "sets the password" do
51
+ @knife.config[:user_password] = "a_password"
52
+ @user.should_receive(:password).with("a_password")
53
+ @knife.run
54
+ end
55
+
56
+ it "exits with an error if password is blank" do
57
+ @knife.config[:user_password] = ''
58
+ lambda { @knife.run }.should raise_error SystemExit
59
+ @stderr.string.should match /You must specify a non-blank password/
60
+ end
61
+
62
+ it "sets the user name" do
63
+ @user.should_receive(:name).with("a_user")
64
+ @knife.run
65
+ end
66
+
67
+ it "sets the public key if given" do
68
+ @knife.config[:user_key] = "/a/filename"
69
+ File.stub(:read).with(File.expand_path("/a/filename")).and_return("a_key")
70
+ @user.should_receive(:public_key).with("a_key")
71
+ @knife.run
72
+ end
73
+
74
+ it "allows you to edit the data" do
75
+ @knife.should_receive(:edit_data).with(@user)
76
+ @knife.run
77
+ end
78
+
79
+ it "writes the private key to a file when --file is specified" do
80
+ @knife.config[:file] = "/tmp/a_file"
81
+ filehandle = mock("filehandle")
82
+ filehandle.should_receive(:print).with('private_key')
83
+ File.should_receive(:open).with("/tmp/a_file", "w").and_yield(filehandle)
84
+ @knife.run
85
+ end
86
+ end
@@ -0,0 +1,39 @@
1
+ #
2
+ # Author:: Steven Danna (<steve@opscode.com>)
3
+ # Copyright:: Copyright (c) 2012 Opscode, Inc
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'spec_helper'
20
+
21
+ describe Chef::Knife::UserDelete do
22
+ before(:each) do
23
+ Chef::Knife::UserDelete.load_deps
24
+ @knife = Chef::Knife::UserDelete.new
25
+ @knife.name_args = [ 'my_user' ]
26
+ end
27
+
28
+ it 'deletes the user' do
29
+ @knife.should_receive(:delete_object).with(Chef::User, 'my_user')
30
+ @knife.run
31
+ end
32
+
33
+ it 'prints usage and exits when a user name is not provided' do
34
+ @knife.name_args = []
35
+ @knife.should_receive(:show_usage)
36
+ @knife.ui.should_receive(:fatal)
37
+ lambda { @knife.run }.should raise_error(SystemExit)
38
+ end
39
+ end
@@ -0,0 +1,42 @@
1
+ #
2
+ # Author:: Steven Danna (<steve@opscode.com>)
3
+ # Copyright:: Copyright (c) 2012 Opscode, Inc
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'spec_helper'
20
+
21
+ describe Chef::Knife::UserEdit do
22
+ before(:each) do
23
+ Chef::Knife::UserEdit.load_deps
24
+ @knife = Chef::Knife::UserEdit.new
25
+ @knife.name_args = [ 'my_user' ]
26
+ @knife.config[:disable_editing] = true
27
+ end
28
+
29
+ it 'loads and edits the user' do
30
+ data = { :name => "my_user" }
31
+ Chef::User.stub(:load).with("my_user").and_return(data)
32
+ @knife.should_receive(:edit_data).with(data).and_return(data)
33
+ @knife.run
34
+ end
35
+
36
+ it 'prints usage and exits when a user name is not provided' do
37
+ @knife.name_args = []
38
+ @knife.should_receive(:show_usage)
39
+ @knife.ui.should_receive(:fatal)
40
+ lambda { @knife.run }.should raise_error(SystemExit)
41
+ end
42
+ end
@@ -0,0 +1,32 @@
1
+ #
2
+ # Author:: Steven Danna
3
+ # Copyright:: Copyright (c) 2012 Opscode, Inc
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'spec_helper'
20
+
21
+ describe Chef::Knife::UserList do
22
+ before(:each) do
23
+ Chef::Knife::UserList.load_deps
24
+ @knife = Chef::Knife::UserList.new
25
+ end
26
+
27
+ it 'lists the users' do
28
+ Chef::User.should_receive(:list)
29
+ @knife.should_receive(:format_list_for_display)
30
+ @knife.run
31
+ end
32
+ end
@@ -0,0 +1,53 @@
1
+ #
2
+ # Author:: Steven Danna (<steve@opscode.com>)
3
+ # Copyright:: Copyright (c) 2012 Opscode, Inc
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'spec_helper'
20
+
21
+ describe Chef::Knife::UserReregister do
22
+ before(:each) do
23
+ Chef::Knife::UserReregister.load_deps
24
+ @knife = Chef::Knife::UserReregister.new
25
+ @knife.name_args = [ 'a_user' ]
26
+ @user_mock = mock('user_mock', :private_key => "private_key")
27
+ Chef::User.stub!(:load).and_return(@user_mock)
28
+ @stdout = StringIO.new
29
+ @knife.ui.stub!(:stdout).and_return(@stdout)
30
+ end
31
+
32
+ it 'prints usage and exits when a user name is not provided' do
33
+ @knife.name_args = []
34
+ @knife.should_receive(:show_usage)
35
+ @knife.ui.should_receive(:fatal)
36
+ lambda { @knife.run }.should raise_error(SystemExit)
37
+ end
38
+
39
+ it 'reregisters the user and prints the key' do
40
+ @user_mock.should_receive(:reregister).and_return(@user_mock)
41
+ @knife.run
42
+ @stdout.string.should match( /private_key/ )
43
+ end
44
+
45
+ it 'writes the private key to a file when --file is specified' do
46
+ @user_mock.should_receive(:reregister).and_return(@user_mock)
47
+ @knife.config[:file] = '/tmp/a_file'
48
+ filehandle = StringIO.new
49
+ File.should_receive(:open).with('/tmp/a_file', 'w').and_yield(filehandle)
50
+ @knife.run
51
+ filehandle.string.should == "private_key"
52
+ end
53
+ end
@@ -0,0 +1,41 @@
1
+ #
2
+ # Author:: Steven Danna (<steve@opscode.com>)
3
+ # Copyright:: Copyright (c) 2012 Opscode, Inc
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'spec_helper'
20
+
21
+ describe Chef::Knife::UserShow do
22
+ before(:each) do
23
+ Chef::Knife::UserShow.load_deps
24
+ @knife = Chef::Knife::UserShow.new
25
+ @knife.name_args = [ 'my_user' ]
26
+ @user_mock = mock('user_mock')
27
+ end
28
+
29
+ it 'loads and displays the user' do
30
+ Chef::User.should_receive(:load).with('my_user').and_return(@user_mock)
31
+ @knife.should_receive(:format_for_display).with(@user_mock)
32
+ @knife.run
33
+ end
34
+
35
+ it 'prints usage and exits when a user name is not provided' do
36
+ @knife.name_args = []
37
+ @knife.should_receive(:show_usage)
38
+ @knife.ui.should_receive(:fatal)
39
+ lambda { @knife.run }.should raise_error(SystemExit)
40
+ end
41
+ end
@@ -40,6 +40,29 @@ describe Chef::Knife do
40
40
  @stdout = StringIO.new
41
41
  end
42
42
 
43
+ describe "selecting a config file" do
44
+ context "when the current working dir is inside a symlinked directory" do
45
+ before do
46
+ Chef::Knife.reset_config_path!
47
+ # pwd according to your shell is /home/someuser/prod/chef-repo, but
48
+ # chef-repo is a symlink to /home/someuser/codes/chef-repo
49
+ ENV.stub!(:[]).with("PWD").and_return("/home/someuser/prod/chef-repo")
50
+ Dir.stub!(:pwd).and_return("/home/someuser/codes/chef-repo")
51
+ end
52
+
53
+ after do
54
+ Chef::Knife.reset_config_path!
55
+ end
56
+
57
+ it "loads the config from the non-dereferenced directory path" do
58
+ File.should_receive(:exist?).with("/home/someuser/prod/chef-repo/.chef").and_return(false)
59
+ File.should_receive(:exist?).with("/home/someuser/prod/.chef").and_return(true)
60
+ File.should_receive(:directory?).with("/home/someuser/prod/.chef").and_return(true)
61
+ Chef::Knife.chef_config_dir.should == "/home/someuser/prod/.chef"
62
+ end
63
+ end
64
+ end
65
+
43
66
  describe "after loading a subcommand" do
44
67
  before do
45
68
  Chef::Knife.reset_subcommands!
@@ -157,6 +180,36 @@ describe Chef::Knife do
157
180
  lambda {Chef::Knife.run(%w{fuuu uuuu fuuuu})}.should raise_error(SystemExit) { |e| e.status.should_not == 0 }
158
181
  end
159
182
 
183
+ describe "merging configuration options" do
184
+ before do
185
+ KnifeSpecs::TestYourself.option(:opt_with_default,
186
+ :short => "-D VALUE",
187
+ :default => "default-value")
188
+ Chef::Config[:knife] = {}
189
+ end
190
+
191
+ it "prefers the default value if no config or command line value is present" do
192
+ knife_command = KnifeSpecs::TestYourself.new([]) #empty argv
193
+ knife_command.configure_chef
194
+ knife_command.config[:opt_with_default].should == "default-value"
195
+ end
196
+
197
+ it "prefers a value in Chef::Config[:knife] to the default" do
198
+ Chef::Config[:knife][:opt_with_default] = "from-knife-config"
199
+ knife_command = KnifeSpecs::TestYourself.new([]) #empty argv
200
+ knife_command.configure_chef
201
+ knife_command.config[:opt_with_default].should == "from-knife-config"
202
+ end
203
+
204
+ it "prefers a value from command line over Chef::Config and the default" do
205
+ Chef::Config[:knife][:opt_with_default] = "from-knife-config"
206
+ knife_command = KnifeSpecs::TestYourself.new(["-D", "from-cli"])
207
+ knife_command.configure_chef
208
+ knife_command.config[:opt_with_default].should == "from-cli"
209
+ end
210
+ end
211
+
212
+
160
213
  end
161
214
 
162
215
  describe "when first created" do
@@ -6,9 +6,9 @@
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
8
8
  # You may obtain a copy of the License at
9
- #
9
+ #
10
10
  # http://www.apache.org/licenses/LICENSE-2.0
11
- #
11
+ #
12
12
  # Unless required by applicable law or agreed to in writing, software
13
13
  # distributed under the License is distributed on an "AS IS" BASIS,
14
14
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -25,23 +25,23 @@ describe "override logging" do
25
25
 
26
26
  it "should log if attempting to load resource of same name" do
27
27
  Dir[File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "lwrp", "resources", "*"))].each do |file|
28
- Chef::Resource.build_from_file("lwrp", file, nil)
28
+ Chef::Resource::LWRPBase.build_from_file("lwrp", file, nil)
29
29
  end
30
30
 
31
31
  Dir[File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "lwrp_override", "resources", "*"))].each do |file|
32
32
  Chef::Log.should_receive(:info).with(/overriding/)
33
- Chef::Resource.build_from_file("lwrp", file, nil)
33
+ Chef::Resource::LWRPBase.build_from_file("lwrp", file, nil)
34
34
  end
35
35
  end
36
36
 
37
37
  it "should log if attempting to load provider of same name" do
38
38
  Dir[File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "lwrp", "providers", "*"))].each do |file|
39
- Chef::Provider.build_from_file("lwrp", file, nil)
39
+ Chef::Provider::LWRPBase.build_from_file("lwrp", file, nil)
40
40
  end
41
41
 
42
42
  Dir[File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "lwrp_override", "providers", "*"))].each do |file|
43
43
  Chef::Log.should_receive(:info).with(/overriding/)
44
- Chef::Provider.build_from_file("lwrp", file, nil)
44
+ Chef::Provider::LWRPBase.build_from_file("lwrp", file, nil)
45
45
  end
46
46
  end
47
47
 
@@ -61,11 +61,11 @@ describe "LWRP" do
61
61
 
62
62
  before do
63
63
  Dir[File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "lwrp", "resources", "*"))].each do |file|
64
- Chef::Resource.build_from_file("lwrp", file, nil)
64
+ Chef::Resource::LWRPBase.build_from_file("lwrp", file, nil)
65
65
  end
66
66
 
67
67
  Dir[File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "lwrp_override", "resources", "*"))].each do |file|
68
- Chef::Resource.build_from_file("lwrp", file, nil)
68
+ Chef::Resource::LWRPBase.build_from_file("lwrp", file, nil)
69
69
  end
70
70
  end
71
71
 
@@ -94,12 +94,12 @@ describe "LWRP" do
94
94
  end
95
95
 
96
96
  it "should have access to the run context and node during class definition" do
97
- node = Chef::Node.new(nil)
98
- node[:penguin_name] = "jackass"
97
+ node = Chef::Node.new
98
+ node.normal[:penguin_name] = "jackass"
99
99
  run_context = Chef::RunContext.new(node, Chef::CookbookCollection.new, @events)
100
100
 
101
101
  Dir[File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "lwrp", "resources_with_default_attributes", "*"))].each do |file|
102
- Chef::Resource.build_from_file("lwrp", file, run_context)
102
+ Chef::Resource::LWRPBase.build_from_file("lwrp", file, run_context)
103
103
  end
104
104
 
105
105
  cls = Chef::Resource.const_get("LwrpNodeattr")
@@ -113,8 +113,8 @@ describe "LWRP" do
113
113
  describe "Lightweight Chef::Provider" do
114
114
  before do
115
115
  @node = Chef::Node.new
116
- @node.platform(:ubuntu)
117
- @node.platform_version('8.10')
116
+ @node.automatic[:platform] = :ubuntu
117
+ @node.automatic[:platform_version] = '8.10'
118
118
  @events = Chef::EventDispatch::Dispatcher.new
119
119
  @run_context = Chef::RunContext.new(@node, Chef::CookbookCollection.new({}), @events)
120
120
  @runner = Chef::Runner.new(@run_context)
@@ -122,19 +122,19 @@ describe "LWRP" do
122
122
 
123
123
  before(:each) do
124
124
  Dir[File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "lwrp", "resources", "*"))].each do |file|
125
- Chef::Resource.build_from_file("lwrp", file, @run_context)
125
+ Chef::Resource::LWRPBase.build_from_file("lwrp", file, @run_context)
126
126
  end
127
127
 
128
128
  Dir[File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "lwrp_override", "resources", "*"))].each do |file|
129
- Chef::Resource.build_from_file("lwrp", file, @run_context)
129
+ Chef::Resource::LWRPBase.build_from_file("lwrp", file, @run_context)
130
130
  end
131
131
 
132
132
  Dir[File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "lwrp", "providers", "*"))].each do |file|
133
- Chef::Provider.build_from_file("lwrp", file, @run_context)
133
+ Chef::Provider::LWRPBase.build_from_file("lwrp", file, @run_context)
134
134
  end
135
135
 
136
136
  Dir[File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "lwrp_override", "providers", "*"))].each do |file|
137
- Chef::Provider.build_from_file("lwrp", file, @run_context)
137
+ Chef::Provider::LWRPBase.build_from_file("lwrp", file, @run_context)
138
138
  end
139
139
 
140
140
  end
@@ -226,6 +226,48 @@ describe "LWRP" do
226
226
  provider.enclosed_resource.monkey.should == 'bob, the monkey'
227
227
  end
228
228
 
229
+ describe "when using inline compilation" do
230
+ before do
231
+ # Behavior in these examples depends on implementation of fixture provider.
232
+ # See spec/data/lwrp/providers/inline_compiler
233
+
234
+ # Side effect of lwrp_inline_compiler provider for testing notifications.
235
+ $interior_ruby_block_2 = nil
236
+ # resource type doesn't matter, so make an existing resource type work with provider.
237
+ @resource = Chef::Resource::LwrpFoo.new("morpheus", @run_context)
238
+ @resource.allowed_actions << :test
239
+ @resource.action(:test)
240
+ @resource.provider(:lwrp_inline_compiler)
241
+ end
242
+
243
+ it "does not add interior resources to the exterior resource collection" do
244
+ @resource.run_action(:test)
245
+ @run_context.resource_collection.should be_empty
246
+ end
247
+
248
+ context "when interior resources are updated" do
249
+ it "processes notifications within the LWRP provider's action" do
250
+ @resource.run_action(:test)
251
+ $interior_ruby_block_2.should == "executed"
252
+ end
253
+
254
+ it "marks the parent resource updated" do
255
+ @resource.run_action(:test)
256
+ @resource.should be_updated
257
+ @resource.should be_updated_by_last_action
258
+ end
259
+ end
260
+
261
+ context "when interior resources are not updated" do
262
+ it "does not mark the parent resource updated" do
263
+ @resource.run_action(:no_updates)
264
+ @resource.should_not be_updated
265
+ @resource.should_not be_updated_by_last_action
266
+ end
267
+ end
268
+
269
+ end
270
+
229
271
  end
230
272
 
231
273
  end