microwave 1.0.4 → 11.400.2

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -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.
@@ -26,158 +26,211 @@ describe Chef::ApiClient do
26
26
  @client = Chef::ApiClient.new
27
27
  end
28
28
 
29
- describe "initialize" do
30
- it "should be a Chef::ApiClient" do
31
- @client.should be_a_kind_of(Chef::ApiClient)
32
- end
29
+ it "has a name attribute" do
30
+ @client.name("ops_master")
31
+ @client.name.should == "ops_master"
32
+ end
33
+
34
+ it "does not allow spaces in the name" do
35
+ lambda { @client.name "ops master" }.should raise_error(ArgumentError)
36
+ end
37
+
38
+ it "only allows string values for the name" do
39
+ lambda { @client.name Hash.new }.should raise_error(ArgumentError)
40
+ end
41
+
42
+ it "has an admin flag attribute" do
43
+ @client.admin(true)
44
+ @client.admin.should be_true
45
+ end
46
+
47
+ it "defaults to non-admin" do
48
+ @client.admin.should be_false
49
+ end
50
+
51
+ it "allows only boolean values for the admin flag" do
52
+ lambda { @client.admin(false) }.should_not raise_error
53
+ lambda { @client.admin(Hash.new) }.should raise_error(ArgumentError)
33
54
  end
34
55
 
35
- describe "name" do
36
- it "should let you set the name to a string" do
37
- @client.name("ops_master").should == "ops_master"
38
- end
39
56
 
40
- it "should return the current name" do
41
- @client.name "ops_master"
42
- @client.name.should == "ops_master"
57
+ it "has a public key attribute" do
58
+ @client.public_key("super public")
59
+ @client.public_key.should == "super public"
60
+ end
61
+
62
+ it "accepts only String values for the public key" do
63
+ lambda { @client.public_key "" }.should_not raise_error
64
+ lambda { @client.public_key Hash.new }.should raise_error(ArgumentError)
65
+ end
66
+
67
+
68
+ it "has a private key attribute" do
69
+ @client.private_key("super private")
70
+ @client.private_key.should == "super private"
71
+ end
72
+
73
+ it "accepts only String values for the private key" do
74
+ lambda { @client.private_key "" }.should_not raise_error
75
+ lambda { @client.private_key Hash.new }.should raise_error(ArgumentError)
76
+ end
77
+
78
+ describe "when serializing to JSON" do
79
+ before(:each) do
80
+ @client.name("black")
81
+ @client.public_key("crowes")
82
+ @json = @client.to_json
43
83
  end
44
84
 
45
- it "should not accept spaces" do
46
- lambda { @client.name "ops master" }.should raise_error(ArgumentError)
85
+ it "serializes as a JSON object" do
86
+ @json.should match(/^\{.+\}$/)
47
87
  end
48
88
 
49
- it "should throw an ArgumentError if you feed it anything but a string" do
50
- lambda { @client.name Hash.new }.should raise_error(ArgumentError)
89
+ it "includes the name value" do
90
+ @json.should include(%q{"name":"black"})
51
91
  end
52
- end
53
92
 
54
- describe "admin" do
55
- it "should let you set the admin bit" do
56
- @client.admin(true).should == true
93
+ it "includes the public key value" do
94
+ @json.should include(%{"public_key":"crowes"})
57
95
  end
58
96
 
59
- it "should return the current admin value" do
60
- @client.admin true
61
- @client.admin.should == true
97
+ it "includes the 'admin' flag" do
98
+ @json.should include(%q{"admin":false})
62
99
  end
63
100
 
64
- it "should default to false" do
65
- @client.admin.should == false
101
+ it "includes the private key when present" do
102
+ @client.private_key("monkeypants")
103
+ @client.to_json.should include(%q{"private_key":"monkeypants"})
66
104
  end
67
105
 
68
- it "should throw an ArgumentError if you feed it anything but true or false" do
69
- lambda { @client.name Hash.new }.should raise_error(ArgumentError)
106
+ it "does not include the private key if not present" do
107
+ @json.should_not include("private_key")
70
108
  end
71
109
  end
72
110
 
73
- describe "public_key" do
74
- it "should let you set the public key" do
75
- @client.public_key("super public").should == "super public"
111
+ describe "when deserializing from JSON" do
112
+ before(:each) do
113
+ client = {
114
+ "name" => "black",
115
+ "public_key" => "crowes",
116
+ "private_key" => "monkeypants",
117
+ "admin" => true,
118
+ "json_class" => "Chef::ApiClient"
119
+ }
120
+ @client = Chef::JSONCompat.from_json(client.to_json)
76
121
  end
77
122
 
78
- it "should return the current public key" do
79
- @client.public_key("super public")
80
- @client.public_key.should == "super public"
123
+ it "should deserialize to a Chef::ApiClient object" do
124
+ @client.should be_a_kind_of(Chef::ApiClient)
81
125
  end
82
126
 
83
- it "should throw an ArgumentError if you feed it something lame" do
84
- lambda { @client.public_key Hash.new }.should raise_error(ArgumentError)
85
- end
86
- end
127
+ it "preserves the name" do
128
+ @client.name.should == "black"
129
+ end
130
+
131
+ it "preserves the public key" do
132
+ @client.public_key.should == "crowes"
133
+ end
87
134
 
88
- describe "private_key" do
89
- it "should let you set the private key" do
90
- @client.private_key("super private").should == "super private"
135
+ it "preserves the admin status" do
136
+ @client.admin.should be_true
91
137
  end
92
138
 
93
- it "should return the private key" do
94
- @client.private_key("super private")
95
- @client.private_key.should == "super private"
139
+ it "includes the private key if present" do
140
+ @client.private_key.should == "monkeypants"
96
141
  end
97
142
 
98
- it "should throw an ArgumentError if you feed it something lame" do
99
- lambda { @client.private_key Hash.new }.should raise_error(ArgumentError)
100
- end
101
143
  end
102
144
 
103
- describe "create_keys" do
104
- before(:each) do
105
- Chef::Certificate.stub!(:gen_keypair).and_return(["cert", "key"])
145
+ describe "with correctly configured API credentials" do
146
+ before do
147
+ Chef::Config[:node_name] = "silent-bob"
148
+ Chef::Config[:client_key] = File.expand_path('ssl/private_key.pem', CHEF_SPEC_DATA)
106
149
  end
107
150
 
108
- it "should create a certificate based on the client name" do
109
- Chef::Certificate.should_receive(:gen_keypair).with(@client.name)
110
- @client.create_keys
151
+ after do
152
+ Chef::Config[:node_name] = nil
153
+ Chef::Config[:client_key] = nil
111
154
  end
112
155
 
113
- it "should set the private key" do
114
- @client.create_keys
115
- @client.private_key.should == "key"
156
+ let :private_key_data do
157
+ File.open(Chef::Config[:client_key], "r") {|f| f.read.chomp }
116
158
  end
117
159
 
118
- it "should set the public key" do
119
- @client.create_keys
120
- @client.public_key.should == "cert"
160
+ it "has an HTTP client configured with default credentials" do
161
+ @client.http_api.should be_a_kind_of(Chef::REST)
162
+ @client.http_api.client_name.should == "silent-bob"
163
+ @client.http_api.signing_key.to_s.should == private_key_data
121
164
  end
122
165
  end
123
166
 
124
- describe "serialize" do
125
- before(:each) do
126
- @client.name("black")
127
- @client.public_key("crowes")
128
- @client.private_key("monkeypants")
129
- @serial = @client.to_json
130
- end
131
167
 
132
- it "should serialize to a json hash" do
133
- @client.to_json.should match(/^\{.+\}$/)
168
+ describe "when requesting a new key" do
169
+ before do
170
+ @http_client = mock("Chef::REST mock")
171
+ Chef::REST.stub!(:new).and_return(@http_client)
134
172
  end
135
173
 
136
- %w{
137
- name
138
- public_key
139
- }.each do |t|
140
- it "should include '#{t}'" do
141
- @serial.should =~ /"#{t}":"#{@client.send(t.to_sym)}"/
174
+ context "and the client does not exist on the server" do
175
+ before do
176
+ @a_404_response = Net::HTTPNotFound.new("404 not found and such", nil, nil)
177
+ @a_404_exception = Net::HTTPServerException.new("404 not found exception", @a_404_response)
178
+
179
+ @http_client.should_receive(:get).with("clients/lost-my-key").and_raise(@a_404_exception)
142
180
  end
143
- end
144
181
 
145
- it "should include 'admin'" do
146
- @serial.should =~ /"admin":false/
182
+ it "raises a 404 error" do
183
+ lambda { Chef::ApiClient.reregister("lost-my-key") }.should raise_error(Net::HTTPServerException)
184
+ end
147
185
  end
148
186
 
149
- it "should not include the private key" do
150
- @serial.should_not =~ /"private_key":/
151
- end
152
- end
187
+ context "and the client exists" do
188
+ before do
189
+ @api_client_without_key = Chef::ApiClient.new
190
+ @api_client_without_key.name("lost-my-key")
191
+ @http_client.should_receive(:get).with("clients/lost-my-key").and_return(@api_client_without_key)
192
+ end
153
193
 
154
- describe "deserialize" do
155
- before(:each) do
156
- @client.name("black")
157
- @client.public_key("crowes")
158
- @client.private_key("monkeypants")
159
- @client.admin(true)
160
- @deserial = Chef::JSONCompat.from_json(@client.to_json)
161
- end
162
194
 
163
- it "should deserialize to a Chef::ApiClient object" do
164
- @deserial.should be_a_kind_of(Chef::ApiClient)
165
- end
195
+ context "and the client exists on a Chef 11-like server" do
196
+ before do
197
+ @api_client_with_key = Chef::ApiClient.new
198
+ @api_client_with_key.name("lost-my-key")
199
+ @api_client_with_key.private_key("the new private key")
200
+ @http_client.should_receive(:put).
201
+ with("clients/lost-my-key", :name => "lost-my-key", :admin => false, :private_key => true).
202
+ and_return(@api_client_with_key)
203
+ end
204
+
205
+ it "returns an ApiClient with a private key" do
206
+ response = Chef::ApiClient.reregister("lost-my-key")
207
+ # no sane == method for ApiClient :'(
208
+ response.should == @api_client_without_key
209
+ response.private_key.should == "the new private key"
210
+ response.name.should == "lost-my-key"
211
+ response.admin.should be_false
212
+ end
213
+ end
166
214
 
167
- %w{
168
- name
169
- public_key
170
- admin
171
- }.each do |t|
172
- it "should match '#{t}'" do
173
- @deserial.send(t.to_sym).should == @client.send(t.to_sym)
215
+ context "and the client exists on a Chef 10-like server" do
216
+ before do
217
+ @api_client_with_key = {"name" => "lost-my-key", "private_key" => "the new private key"}
218
+ @http_client.should_receive(:put).
219
+ with("clients/lost-my-key", :name => "lost-my-key", :admin => false, :private_key => true).
220
+ and_return(@api_client_with_key)
221
+ end
222
+
223
+ it "returns an ApiClient with a private key" do
224
+ response = Chef::ApiClient.reregister("lost-my-key")
225
+ # no sane == method for ApiClient :'(
226
+ response.should == @api_client_without_key
227
+ response.private_key.should == "the new private key"
228
+ response.name.should == "lost-my-key"
229
+ response.admin.should be_false
230
+ end
174
231
  end
175
- end
176
232
 
177
- it "should not include the private key" do
178
- @deserial.private_key.should == nil
179
233
  end
180
-
181
234
  end
182
235
  end
183
236
 
@@ -0,0 +1,84 @@
1
+ #
2
+ # Author:: Bryan W. Berry (<bryan.berry@gmail.com>)
3
+ # Copyright:: Copyright (c) 2012 Bryan W. Berry
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
+ require 'spec_helper'
19
+
20
+ describe Chef::Application::Apply do
21
+
22
+ before do
23
+ @original_config = Chef::Config.configuration
24
+ @app = Chef::Application::Recipe.new
25
+ @app.stub!(:configure_logging).and_return(true)
26
+ @recipe_text = "package 'nyancat'"
27
+ Chef::Config[:solo] = true
28
+ end
29
+
30
+ after do
31
+ Chef::Config[:solo] = nil
32
+ Chef::Config.configuration.replace(@original_config)
33
+ Chef::Config[:solo] = false
34
+ end
35
+
36
+
37
+ describe "configuring the application" do
38
+ it "should set solo mode to true" do
39
+ @app.reconfigure
40
+ Chef::Config[:solo].should be_true
41
+ end
42
+ end
43
+ describe "read_recipe_file" do
44
+ before do
45
+ @recipe_file_name = "foo.rb"
46
+ @recipe_path = File.expand_path("foo.rb")
47
+ @recipe_file = mock("Tempfile (mock)", :read => @recipe_text)
48
+ @app.stub!(:open).with(@recipe_path).and_return(@recipe_file)
49
+ File.stub!(:exist?).with("foo.rb").and_return(true)
50
+ Chef::Application.stub!(:fatal!).and_return(true)
51
+ end
52
+ it "should read text properly" do
53
+ @app.read_recipe_file(@recipe_file_name)[0].should == @recipe_text
54
+ end
55
+ it "should return a file_handle" do
56
+ @app.read_recipe_file(@recipe_file_name)[1].should be_instance_of(RSpec::Mocks::Mock)
57
+ end
58
+ describe "when recipe doesn't exist" do
59
+ before do
60
+ File.stub!(:exist?).with(@recipe_file_name).and_return(false)
61
+ end
62
+ it "should raise a fatal" do
63
+ Chef::Application.should_receive(:fatal!)
64
+ @app.read_recipe_file(@recipe_file_name)
65
+ end
66
+ end
67
+ end
68
+ describe "temp_recipe_file" do
69
+ before do
70
+ @app.instance_variable_set(:@recipe_text, @recipe_text)
71
+ @app.temp_recipe_file
72
+ @recipe_fh = @app.instance_variable_get(:@recipe_fh)
73
+ end
74
+ it "should open a tempfile" do
75
+ @recipe_fh.path.should match(/.*recipe-temporary-file.*/)
76
+ end
77
+ it "should write recipe text to the tempfile" do
78
+ @recipe_fh.read.should == @recipe_text
79
+ end
80
+ it "should save the filename for later use" do
81
+ @recipe_fh.path.should == @app.instance_variable_get(:@recipe_filename)
82
+ end
83
+ end
84
+ end
@@ -23,6 +23,11 @@ describe Chef::Application::Knife do
23
23
 
24
24
  before(:all) do
25
25
  class NoopKnifeCommand < Chef::Knife
26
+ option :opt_with_default,
27
+ :short => "-D VALUE",
28
+ :long => "-optwithdefault VALUE",
29
+ :default => "default-value"
30
+
26
31
  def run
27
32
  end
28
33
  end
@@ -20,12 +20,17 @@ require 'spec_helper'
20
20
 
21
21
  describe Chef::Application do
22
22
  before do
23
+ @original_conf = Chef::Config.configuration
23
24
  Chef::Log.logger = Logger.new(StringIO.new)
24
25
  @app = Chef::Application.new
25
26
  Dir.stub!(:chdir).and_return(0)
26
27
  @app.stub!(:reconfigure)
27
28
  end
28
29
 
30
+ after do
31
+ Chef::Config.configuration.replace(@original_conf)
32
+ end
33
+
29
34
  describe "reconfigure" do
30
35
  before do
31
36
  @app = Chef::Application.new
@@ -170,14 +175,14 @@ describe Chef::Application do
170
175
  end
171
176
  end
172
177
 
173
- describe "configure_logging" do
178
+ describe "when configuring the logger" do
174
179
  before do
175
180
  @app = Chef::Application.new
176
181
  Chef::Log.stub!(:init)
177
- Chef::Log.stub!(:level=)
178
182
  end
179
183
 
180
184
  it "should initialise the chef logger" do
185
+ Chef::Log.stub!(:level=)
181
186
  Chef::Log.should_receive(:init).with(Chef::Config[:log_location]).and_return(true)
182
187
  @app.configure_logging
183
188
  end
@@ -187,6 +192,56 @@ describe Chef::Application do
187
192
  @app.configure_logging
188
193
  end
189
194
 
195
+ context "and log_level is :auto" do
196
+ before do
197
+ Chef::Config[:log_level] = :auto
198
+ end
199
+
200
+ context "and STDOUT is to a tty" do
201
+ before do
202
+ STDOUT.stub!(:tty?).and_return(true)
203
+ end
204
+
205
+ it "configures the log level to :warn" do
206
+ @app.configure_logging
207
+ Chef::Log.level.should == :warn
208
+ end
209
+
210
+ context "and force_logger is configured" do
211
+ before do
212
+ Chef::Config[:force_logger] = true
213
+ end
214
+
215
+ it "configures the log level to info" do
216
+ @app.configure_logging
217
+ Chef::Log.level.should == :info
218
+ end
219
+ end
220
+ end
221
+
222
+ context "and STDOUT is not to a tty" do
223
+ before do
224
+ STDOUT.stub!(:tty?).and_return(false)
225
+ end
226
+
227
+ it "configures the log level to :info" do
228
+ @app.configure_logging
229
+ Chef::Log.level.should == :info
230
+ end
231
+
232
+ context "and force_formatter is configured" do
233
+ before do
234
+ Chef::Config[:force_formatter] = true
235
+ end
236
+ it "sets the log level to :warn" do
237
+ @app.configure_logging
238
+ Chef::Log.level.should == :warn
239
+ end
240
+ end
241
+ end
242
+
243
+
244
+ end
190
245
  end
191
246
 
192
247
  describe "class method: fatal!" do