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
@@ -2,10 +2,10 @@ require 'spec_helper'
2
2
 
3
3
  describe Chef::Knife::Configure do
4
4
  before do
5
- @original_config = Chef::Config.configuration.dup
6
-
7
5
  Chef::Log.logger = Logger.new(StringIO.new)
8
6
 
7
+ @original_config = Chef::Config.configuration.dup
8
+
9
9
  Chef::Config[:node_name] = "webmonkey.example.com"
10
10
  @knife = Chef::Knife::Configure.new
11
11
  @rest_client = mock("null rest client", :post_rest => { :result => :true })
@@ -41,7 +41,7 @@ describe Chef::Knife::Configure do
41
41
  @knife.config[:initial] = true
42
42
  Etc.stub!(:getlogin).and_return("a-new-user")
43
43
  @knife.ask_user_for_config
44
- @out.string.should match(Regexp.escape("Please enter a clientname for the new client: [a-new-user]"))
44
+ @out.string.should match(Regexp.escape("Please enter a name for the new user: [a-new-user]"))
45
45
  @knife.new_client_name.should == Etc.getlogin
46
46
  end
47
47
 
@@ -50,7 +50,7 @@ describe Chef::Knife::Configure do
50
50
  @knife.config[:node_name] = 'testnode'
51
51
  Etc.stub!(:getlogin).and_return("a-new-user")
52
52
  @knife.ask_user_for_config
53
- @out.string.should_not match(Regexp.escape("Please enter a clientname for the new client"))
53
+ @out.string.should_not match(Regexp.escape("Please enter a name for the new user"))
54
54
  @knife.new_client_name.should == 'testnode'
55
55
  end
56
56
 
@@ -64,32 +64,32 @@ describe Chef::Knife::Configure do
64
64
  it "asks the user for the existing admin client's name if -i is specified" do
65
65
  @knife.config[:initial] = true
66
66
  @knife.ask_user_for_config
67
- @out.string.should match(Regexp.escape("Please enter the existing admin clientname: [chef-webui]"))
68
- @knife.admin_client_name.should == 'chef-webui'
67
+ @out.string.should match(Regexp.escape("Please enter the existing admin name: [admin]"))
68
+ @knife.admin_client_name.should == 'admin'
69
69
  end
70
70
 
71
71
  it "should not ask the user for the existing admin client's name if -i and --admin-client_name are specified" do
72
72
  @knife.config[:initial] = true
73
73
  @knife.config[:admin_client_name] = 'my-webui'
74
74
  @knife.ask_user_for_config
75
- @out.string.should_not match(Regexp.escape("Please enter the existing admin clientname:"))
75
+ @out.string.should_not match(Regexp.escape("Please enter the existing admin:"))
76
76
  @knife.admin_client_name.should == 'my-webui'
77
77
  end
78
78
 
79
79
  it "should not ask the user for the existing admin client's name if -i is not specified" do
80
80
  @knife.ask_user_for_config
81
- @out.string.should_not match(Regexp.escape("Please enter the existing admin clientname: [chef-webui]"))
82
- @knife.admin_client_name.should_not == 'chef-webui'
81
+ @out.string.should_not match(Regexp.escape("Please enter the existing admin: [admin]"))
82
+ @knife.admin_client_name.should_not == 'admin'
83
83
  end
84
84
 
85
85
  it "asks the user for the location of the existing admin key if -i is specified" do
86
86
  @knife.config[:initial] = true
87
87
  @knife.ask_user_for_config
88
- @out.string.should match(Regexp.escape("Please enter the location of the existing admin client's private key: [/etc/chef/webui.pem]"))
88
+ @out.string.should match(Regexp.escape("Please enter the location of the existing admin's private key: [/etc/chef/admin.pem]"))
89
89
  if windows?
90
- @knife.admin_client_key.should == 'C:/etc/chef/webui.pem'
90
+ @knife.admin_client_key.should == 'C:/etc/chef/admin.pem'
91
91
  else
92
- @knife.admin_client_key.should == '/etc/chef/webui.pem'
92
+ @knife.admin_client_key.should == '/etc/chef/admin.pem'
93
93
  end
94
94
  end
95
95
 
@@ -111,7 +111,7 @@ describe Chef::Knife::Configure do
111
111
  if windows?
112
112
  @knife.admin_client_key.should_not == 'C:/etc//chef/webui.pem'
113
113
  else
114
- @knife.admin_client_key.should_not == '/etc/chef/webui.pem'
114
+ @knife.admin_client_key.should_not == '/etc/chef/webui.pem'
115
115
  end
116
116
  end
117
117
 
@@ -140,7 +140,7 @@ describe Chef::Knife::Configure do
140
140
  if windows?
141
141
  @knife.validation_key.should == 'C:/etc/chef/validation.pem'
142
142
  else
143
- @knife.validation_key.should == '/etc/chef/validation.pem'
143
+ @knife.validation_key.should == '/etc/chef/validation.pem'
144
144
  end
145
145
  end
146
146
 
@@ -205,25 +205,28 @@ describe Chef::Knife::Configure do
205
205
  end
206
206
 
207
207
  it "creates a new client when given the --initial option" do
208
- File.stub!(:expand_path).with("/home/you/.chef/knife.rb").and_return("/home/you/.chef/knife.rb")
209
- File.stub!(:expand_path).with("/home/you/.chef/a-new-user.pem").and_return("/home/you/.chef/a-new-user.pem")
210
- File.stub!(:expand_path).with("/etc/chef/validation.pem").and_return("/etc/chef/validation.pem")
211
- File.stub!(:expand_path).with("/etc/chef/webui.pem").and_return("/etc/chef/webui.pem")
208
+ File.should_receive(:expand_path).with("/home/you/.chef/knife.rb").and_return("/home/you/.chef/knife.rb")
209
+ File.should_receive(:expand_path).with("/home/you/.chef/a-new-user.pem").and_return("/home/you/.chef/a-new-user.pem")
210
+ File.should_receive(:expand_path).with("/etc/chef/validation.pem").and_return("/etc/chef/validation.pem")
211
+ File.should_receive(:expand_path).with("/etc/chef/admin.pem").and_return("/etc/chef/admin.pem")
212
212
  Chef::Config[:node_name] = "webmonkey.example.com"
213
- client_command = Chef::Knife::ClientCreate.new
214
- client_command.should_receive(:run)
213
+
214
+ user_command = Chef::Knife::UserCreate.new
215
+ user_command.should_receive(:run)
215
216
 
216
217
  Etc.stub!(:getlogin).and_return("a-new-user")
217
218
 
218
- Chef::Knife::ClientCreate.stub!(:new).and_return(client_command)
219
+ Chef::Knife::UserCreate.stub!(:new).and_return(user_command)
219
220
  FileUtils.should_receive(:mkdir_p).with("/home/you/.chef")
220
221
  ::File.should_receive(:open).with("/home/you/.chef/knife.rb", "w")
221
222
  @knife.config[:initial] = true
223
+ @knife.config[:user_password] = "blah"
222
224
  @knife.run
223
- client_command.name_args.should == Array("a-new-user")
224
- client_command.config[:admin].should be_true
225
- client_command.config[:file].should == "/home/you/.chef/a-new-user.pem"
226
- client_command.config[:yes].should be_true
227
- client_command.config[:disable_editing].should be_true
225
+ user_command.name_args.should == Array("a-new-user")
226
+ user_command.config[:user_password].should == "blah"
227
+ user_command.config[:admin].should be_true
228
+ user_command.config[:file].should == "/home/you/.chef/a-new-user.pem"
229
+ user_command.config[:yes].should be_true
230
+ user_command.config[:disable_editing].should be_true
228
231
  end
229
232
  end
@@ -51,22 +51,29 @@ describe Chef::Knife::CookbookMetadata do
51
51
  describe 'with -a or --all' do
52
52
  before(:each) do
53
53
  @knife.config[:all] = true
54
+ @foo = Chef::CookbookVersion.new('foo')
55
+ @foo.version = '1.0.0'
56
+ @bar = Chef::CookbookVersion.new('bar')
57
+ @bar.version = '2.0.0'
58
+ @cookbook_loader = {
59
+ "foo" => @foo,
60
+ "bar" => @bar
61
+ }
62
+ @cookbook_loader.should_receive(:load_cookbooks).and_return(@cookbook_loader)
54
63
  @knife.should_receive(:generate_metadata).with('foo')
55
64
  @knife.should_receive(:generate_metadata).with('bar')
56
65
  end
57
66
 
58
67
  it 'should generate the metadata for each cookbook' do
59
68
  Chef::Config[:cookbook_path] = @cookbook_dir
60
- Chef::CookbookLoader.should_receive(:new).with(@cookbook_dir).
61
- and_return({'foo' => '1.0.0', 'bar' => '2.0.0'})
69
+ Chef::CookbookLoader.should_receive(:new).with(@cookbook_dir).and_return(@cookbook_loader)
62
70
  @knife.run
63
71
  end
64
72
 
65
73
  describe 'and with -o or --cookbook-path' do
66
74
  it 'should look in the provided path and generate cookbook metadata' do
67
75
  @knife.config[:cookbook_path] = '/opt/chef/cookbooks'
68
- Chef::CookbookLoader.should_receive(:new).with('/opt/chef/cookbooks').
69
- and_return({'foo' => '1.0.0', 'bar' => '2.0.0'})
76
+ Chef::CookbookLoader.should_receive(:new).with('/opt/chef/cookbooks').and_return(@cookbook_loader)
70
77
  @knife.run
71
78
  end
72
79
  end
@@ -60,7 +60,6 @@ describe Chef::Knife::CookbookSiteInstall do
60
60
 
61
61
 
62
62
  describe "run" do
63
-
64
63
  it "should return an error if a cookbook name is not provided" do
65
64
  @knife.name_args = []
66
65
  @knife.ui.should_receive(:error).with("Please specify a cookbook to download and install.")
@@ -91,7 +90,6 @@ describe Chef::Knife::CookbookSiteInstall do
91
90
  lambda { @knife.run }.should raise_error(SystemExit)
92
91
  end
93
92
 
94
-
95
93
  it "should install the specified version if second argument is a three-digit version" do
96
94
  @knife.name_args = ["getting-started", "0.1.0"]
97
95
  @knife.config[:no_deps] = true
@@ -134,5 +132,17 @@ describe Chef::Knife::CookbookSiteInstall do
134
132
  @repo.should_not_receive(:reset_to_default_state)
135
133
  @knife.run
136
134
  end
135
+
136
+ it "should not raise an error if cookbook_path is a string" do
137
+ @knife.config[:cookbook_path] = @install_path
138
+ @knife.config[:no_deps] = true
139
+ @knife.name_args = ["getting-started"]
140
+ upstream_file = File.join(@install_path, "getting-started.tar.gz")
141
+ @knife.should_receive(:download_cookbook_to).with(upstream_file)
142
+ @knife.should_receive(:extract_cookbook).with(upstream_file, "0.3.0")
143
+ @knife.should_receive(:clear_existing_files).with(File.join(@install_path, "getting-started"))
144
+ @repo.should_receive(:merge_updates_from).with("getting-started", "0.3.0")
145
+ lambda { @knife.run }.should_not raise_error
146
+ end
137
147
  end
138
148
  end
@@ -68,6 +68,7 @@ describe Chef::Knife::CookbookTest do
68
68
  @knife.stub!(:test_cookbook).and_return(true)
69
69
  @knife.config[:all] = true
70
70
  @loader = {}
71
+ @loader.stub!(:load_cookbooks).and_return(@loader)
71
72
  @cookbooks.each do |cookbook|
72
73
  @loader[cookbook.name] = cookbook
73
74
  end
@@ -32,6 +32,7 @@ describe Chef::Knife::CookbookUpload do
32
32
  @cookbook_loader = {}
33
33
  @cookbook_loader.stub!(:[]).and_return(@cookbook)
34
34
  @cookbook_loader.stub!(:merged_cookbooks).and_return([])
35
+ @cookbook_loader.stub!(:load_cookbooks).and_return(@cookbook_loader)
35
36
  Chef::CookbookLoader.stub!(:new).and_return(@cookbook_loader)
36
37
 
37
38
  @output = StringIO.new
@@ -65,6 +66,44 @@ describe Chef::Knife::CookbookUpload do
65
66
  end
66
67
  end
67
68
 
69
+ describe 'when specifying the same cookbook name twice' do
70
+ it 'should upload the cookbook only once' do
71
+ @knife.name_args = ['test_cookbook', 'test_cookbook']
72
+ @knife.should_receive(:upload).once
73
+ @knife.run
74
+ end
75
+ end
76
+
77
+ describe 'when specifying a cookbook name among many' do
78
+ before(:each) do
79
+ @knife.name_args = ['test_cookbook1']
80
+ @cookbooks = {
81
+ 'test_cookbook1' => Chef::CookbookVersion.new('test_cookbook1'),
82
+ 'test_cookbook2' => Chef::CookbookVersion.new('test_cookbook2'),
83
+ 'test_cookbook3' => Chef::CookbookVersion.new('test_cookbook3')
84
+ }
85
+ @cookbook_loader = {}
86
+ @cookbook_loader.stub!(:merged_cookbooks).and_return([])
87
+ @cookbook_loader.stub(:[]) { |ckbk| @cookbooks[ckbk] }
88
+ Chef::CookbookLoader.stub!(:new).and_return(@cookbook_loader)
89
+ end
90
+
91
+ it "should read only one cookbook" do
92
+ @cookbook_loader.should_receive(:[]).once.with('test_cookbook1')
93
+ @knife.run
94
+ end
95
+
96
+ it "should not read all cookbooks" do
97
+ @cookbook_loader.should_not_receive(:load_cookbooks)
98
+ @knife.run
99
+ end
100
+
101
+ it "should upload only one cookbook" do
102
+ @knife.should_receive(:upload).exactly(1).times
103
+ @knife.run
104
+ end
105
+ end
106
+
68
107
  # This is testing too much. We should break it up.
69
108
  describe 'when specifying a cookbook name with dependencies' do
70
109
  it "should upload all dependencies once" do
@@ -140,5 +179,5 @@ describe Chef::Knife::CookbookUpload do
140
179
  lambda { @knife.run }.should raise_error(SystemExit)
141
180
  end
142
181
  end
143
- end
144
- end # run
182
+ end # run
183
+ end # Chef::Knife::CookbookUpload
@@ -56,9 +56,16 @@ describe Chef::Knife::Core::BootstrapContext do
56
56
  @context.validation_key.should == IO.read(File.join(CHEF_SPEC_DATA, 'ssl', 'private_key.pem'))
57
57
  end
58
58
 
59
+ it "reads the validation key when it contains a ~" do
60
+ IO.should_receive(:read).with(File.expand_path("my.key", ENV['HOME']))
61
+ @chef_config = {:validation_key => '~/my.key'}
62
+ @context = Chef::Knife::Core::BootstrapContext.new(@config, @run_list, @chef_config)
63
+ @context.validation_key
64
+ end
65
+
59
66
  it "generates the config file data" do
60
67
  expected=<<-EXPECTED
61
- log_level :info
68
+ log_level :auto
62
69
  log_location STDOUT
63
70
  chef_server_url "http://chef.example.com:4444"
64
71
  validation_client_name "chef-validator-testing"
@@ -2,7 +2,8 @@
2
2
  # Author:: Adam Jacob (<adam@opscode.com>)
3
3
  # Author:: Tim Hinderliter (<tim@opscode.com>)
4
4
  # Author:: Daniel DeLeo (<dan@opscode.com>)
5
- # Copyright:: Copyright (c) 2008, 2011 Opscode, Inc.
5
+ # Author:: John Keiser (<jkeiser@opscode.com>)
6
+ # Copyright:: Copyright (c) 2008, 2011, 2012 Opscode, Inc.
6
7
  # License:: Apache License, Version 2.0
7
8
  #
8
9
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -39,6 +40,153 @@ describe Chef::Knife::UI do
39
40
  end
40
41
  end
41
42
 
43
+ describe "output" do
44
+ it "formats strings appropriately" do
45
+ @ui.output("hi")
46
+ @out.string.should == "hi\n"
47
+ end
48
+
49
+ it "formats hashes appropriately" do
50
+ @ui.output({'hi' => 'a', 'lo' => 'b' })
51
+ @out.string.should == <<EOM
52
+ hi: a
53
+ lo: b
54
+ EOM
55
+ end
56
+
57
+ it "formats empty hashes appropriately" do
58
+ @ui.output({})
59
+ @out.string.should == "\n"
60
+ end
61
+
62
+ it "formats arrays appropriately" do
63
+ @ui.output([ 'a', 'b' ])
64
+ @out.string.should == <<EOM
65
+ a
66
+ b
67
+ EOM
68
+ end
69
+
70
+ it "formats empty arrays appropriately" do
71
+ @ui.output([ ])
72
+ @out.string.should == "\n"
73
+ end
74
+
75
+ it "formats single-member arrays appropriately" do
76
+ @ui.output([ 'a' ])
77
+ @out.string.should == "a\n"
78
+ end
79
+
80
+ it "formats nested single-member arrays appropriately" do
81
+ @ui.output([ [ 'a' ] ])
82
+ @out.string.should == "a\n"
83
+ end
84
+
85
+ it "formats nested arrays appropriately" do
86
+ @ui.output([ [ 'a', 'b' ], [ 'c', 'd' ]])
87
+ @out.string.should == <<EOM
88
+ a
89
+ b
90
+
91
+ c
92
+ d
93
+ EOM
94
+ end
95
+
96
+ it "formats nested arrays with single- and empty subarrays appropriately" do
97
+ @ui.output([ [ 'a', 'b' ], [ 'c' ], [], [ 'd', 'e' ]])
98
+ @out.string.should == <<EOM
99
+ a
100
+ b
101
+
102
+ c
103
+
104
+
105
+ d
106
+ e
107
+ EOM
108
+ end
109
+
110
+ it "formats arrays of hashes with extra lines in between for readability" do
111
+ @ui.output([ { 'a' => 'b', 'c' => 'd' }, { 'x' => 'y' }, { 'm' => 'n', 'o' => 'p' }])
112
+ @out.string.should == <<EOM
113
+ a: b
114
+ c: d
115
+
116
+ x: y
117
+
118
+ m: n
119
+ o: p
120
+ EOM
121
+ end
122
+
123
+ it "formats hashes with empty array members appropriately" do
124
+ @ui.output({ 'a' => [], 'b' => 'c' })
125
+ @out.string.should == <<EOM
126
+ a:
127
+ b: c
128
+ EOM
129
+ end
130
+
131
+ it "formats hashes with single-member array values appropriately" do
132
+ @ui.output({ 'a' => [ 'foo' ], 'b' => 'c' })
133
+ @out.string.should == <<EOM
134
+ a: foo
135
+ b: c
136
+ EOM
137
+ end
138
+
139
+ it "formats hashes with array members appropriately" do
140
+ @ui.output({ 'a' => [ 'foo', 'bar' ], 'b' => 'c' })
141
+ @out.string.should == <<EOM
142
+ a:
143
+ foo
144
+ bar
145
+ b: c
146
+ EOM
147
+ end
148
+
149
+ it "formats hashes with single-member nested array values appropriately" do
150
+ @ui.output({ 'a' => [ [ 'foo' ] ], 'b' => 'c' })
151
+ @out.string.should == <<EOM
152
+ a:
153
+ foo
154
+ b: c
155
+ EOM
156
+ end
157
+
158
+ it "formats hashes with nested array values appropriately" do
159
+ @ui.output({ 'a' => [ [ 'foo', 'bar' ], [ 'baz', 'bjork' ] ], 'b' => 'c' })
160
+ @out.string.should == <<EOM
161
+ a:
162
+ foo
163
+ bar
164
+
165
+ baz
166
+ bjork
167
+ b: c
168
+ EOM
169
+ end
170
+
171
+ it "formats hashes with hash values appropriately" do
172
+ @ui.output({ 'a' => { 'aa' => 'bb', 'cc' => 'dd' }, 'b' => 'c' })
173
+ @out.string.should == <<EOM
174
+ a:
175
+ aa: bb
176
+ cc: dd
177
+ b: c
178
+ EOM
179
+ end
180
+
181
+ it "formats hashes with empty hash values appropriately" do
182
+ @ui.output({ 'a' => { }, 'b' => 'c' })
183
+ @out.string.should == <<EOM
184
+ a:
185
+ b: c
186
+ EOM
187
+ end
188
+ end
189
+
42
190
  describe "format_for_display" do
43
191
  it "should return the raw data" do
44
192
  input = { :gi => :go }
@@ -47,20 +195,21 @@ describe Chef::Knife::UI do
47
195
 
48
196
  describe "with --attribute passed" do
49
197
  it "should return the deeply nested attribute" do
50
- input = { "gi" => { "go" => "ge" } }
198
+ input = { "gi" => { "go" => "ge" }, "id" => "sample-data-bag-item" }
51
199
  @ui.config[:attribute] = "gi.go"
52
- @ui.format_for_display(input).should == { "gi.go" => "ge" }
200
+ @ui.format_for_display(input).should == { "sample-data-bag-item" => { "gi.go" => "ge" } }
53
201
  end
54
202
  end
55
203
 
56
204
  describe "with --run-list passed" do
57
205
  it "should return the run list" do
58
206
  input = Chef::Node.new
207
+ input.name("sample-node")
59
208
  input.run_list("role[monkey]", "role[churchmouse]")
60
209
  @ui.config[:run_list] = true
61
210
  response = @ui.format_for_display(input)
62
- response["run_list"][0].should == "role[monkey]"
63
- response["run_list"][1].should == "role[churchmouse]"
211
+ response["sample-node"]["run_list"][0].should == "role[monkey]"
212
+ response["sample-node"]["run_list"][1].should == "role[churchmouse]"
64
213
  end
65
214
  end
66
215
  end
@@ -89,8 +238,8 @@ describe Chef::Knife::UI do
89
238
  it "should return the URIs" do
90
239
  response = {
91
240
  "cookbook_name"=>{
92
- "1.0.0" => "http://url/cookbooks/1.0.0",
93
- "2.0.0" => "http://url/cookbooks/2.0.0",
241
+ "1.0.0" => "http://url/cookbooks/1.0.0",
242
+ "2.0.0" => "http://url/cookbooks/2.0.0",
94
243
  "3.0.0" => "http://url/cookbooks/3.0.0"}
95
244
  }
96
245
  @ui.config[:with_uri] = true