chef 12.0.0.alpha.0 → 12.0.0.alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (207) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +3 -5
  3. data/lib/chef/api_client.rb +1 -1
  4. data/lib/chef/application.rb +16 -8
  5. data/lib/chef/chef_fs/chef_fs_data_store.rb +1 -1
  6. data/lib/chef/chef_fs/command_line.rb +1 -1
  7. data/lib/chef/chef_fs/file_system.rb +1 -1
  8. data/lib/chef/chef_fs/file_system/acl_entry.rb +1 -1
  9. data/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +3 -3
  10. data/lib/chef/chef_fs/file_system/cookbook_file.rb +2 -2
  11. data/lib/chef/chef_fs/file_system/rest_list_dir.rb +2 -2
  12. data/lib/chef/chef_fs/file_system/rest_list_entry.rb +4 -4
  13. data/lib/chef/config.rb +6 -5
  14. data/lib/chef/config_fetcher.rb +1 -1
  15. data/lib/chef/cookbook/cookbook_version_loader.rb +126 -43
  16. data/lib/chef/cookbook/metadata.rb +102 -53
  17. data/lib/chef/cookbook/syntax_check.rb +1 -1
  18. data/lib/chef/cookbook_loader.rb +62 -14
  19. data/lib/chef/cookbook_site_streaming_uploader.rb +12 -1
  20. data/lib/chef/cookbook_version.rb +13 -4
  21. data/lib/chef/data_bag.rb +28 -15
  22. data/lib/chef/data_bag_item.rb +5 -7
  23. data/lib/chef/digester.rb +5 -9
  24. data/lib/chef/dsl/recipe.rb +14 -0
  25. data/lib/chef/encrypted_data_bag_item.rb +1 -0
  26. data/lib/chef/encrypted_data_bag_item/assertions.rb +57 -0
  27. data/lib/chef/encrypted_data_bag_item/decryptor.rb +52 -28
  28. data/lib/chef/encrypted_data_bag_item/encrypted_data_bag_item_assertions.rb +37 -0
  29. data/lib/chef/encrypted_data_bag_item/encryption_failure.rb +22 -0
  30. data/lib/chef/encrypted_data_bag_item/encryptor.rb +79 -8
  31. data/lib/chef/environment.rb +1 -3
  32. data/lib/chef/exceptions.rb +18 -3
  33. data/lib/chef/formatters/base.rb +7 -0
  34. data/lib/chef/formatters/error_inspectors/cookbook_resolve_error_inspector.rb +1 -1
  35. data/lib/chef/handler/json_file.rb +0 -1
  36. data/lib/chef/http/json_output.rb +1 -1
  37. data/lib/chef/json_compat.rb +24 -6
  38. data/lib/chef/knife/bootstrap.rb +2 -2
  39. data/lib/chef/knife/client_delete.rb +1 -1
  40. data/lib/chef/knife/cookbook_site_download.rb +1 -1
  41. data/lib/chef/knife/cookbook_site_list.rb +1 -1
  42. data/lib/chef/knife/cookbook_site_search.rb +1 -1
  43. data/lib/chef/knife/cookbook_site_share.rb +2 -2
  44. data/lib/chef/knife/cookbook_site_show.rb +3 -3
  45. data/lib/chef/knife/cookbook_site_unshare.rb +1 -1
  46. data/lib/chef/knife/core/node_editor.rb +2 -3
  47. data/lib/chef/knife/core/ui.rb +2 -2
  48. data/lib/chef/knife/deps.rb +2 -3
  49. data/lib/chef/mixin/shell_out.rb +1 -1
  50. data/lib/chef/mixin/windows_architecture_helper.rb +1 -0
  51. data/lib/chef/node.rb +1 -2
  52. data/lib/chef/platform/provider_mapping.rb +33 -6
  53. data/lib/chef/provider.rb +0 -2
  54. data/lib/chef/provider/cookbook_file/content.rb +1 -1
  55. data/lib/chef/provider/cron.rb +11 -0
  56. data/lib/chef/provider/deploy.rb +3 -2
  57. data/lib/chef/provider/deploy/revision.rb +2 -2
  58. data/lib/chef/provider/env.rb +1 -1
  59. data/lib/chef/provider/env/windows.rb +5 -9
  60. data/lib/chef/provider/file.rb +84 -33
  61. data/lib/chef/provider/git.rb +2 -1
  62. data/lib/chef/provider/group/aix.rb +17 -2
  63. data/lib/chef/provider/group/dscl.rb +27 -9
  64. data/lib/chef/provider/group/pw.rb +8 -1
  65. data/lib/chef/provider/http_request.rb +4 -4
  66. data/lib/chef/provider/log.rb +4 -14
  67. data/lib/chef/provider/mount/mount.rb +2 -2
  68. data/lib/chef/provider/package/ips.rb +17 -23
  69. data/lib/chef/provider/package/paludis.rb +2 -2
  70. data/lib/chef/provider/package/rpm.rb +2 -2
  71. data/lib/chef/provider/package/rubygems.rb +2 -0
  72. data/lib/chef/provider/package/yum.rb +2 -0
  73. data/lib/chef/provider/package/zypper.rb +1 -1
  74. data/lib/chef/provider/remote_file/cache_control_data.rb +2 -2
  75. data/lib/chef/provider/service/windows.rb +87 -21
  76. data/lib/chef/provider/user/aix.rb +95 -0
  77. data/lib/chef/provider/user/dscl.rb +544 -156
  78. data/lib/chef/provider/user/useradd.rb +1 -0
  79. data/lib/chef/providers.rb +1 -0
  80. data/lib/chef/resource.rb +4 -3
  81. data/lib/chef/resource/freebsd_package.rb +10 -2
  82. data/lib/chef/resource/paludis_package.rb +1 -0
  83. data/lib/chef/resource/scm.rb +10 -0
  84. data/lib/chef/resource/user.rb +27 -0
  85. data/lib/chef/resource/windows_service.rb +53 -0
  86. data/lib/chef/resource_collection.rb +23 -12
  87. data/lib/chef/resource_reporter.rb +10 -10
  88. data/lib/chef/resources.rb +1 -0
  89. data/lib/chef/role.rb +3 -3
  90. data/lib/chef/run_list.rb +6 -3
  91. data/lib/chef/user.rb +1 -1
  92. data/lib/chef/util/diff.rb +1 -2
  93. data/lib/chef/version.rb +1 -1
  94. data/lib/chef/version_constraint.rb +4 -4
  95. data/spec/data/cookbooks/angrybash/metadata.rb +2 -0
  96. data/spec/data/cookbooks/apache2/metadata.rb +2 -0
  97. data/spec/data/cookbooks/borken/metadata.rb +2 -0
  98. data/spec/data/cookbooks/ignorken/metadata.rb +2 -0
  99. data/spec/data/cookbooks/java/metadata.rb +2 -0
  100. data/spec/data/cookbooks/name-mismatch-versionnumber/README.md +4 -0
  101. data/spec/data/cookbooks/name-mismatch-versionnumber/metadata.rb +8 -0
  102. data/spec/data/cookbooks/name-mismatch-versionnumber/recipes/default.rb +8 -0
  103. data/spec/data/cookbooks/openldap/files/default/remotedir/not_a_template.erb +2 -0
  104. data/spec/data/cookbooks/preseed/metadata.rb +2 -0
  105. data/spec/data/incomplete-metadata-chef-repo/incomplete-metadata/README.md +4 -0
  106. data/spec/data/incomplete-metadata-chef-repo/incomplete-metadata/metadata.rb +13 -0
  107. data/spec/data/incomplete-metadata-chef-repo/incomplete-metadata/recipes/default.rb +8 -0
  108. data/spec/data/invalid-metadata-chef-repo/invalid-metadata/README.md +4 -0
  109. data/spec/data/invalid-metadata-chef-repo/invalid-metadata/metadata.rb +10 -0
  110. data/spec/data/invalid-metadata-chef-repo/invalid-metadata/recipes/default.rb +8 -0
  111. data/spec/data/mac_users/10.7-8.plist.xml +559 -0
  112. data/spec/data/mac_users/10.7-8.shadow.xml +11 -0
  113. data/spec/data/mac_users/10.7.plist.xml +559 -0
  114. data/spec/data/mac_users/10.7.shadow.xml +11 -0
  115. data/spec/data/mac_users/10.8.plist.xml +559 -0
  116. data/spec/data/mac_users/10.8.shadow.xml +21 -0
  117. data/spec/data/mac_users/10.9.plist.xml +560 -0
  118. data/spec/data/mac_users/10.9.shadow.xml +21 -0
  119. data/spec/data/object_loader/environments/test.json +2 -0
  120. data/spec/data/object_loader/environments/test_json_class.json +2 -0
  121. data/spec/data/object_loader/nodes/test.json +2 -0
  122. data/spec/data/object_loader/nodes/test_json_class.json +2 -0
  123. data/spec/data/object_loader/roles/test.json +2 -0
  124. data/spec/data/object_loader/roles/test_json_class.json +2 -0
  125. data/spec/functional/resource/bff_spec.rb +1 -1
  126. data/spec/functional/resource/cron_spec.rb +20 -1
  127. data/spec/functional/resource/env_spec.rb +137 -0
  128. data/spec/functional/resource/group_spec.rb +7 -5
  129. data/spec/functional/resource/remote_file_spec.rb +12 -1
  130. data/spec/functional/resource/user/dscl_spec.rb +198 -0
  131. data/spec/functional/resource/{user_spec.rb → user/useradd_spec.rb} +175 -37
  132. data/spec/integration/client/client_spec.rb +6 -4
  133. data/spec/integration/client/ipv6_spec.rb +16 -14
  134. data/spec/integration/knife/chef_fs_data_store_spec.rb +57 -46
  135. data/spec/integration/knife/chef_repo_path_spec.rb +105 -78
  136. data/spec/integration/knife/chef_repository_file_system_spec.rb +100 -84
  137. data/spec/integration/knife/chefignore_spec.rb +76 -46
  138. data/spec/integration/knife/common_options_spec.rb +16 -21
  139. data/spec/integration/knife/cookbook_api_ipv6_spec.rb +3 -3
  140. data/spec/integration/knife/delete_spec.rb +66 -46
  141. data/spec/integration/knife/deps_spec.rb +145 -94
  142. data/spec/integration/knife/diff_spec.rb +176 -110
  143. data/spec/integration/knife/download_spec.rb +229 -133
  144. data/spec/integration/knife/list_spec.rb +62 -54
  145. data/spec/integration/knife/raw_spec.rb +24 -9
  146. data/spec/integration/knife/redirection_spec.rb +2 -2
  147. data/spec/integration/knife/serve_spec.rb +2 -2
  148. data/spec/integration/knife/show_spec.rb +32 -26
  149. data/spec/integration/knife/upload_spec.rb +308 -165
  150. data/spec/integration/recipes/lwrp_inline_resources_spec.rb +10 -8
  151. data/spec/integration/solo/solo_spec.rb +22 -11
  152. data/spec/spec_helper.rb +3 -0
  153. data/spec/support/lib/chef/resource/zen_follower.rb +46 -0
  154. data/spec/support/platform_helpers.rb +12 -0
  155. data/spec/support/shared/functional/file_resource.rb +10 -0
  156. data/spec/support/shared/integration/chef_zero_support.rb +130 -0
  157. data/spec/support/shared/integration/integration_helper.rb +100 -98
  158. data/spec/support/shared/integration/knife_support.rb +0 -1
  159. data/spec/support/shared/unit/provider/file.rb +6 -4
  160. data/spec/support/shared/unit/provider/useradd_based_user_provider.rb +10 -1
  161. data/spec/unit/api_client/registration_spec.rb +83 -74
  162. data/spec/unit/application_spec.rb +32 -9
  163. data/spec/unit/cookbook/cookbook_version_loader_spec.rb +179 -0
  164. data/spec/unit/cookbook/metadata_spec.rb +190 -150
  165. data/spec/unit/cookbook/syntax_check_spec.rb +3 -2
  166. data/spec/unit/cookbook_loader_spec.rb +114 -53
  167. data/spec/unit/{cookbook_site_streaming_uploader.rb → cookbook_site_streaming_uploader_spec.rb} +21 -1
  168. data/spec/unit/data_bag_spec.rb +88 -13
  169. data/spec/unit/deprecation_spec.rb +1 -2
  170. data/spec/unit/encrypted_data_bag_item_spec.rb +145 -9
  171. data/spec/unit/environment_spec.rb +1 -1
  172. data/spec/unit/formatters/base_spec.rb +48 -0
  173. data/spec/unit/json_compat_spec.rb +48 -17
  174. data/spec/unit/knife/client_delete_spec.rb +4 -4
  175. data/spec/unit/knife/client_show_spec.rb +15 -5
  176. data/spec/unit/knife/cookbook_site_download_spec.rb +1 -1
  177. data/spec/unit/knife/cookbook_site_share_spec.rb +3 -3
  178. data/spec/unit/knife/data_bag_from_file_spec.rb +0 -2
  179. data/spec/unit/knife/data_bag_show_spec.rb +23 -14
  180. data/spec/unit/knife/node_show_spec.rb +32 -15
  181. data/spec/unit/knife/role_show_spec.rb +59 -0
  182. data/spec/unit/platform_spec.rb +10 -0
  183. data/spec/unit/provider/deploy_spec.rb +4 -0
  184. data/spec/unit/provider/env_spec.rb +19 -0
  185. data/spec/unit/provider/git_spec.rb +22 -2
  186. data/spec/unit/provider/group/dscl_spec.rb +38 -1
  187. data/spec/unit/provider/group/pw_spec.rb +2 -2
  188. data/spec/unit/provider/http_request_spec.rb +8 -8
  189. data/spec/unit/provider/log_spec.rb +33 -53
  190. data/spec/unit/provider/mount/mount_spec.rb +12 -3
  191. data/spec/unit/provider/package/ips_spec.rb +96 -63
  192. data/spec/unit/provider/package/paludis_spec.rb +5 -5
  193. data/spec/unit/provider/package/rpm_spec.rb +12 -0
  194. data/spec/unit/provider/package/zypper_spec.rb +28 -16
  195. data/spec/unit/provider/service/windows_spec.rb +77 -17
  196. data/spec/unit/provider/user/dscl_spec.rb +659 -264
  197. data/spec/unit/provider/user/useradd_spec.rb +1 -0
  198. data/spec/unit/recipe_spec.rb +41 -0
  199. data/spec/unit/resource/scm_spec.rb +11 -0
  200. data/spec/unit/resource/user_spec.rb +4 -0
  201. data/spec/unit/resource/windows_service_spec.rb +46 -0
  202. data/spec/unit/resource_collection_spec.rb +33 -0
  203. data/spec/unit/resource_reporter_spec.rb +48 -0
  204. data/spec/unit/resource_spec.rb +9 -2
  205. data/spec/unit/role_spec.rb +6 -0
  206. data/spec/unit/version_constraint_spec.rb +28 -0
  207. metadata +61 -4
@@ -20,27 +20,32 @@ require 'chef/knife/download'
20
20
  require 'chef/knife/diff'
21
21
 
22
22
  describe 'knife download' do
23
- extend IntegrationSupport
23
+ include IntegrationSupport
24
24
  include KnifeSupport
25
25
 
26
26
  context 'without versioned cookbooks' do
27
27
  when_the_chef_server "has one of each thing" do
28
- client 'x', {}
29
- cookbook 'x', '1.0.0', { 'metadata.rb' => 'version "1.0.0"' }
30
- data_bag 'x', { 'y' => {} }
31
- environment 'x', {}
32
- node 'x', {}
33
- role 'x', {}
34
- user 'x', {}
28
+
29
+ before do
30
+ client 'x', {}
31
+ cookbook 'x', '1.0.0'
32
+ data_bag 'x', { 'y' => {} }
33
+ environment 'x', {}
34
+ node 'x', {}
35
+ role 'x', {}
36
+ user 'x', {}
37
+ end
35
38
 
36
39
  when_the_repository 'has only top-level directories' do
37
- directory 'clients'
38
- directory 'cookbooks'
39
- directory 'data_bags'
40
- directory 'environments'
41
- directory 'nodes'
42
- directory 'roles'
43
- directory 'users'
40
+ before do
41
+ directory 'clients'
42
+ directory 'cookbooks'
43
+ directory 'data_bags'
44
+ directory 'environments'
45
+ directory 'nodes'
46
+ directory 'roles'
47
+ directory 'users'
48
+ end
44
49
 
45
50
  it 'knife download downloads everything' do
46
51
  knife('download /').should_succeed <<EOM
@@ -63,17 +68,19 @@ EOM
63
68
  end
64
69
 
65
70
  when_the_repository 'has an identical copy of each thing' do
66
- file 'clients/chef-validator.json', { 'validator' => true, 'public_key' => ChefZero::PUBLIC_KEY }
67
- file 'clients/chef-webui.json', { 'admin' => true, 'public_key' => ChefZero::PUBLIC_KEY }
68
- file 'clients/x.json', { 'public_key' => ChefZero::PUBLIC_KEY }
69
- file 'cookbooks/x/metadata.rb', 'version "1.0.0"'
70
- file 'data_bags/x/y.json', {}
71
- file 'environments/_default.json', { "description" => "The default Chef environment" }
72
- file 'environments/x.json', {}
73
- file 'nodes/x.json', {}
74
- file 'roles/x.json', {}
75
- file 'users/admin.json', { 'admin' => true, 'public_key' => ChefZero::PUBLIC_KEY }
76
- file 'users/x.json', { 'public_key' => ChefZero::PUBLIC_KEY }
71
+ before do
72
+ file 'clients/chef-validator.json', { 'validator' => true, 'public_key' => ChefZero::PUBLIC_KEY }
73
+ file 'clients/chef-webui.json', { 'admin' => true, 'public_key' => ChefZero::PUBLIC_KEY }
74
+ file 'clients/x.json', { 'public_key' => ChefZero::PUBLIC_KEY }
75
+ file 'cookbooks/x/metadata.rb', cb_metadata("x", "1.0.0")
76
+ file 'data_bags/x/y.json', {}
77
+ file 'environments/_default.json', { "description" => "The default Chef environment" }
78
+ file 'environments/x.json', {}
79
+ file 'nodes/x.json', {}
80
+ file 'roles/x.json', {}
81
+ file 'users/admin.json', { 'admin' => true, 'public_key' => ChefZero::PUBLIC_KEY }
82
+ file 'users/x.json', { 'public_key' => ChefZero::PUBLIC_KEY }
83
+ end
77
84
 
78
85
  it 'knife download makes no changes' do
79
86
  knife('download /').should_succeed ''
@@ -86,7 +93,8 @@ EOM
86
93
  end
87
94
 
88
95
  context 'except the role file' do
89
- file 'roles/x.json', <<EOM
96
+ before do
97
+ file 'roles/x.json', <<EOM
90
98
  {
91
99
  "chef_type": "role",
92
100
  "default_attributes": {
@@ -103,6 +111,8 @@ EOM
103
111
  ]
104
112
  }
105
113
  EOM
114
+ end
115
+
106
116
  it 'knife download changes the role' do
107
117
  knife('download /').should_succeed "Updated /roles/x.json\n"
108
118
  knife('diff --name-status /').should_succeed ''
@@ -115,7 +125,8 @@ EOM
115
125
  end
116
126
 
117
127
  context 'except the role file is textually different, but not ACTUALLY different' do
118
- file 'roles/x.json', <<EOM
128
+ before do
129
+ file 'roles/x.json', <<EOM
119
130
  {
120
131
  "chef_type": "role",
121
132
  "default_attributes": {
@@ -132,6 +143,8 @@ EOM
132
143
  ]
133
144
  }
134
145
  EOM
146
+ end
147
+
135
148
  it 'knife download / does not change anything' do
136
149
  knife('download /').should_succeed ''
137
150
  knife('diff --name-status /').should_succeed ''
@@ -139,15 +152,17 @@ EOM
139
152
  end
140
153
 
141
154
  context 'as well as one extra copy of each thing' do
142
- file 'clients/y.json', { 'public_key' => ChefZero::PUBLIC_KEY }
143
- file 'cookbooks/x/blah.rb', ''
144
- file 'cookbooks/y/metadata.rb', 'version "1.0.0"'
145
- file 'data_bags/x/z.json', {}
146
- file 'data_bags/y/zz.json', {}
147
- file 'environments/y.json', {}
148
- file 'nodes/y.json', {}
149
- file 'roles/y.json', {}
150
- file 'users/y.json', { 'public_key' => ChefZero::PUBLIC_KEY }
155
+ before do
156
+ file 'clients/y.json', { 'public_key' => ChefZero::PUBLIC_KEY }
157
+ file 'cookbooks/x/blah.rb', ''
158
+ file 'cookbooks/y/metadata.rb', cb_metadata("x", "1.0.0")
159
+ file 'data_bags/x/z.json', {}
160
+ file 'data_bags/y/zz.json', {}
161
+ file 'environments/y.json', {}
162
+ file 'nodes/y.json', {}
163
+ file 'roles/y.json', {}
164
+ file 'users/y.json', { 'public_key' => ChefZero::PUBLIC_KEY }
165
+ end
151
166
 
152
167
  it 'knife download does nothing' do
153
168
  knife('download /').should_succeed ''
@@ -235,7 +250,10 @@ EOM
235
250
  end
236
251
 
237
252
  context 'when current directory is top level' do
238
- cwd '.'
253
+ before do
254
+ cwd '.'
255
+ end
256
+
239
257
  it 'knife download with no parameters reports an error' do
240
258
  knife('download').should_fail "FATAL: Must specify at least one argument. If you want to download everything in this directory, type \"knife download .\"\n", :stdout => /USAGE/
241
259
  end
@@ -246,7 +264,9 @@ EOM
246
264
  # Test download of an item when the other end doesn't even have the container
247
265
  when_the_repository 'is empty' do
248
266
  when_the_chef_server 'has two data bag items' do
249
- data_bag 'x', { 'y' => {}, 'z' => {} }
267
+ before do
268
+ data_bag 'x', { 'y' => {}, 'z' => {} }
269
+ end
250
270
 
251
271
  it 'knife download of one data bag item itself succeeds' do
252
272
  knife('download /data_bags/x/y.json').should_succeed <<EOM
@@ -271,28 +291,32 @@ EOM
271
291
  end
272
292
 
273
293
  when_the_repository 'has three data bag items' do
274
- file 'data_bags/x/deleted.json', <<EOM
294
+ before do
295
+ file 'data_bags/x/deleted.json', <<EOM
275
296
  {
276
297
  "id": "deleted"
277
298
  }
278
299
  EOM
279
- file 'data_bags/x/modified.json', <<EOM
300
+ file 'data_bags/x/modified.json', <<EOM
280
301
  {
281
302
  "id": "modified"
282
303
  }
283
304
  EOM
284
- file 'data_bags/x/unmodified.json', <<EOM
305
+ file 'data_bags/x/unmodified.json', <<EOM
285
306
  {
286
307
  "id": "unmodified"
287
308
  }
288
309
  EOM
310
+ end
289
311
 
290
312
  when_the_chef_server 'has a modified, unmodified, added and deleted data bag item' do
291
- data_bag 'x', {
292
- 'added' => {},
293
- 'modified' => { 'foo' => 'bar' },
294
- 'unmodified' => {}
295
- }
313
+ before do
314
+ data_bag 'x', {
315
+ 'added' => {},
316
+ 'modified' => { 'foo' => 'bar' },
317
+ 'unmodified' => {}
318
+ }
319
+ end
296
320
 
297
321
  it 'knife download of the modified file succeeds' do
298
322
  knife('download /data_bags/x/modified.json').should_succeed <<EOM
@@ -355,7 +379,9 @@ EOM
355
379
  knife('diff --name-status /data_bags').should_succeed ''
356
380
  end
357
381
  context 'when cwd is the /data_bags directory' do
358
- cwd 'data_bags'
382
+ before do
383
+ cwd 'data_bags'
384
+ end
359
385
  it 'knife download fails' do
360
386
  knife('download').should_fail "FATAL: Must specify at least one argument. If you want to download everything in this directory, type \"knife download .\"\n", :stdout => /USAGE/
361
387
  end
@@ -380,11 +406,15 @@ EOM
380
406
  end
381
407
 
382
408
  when_the_repository 'has a cookbook' do
383
- file 'cookbooks/x/metadata.rb', 'version "1.0.0"'
384
- file 'cookbooks/x/z.rb', ''
409
+ before do
410
+ file 'cookbooks/x/metadata.rb', cb_metadata("x", "1.0.0")
411
+ file 'cookbooks/x/z.rb', ''
412
+ end
385
413
 
386
414
  when_the_chef_server 'has a modified, added and deleted file for the cookbook' do
387
- cookbook 'x', '1.0.0', { 'metadata.rb' => 'version "1.0.0"', 'y.rb' => 'hi' }
415
+ before do
416
+ cookbook 'x', '1.0.0', { 'metadata.rb' => cb_metadata("x", "1.0.0", "#extra content"), 'y.rb' => 'hi' }
417
+ end
388
418
 
389
419
  it 'knife download of a modified file succeeds' do
390
420
  knife('download /cookbooks/x/metadata.rb').should_succeed "Updated /cookbooks/x/metadata.rb\n"
@@ -436,12 +466,16 @@ EOM
436
466
  end
437
467
 
438
468
  when_the_repository 'has a cookbook' do
439
- file 'cookbooks/x/metadata.rb', 'version "1.0.0"'
440
- file 'cookbooks/x/onlyin1.0.0.rb', 'old_text'
469
+ before do
470
+ file 'cookbooks/x/metadata.rb', cb_metadata("x", "1.0.0")
471
+ file 'cookbooks/x/onlyin1.0.0.rb', 'old_text'
472
+ end
441
473
 
442
474
  when_the_chef_server 'has a later version for the cookbook' do
443
- cookbook 'x', '1.0.0', { 'metadata.rb' => 'version "1.0.0"', 'onlyin1.0.0.rb' => '' }
444
- cookbook 'x', '1.0.1', { 'metadata.rb' => 'version "1.0.1"', 'onlyin1.0.1.rb' => 'hi' }
475
+ before do
476
+ cookbook 'x', '1.0.0', { 'onlyin1.0.0.rb' => '' }
477
+ cookbook 'x', '1.0.1', { 'onlyin1.0.1.rb' => 'hi' }
478
+ end
445
479
 
446
480
  it 'knife download /cookbooks/x downloads the latest version' do
447
481
  knife('download --purge /cookbooks/x').should_succeed <<EOM
@@ -454,8 +488,11 @@ EOM
454
488
  end
455
489
 
456
490
  when_the_chef_server 'has an earlier version for the cookbook' do
457
- cookbook 'x', '1.0.0', { 'metadata.rb' => 'version "1.0.0"', 'onlyin1.0.0.rb' => ''}
458
- cookbook 'x', '0.9.9', { 'metadata.rb' => 'version "0.9.9"', 'onlyin0.9.9.rb' => 'hi' }
491
+ before do
492
+ cookbook 'x', '1.0.0', { 'onlyin1.0.0.rb' => ''}
493
+ cookbook 'x', '0.9.9', { 'onlyin0.9.9.rb' => 'hi' }
494
+ end
495
+
459
496
  it 'knife download /cookbooks/x downloads the updated file' do
460
497
  knife('download --purge /cookbooks/x').should_succeed <<EOM
461
498
  Updated /cookbooks/x/onlyin1.0.0.rb
@@ -465,7 +502,9 @@ EOM
465
502
  end
466
503
 
467
504
  when_the_chef_server 'has a later version for the cookbook, and no current version' do
468
- cookbook 'x', '1.0.1', { 'metadata.rb' => 'version "1.0.1"', 'onlyin1.0.1.rb' => 'hi' }
505
+ before do
506
+ cookbook 'x', '1.0.1', { 'onlyin1.0.1.rb' => 'hi' }
507
+ end
469
508
 
470
509
  it 'knife download /cookbooks/x downloads the latest version' do
471
510
  knife('download --purge /cookbooks/x').should_succeed <<EOM
@@ -478,7 +517,9 @@ EOM
478
517
  end
479
518
 
480
519
  when_the_chef_server 'has an earlier version for the cookbook, and no current version' do
481
- cookbook 'x', '0.9.9', { 'metadata.rb' => 'version "0.9.9"', 'onlyin0.9.9.rb' => 'hi' }
520
+ before do
521
+ cookbook 'x', '0.9.9', { 'onlyin0.9.9.rb' => 'hi' }
522
+ end
482
523
 
483
524
  it 'knife download /cookbooks/x downloads the old version' do
484
525
  knife('download --purge /cookbooks/x').should_succeed <<EOM
@@ -492,17 +533,29 @@ EOM
492
533
  end
493
534
 
494
535
  when_the_chef_server 'has an environment' do
495
- environment 'x', {}
536
+ before do
537
+ environment 'x', {}
538
+ end
496
539
  when_the_repository 'has an environment with bad JSON' do
497
- file 'environments/x.json', '{'
540
+ before do
541
+ file 'environments/x.json', '{'
542
+ end
498
543
  it 'knife download succeeds' do
499
- knife('download /environments/x.json').should_succeed "Updated /environments/x.json\n", :stderr => "WARN: Parse error reading #{path_to('environments/x.json')} as JSON: A JSON text must at least contain two octets!\n"
544
+ warning = <<-EOH
545
+ WARN: Parse error reading #{path_to('environments/x.json')} as JSON: parse error: premature EOF
546
+ {
547
+ (right here) ------^
548
+
549
+ EOH
550
+ knife('download /environments/x.json').should_succeed "Updated /environments/x.json\n", :stderr => warning
500
551
  knife('diff --name-status /environments/x.json').should_succeed ''
501
552
  end
502
553
  end
503
554
 
504
555
  when_the_repository 'has the same environment with the wrong name in the file' do
505
- file 'environments/x.json', { 'name' => 'y' }
556
+ before do
557
+ file 'environments/x.json', { 'name' => 'y' }
558
+ end
506
559
  it 'knife download succeeds' do
507
560
  knife('download /environments/x.json').should_succeed "Updated /environments/x.json\n"
508
561
  knife('diff --name-status /environments/x.json').should_succeed ''
@@ -510,7 +563,9 @@ EOM
510
563
  end
511
564
 
512
565
  when_the_repository 'has the same environment with no name in the file' do
513
- file 'environments/x.json', { 'description' => 'hi' }
566
+ before do
567
+ file 'environments/x.json', { 'description' => 'hi' }
568
+ end
514
569
  it 'knife download succeeds' do
515
570
  knife('download /environments/x.json').should_succeed "Updated /environments/x.json\n"
516
571
  knife('diff --name-status /environments/x.json').should_succeed ''
@@ -521,22 +576,26 @@ EOM
521
576
 
522
577
  with_versioned_cookbooks do
523
578
  when_the_chef_server "has one of each thing" do
524
- client 'x', {}
525
- cookbook 'x', '1.0.0', { 'metadata.rb' => 'version "1.0.0"' }
526
- data_bag 'x', { 'y' => {} }
527
- environment 'x', {}
528
- node 'x', {}
529
- role 'x', {}
530
- user 'x', {}
579
+ before do
580
+ client 'x', {}
581
+ cookbook 'x', '1.0.0'
582
+ data_bag 'x', { 'y' => {} }
583
+ environment 'x', {}
584
+ node 'x', {}
585
+ role 'x', {}
586
+ user 'x', {}
587
+ end
531
588
 
532
589
  when_the_repository 'has only top-level directories' do
533
- directory 'clients'
534
- directory 'cookbooks'
535
- directory 'data_bags'
536
- directory 'environments'
537
- directory 'nodes'
538
- directory 'roles'
539
- directory 'users'
590
+ before do
591
+ directory 'clients'
592
+ directory 'cookbooks'
593
+ directory 'data_bags'
594
+ directory 'environments'
595
+ directory 'nodes'
596
+ directory 'roles'
597
+ directory 'users'
598
+ end
540
599
 
541
600
  it 'knife download downloads everything' do
542
601
  knife('download /').should_succeed <<EOM
@@ -559,17 +618,19 @@ EOM
559
618
  end
560
619
 
561
620
  when_the_repository 'has an identical copy of each thing' do
562
- file 'clients/chef-validator.json', { 'validator' => true, 'public_key' => ChefZero::PUBLIC_KEY }
563
- file 'clients/chef-webui.json', { 'admin' => true, 'public_key' => ChefZero::PUBLIC_KEY }
564
- file 'clients/x.json', { 'public_key' => ChefZero::PUBLIC_KEY }
565
- file 'cookbooks/x-1.0.0/metadata.rb', 'version "1.0.0"'
566
- file 'data_bags/x/y.json', {}
567
- file 'environments/_default.json', { "description" => "The default Chef environment" }
568
- file 'environments/x.json', {}
569
- file 'nodes/x.json', {}
570
- file 'roles/x.json', {}
571
- file 'users/admin.json', { 'admin' => true, 'public_key' => ChefZero::PUBLIC_KEY }
572
- file 'users/x.json', { 'public_key' => ChefZero::PUBLIC_KEY }
621
+ before do
622
+ file 'clients/chef-validator.json', { 'validator' => true, 'public_key' => ChefZero::PUBLIC_KEY }
623
+ file 'clients/chef-webui.json', { 'admin' => true, 'public_key' => ChefZero::PUBLIC_KEY }
624
+ file 'clients/x.json', { 'public_key' => ChefZero::PUBLIC_KEY }
625
+ file 'cookbooks/x-1.0.0/metadata.rb', cb_metadata("x", "1.0.0")
626
+ file 'data_bags/x/y.json', {}
627
+ file 'environments/_default.json', { "description" => "The default Chef environment" }
628
+ file 'environments/x.json', {}
629
+ file 'nodes/x.json', {}
630
+ file 'roles/x.json', {}
631
+ file 'users/admin.json', { 'admin' => true, 'public_key' => ChefZero::PUBLIC_KEY }
632
+ file 'users/x.json', { 'public_key' => ChefZero::PUBLIC_KEY }
633
+ end
573
634
 
574
635
  it 'knife download makes no changes' do
575
636
  knife('download /').should_succeed ''
@@ -582,7 +643,9 @@ EOM
582
643
  end
583
644
 
584
645
  context 'except the role file' do
585
- file 'roles/x.json', { "description" => "blarghle" }
646
+ before do
647
+ file 'roles/x.json', { "description" => "blarghle" }
648
+ end
586
649
 
587
650
  it 'knife download changes the role' do
588
651
  knife('download /').should_succeed "Updated /roles/x.json\n"
@@ -591,7 +654,8 @@ EOM
591
654
  end
592
655
 
593
656
  context 'except the role file is textually different, but not ACTUALLY different' do
594
- file 'roles/x.json', <<EOM
657
+ before do
658
+ file 'roles/x.json', <<EOM
595
659
  {
596
660
  "chef_type": "role" ,
597
661
  "default_attributes": {
@@ -608,6 +672,8 @@ EOM
608
672
  ]
609
673
  }
610
674
  EOM
675
+ end
676
+
611
677
  it 'knife download / does not change anything' do
612
678
  knife('download /').should_succeed ''
613
679
  knife('diff --name-status /').should_succeed ''
@@ -615,16 +681,18 @@ EOM
615
681
  end
616
682
 
617
683
  context 'as well as one extra copy of each thing' do
618
- file 'clients/y.json', { 'public_key' => ChefZero::PUBLIC_KEY }
619
- file 'cookbooks/x-1.0.0/blah.rb', ''
620
- file 'cookbooks/x-2.0.0/metadata.rb', 'version "2.0.0"'
621
- file 'cookbooks/y-1.0.0/metadata.rb', 'version "1.0.0"'
622
- file 'data_bags/x/z.json', {}
623
- file 'data_bags/y/zz.json', {}
624
- file 'environments/y.json', {}
625
- file 'nodes/y.json', {}
626
- file 'roles/y.json', {}
627
- file 'users/y.json', { 'public_key' => ChefZero::PUBLIC_KEY }
684
+ before do
685
+ file 'clients/y.json', { 'public_key' => ChefZero::PUBLIC_KEY }
686
+ file 'cookbooks/x-1.0.0/blah.rb', ''
687
+ file 'cookbooks/x-2.0.0/metadata.rb', 'version "2.0.0"'
688
+ file 'cookbooks/y-1.0.0/metadata.rb', 'version "1.0.0"'
689
+ file 'data_bags/x/z.json', {}
690
+ file 'data_bags/y/zz.json', {}
691
+ file 'environments/y.json', {}
692
+ file 'nodes/y.json', {}
693
+ file 'roles/y.json', {}
694
+ file 'users/y.json', { 'public_key' => ChefZero::PUBLIC_KEY }
695
+ end
628
696
 
629
697
  it 'knife download does nothing' do
630
698
  knife('download /').should_succeed ''
@@ -688,7 +756,9 @@ EOM
688
756
  end
689
757
 
690
758
  context 'when current directory is top level' do
691
- cwd '.'
759
+ before do
760
+ cwd '.'
761
+ end
692
762
  it 'knife download with no parameters reports an error' do
693
763
  knife('download').should_fail "FATAL: Must specify at least one argument. If you want to download everything in this directory, type \"knife download .\"\n", :stdout => /USAGE/
694
764
  end
@@ -699,7 +769,9 @@ EOM
699
769
  # Test download of an item when the other end doesn't even have the container
700
770
  when_the_repository 'is empty' do
701
771
  when_the_chef_server 'has two data bag items' do
702
- data_bag 'x', { 'y' => {}, 'z' => {} }
772
+ before do
773
+ data_bag 'x', { 'y' => {}, 'z' => {} }
774
+ end
703
775
 
704
776
  it 'knife download of one data bag item itself succeeds' do
705
777
  knife('download /data_bags/x/y.json').should_succeed <<EOM
@@ -715,28 +787,32 @@ EOM
715
787
  end
716
788
 
717
789
  when_the_repository 'has three data bag items' do
718
- file 'data_bags/x/deleted.json', <<EOM
790
+ before do
791
+ file 'data_bags/x/deleted.json', <<EOM
719
792
  {
720
793
  "id": "deleted"
721
794
  }
722
795
  EOM
723
- file 'data_bags/x/modified.json', <<EOM
796
+ file 'data_bags/x/modified.json', <<EOM
724
797
  {
725
798
  "id": "modified"
726
799
  }
727
800
  EOM
728
- file 'data_bags/x/unmodified.json', <<EOM
801
+ file 'data_bags/x/unmodified.json', <<EOM
729
802
  {
730
803
  "id": "unmodified"
731
804
  }
732
805
  EOM
806
+ end
733
807
 
734
808
  when_the_chef_server 'has a modified, unmodified, added and deleted data bag item' do
735
- data_bag 'x', {
736
- 'added' => {},
737
- 'modified' => { 'foo' => 'bar' },
738
- 'unmodified' => {}
739
- }
809
+ before do
810
+ data_bag 'x', {
811
+ 'added' => {},
812
+ 'modified' => { 'foo' => 'bar' },
813
+ 'unmodified' => {}
814
+ }
815
+ end
740
816
 
741
817
  it 'knife download of the modified file succeeds' do
742
818
  knife('download /data_bags/x/modified.json').should_succeed <<EOM
@@ -799,7 +875,9 @@ EOM
799
875
  knife('diff --name-status /data_bags').should_succeed ''
800
876
  end
801
877
  context 'when cwd is the /data_bags directory' do
802
- cwd 'data_bags'
878
+ before do
879
+ cwd 'data_bags'
880
+ end
803
881
  it 'knife download fails' do
804
882
  knife('download').should_fail "FATAL: Must specify at least one argument. If you want to download everything in this directory, type \"knife download .\"\n", :stdout => /USAGE/
805
883
  end
@@ -824,11 +902,15 @@ EOM
824
902
  end
825
903
 
826
904
  when_the_repository 'has a cookbook' do
827
- file 'cookbooks/x-1.0.0/metadata.rb', 'version "1.0.0"'
828
- file 'cookbooks/x-1.0.0/z.rb', ''
905
+ before do
906
+ file 'cookbooks/x-1.0.0/metadata.rb', 'name "x"; version "1.0.0"'
907
+ file 'cookbooks/x-1.0.0/z.rb', ''
908
+ end
829
909
 
830
910
  when_the_chef_server 'has a modified, added and deleted file for the cookbook' do
831
- cookbook 'x', '1.0.0', { 'metadata.rb' => 'version "1.0.0"', 'y.rb' => 'hi' }
911
+ before do
912
+ cookbook 'x', '1.0.0', { 'y.rb' => 'hi' }
913
+ end
832
914
 
833
915
  it 'knife download of a modified file succeeds' do
834
916
  knife('download /cookbooks/x-1.0.0/metadata.rb').should_succeed "Updated /cookbooks/x-1.0.0/metadata.rb\n"
@@ -880,12 +962,16 @@ EOM
880
962
  end
881
963
 
882
964
  when_the_repository 'has a cookbook' do
883
- file 'cookbooks/x-1.0.0/metadata.rb', 'version "1.0.0"'
884
- file 'cookbooks/x-1.0.0/onlyin1.0.0.rb', 'old_text'
965
+ before do
966
+ file 'cookbooks/x-1.0.0/metadata.rb', cb_metadata("x", "1.0.0")
967
+ file 'cookbooks/x-1.0.0/onlyin1.0.0.rb', 'old_text'
968
+ end
885
969
 
886
970
  when_the_chef_server 'has a later version for the cookbook' do
887
- cookbook 'x', '1.0.0', { 'metadata.rb' => 'version "1.0.0"', 'onlyin1.0.0.rb' => '' }
888
- cookbook 'x', '1.0.1', { 'metadata.rb' => 'version "1.0.1"', 'onlyin1.0.1.rb' => 'hi' }
971
+ before do
972
+ cookbook 'x', '1.0.0', { 'onlyin1.0.0.rb' => '' }
973
+ cookbook 'x', '1.0.1', { 'onlyin1.0.1.rb' => 'hi' }
974
+ end
889
975
 
890
976
  it 'knife download /cookbooks/x downloads the latest version' do
891
977
  knife('download --purge /cookbooks').should_succeed <<EOM
@@ -899,8 +985,11 @@ EOM
899
985
  end
900
986
 
901
987
  when_the_chef_server 'has an earlier version for the cookbook' do
902
- cookbook 'x', '1.0.0', { 'metadata.rb' => 'version "1.0.0"', 'onlyin1.0.0.rb' => ''}
903
- cookbook 'x', '0.9.9', { 'metadata.rb' => 'version "0.9.9"', 'onlyin0.9.9.rb' => 'hi' }
988
+ before do
989
+ cookbook 'x', '1.0.0', { 'onlyin1.0.0.rb' => ''}
990
+ cookbook 'x', '0.9.9', { 'onlyin0.9.9.rb' => 'hi' }
991
+ end
992
+
904
993
  it 'knife download /cookbooks downloads the updated file' do
905
994
  knife('download --purge /cookbooks').should_succeed <<EOM
906
995
  Created /cookbooks/x-0.9.9
@@ -913,7 +1002,9 @@ EOM
913
1002
  end
914
1003
 
915
1004
  when_the_chef_server 'has a later version for the cookbook, and no current version' do
916
- cookbook 'x', '1.0.1', { 'metadata.rb' => 'version "1.0.1"', 'onlyin1.0.1.rb' => 'hi' }
1005
+ before do
1006
+ cookbook 'x', '1.0.1', { 'onlyin1.0.1.rb' => 'hi' }
1007
+ end
917
1008
 
918
1009
  it 'knife download /cookbooks/x downloads the latest version' do
919
1010
  knife('download --purge /cookbooks').should_succeed <<EOM
@@ -927,7 +1018,9 @@ EOM
927
1018
  end
928
1019
 
929
1020
  when_the_chef_server 'has an earlier version for the cookbook, and no current version' do
930
- cookbook 'x', '0.9.9', { 'metadata.rb' => 'version "0.9.9"', 'onlyin0.9.9.rb' => 'hi' }
1021
+ before do
1022
+ cookbook 'x', '0.9.9', { 'onlyin0.9.9.rb' => 'hi' }
1023
+ end
931
1024
 
932
1025
  it 'knife download --purge /cookbooks downloads the old version and deletes the new version' do
933
1026
  knife('download --purge /cookbooks').should_succeed <<EOM
@@ -942,17 +1035,15 @@ EOM
942
1035
  end
943
1036
 
944
1037
  when_the_chef_server 'has an environment' do
945
- environment 'x', {}
946
- when_the_repository 'has an environment with bad JSON' do
947
- file 'environments/x.json', '{'
948
- it 'knife download succeeds' do
949
- knife('download /environments/x.json').should_succeed "Updated /environments/x.json\n", :stderr => "WARN: Parse error reading #{path_to('environments/x.json')} as JSON: A JSON text must at least contain two octets!\n"
950
- knife('diff --name-status /environments/x.json').should_succeed ''
951
- end
1038
+ before do
1039
+ environment 'x', {}
952
1040
  end
953
1041
 
954
1042
  when_the_repository 'has the same environment with the wrong name in the file' do
955
- file 'environments/x.json', { 'name' => 'y' }
1043
+ before do
1044
+ file 'environments/x.json', { 'name' => 'y' }
1045
+ end
1046
+
956
1047
  it 'knife download succeeds' do
957
1048
  knife('download /environments/x.json').should_succeed "Updated /environments/x.json\n"
958
1049
  knife('diff --name-status /environments/x.json').should_succeed ''
@@ -960,7 +1051,10 @@ EOM
960
1051
  end
961
1052
 
962
1053
  when_the_repository 'has the same environment with no name in the file' do
963
- file 'environments/x.json', { 'description' => 'hi' }
1054
+ before do
1055
+ file 'environments/x.json', { 'description' => 'hi' }
1056
+ end
1057
+
964
1058
  it 'knife download succeeds' do
965
1059
  knife('download /environments/x.json').should_succeed "Updated /environments/x.json\n"
966
1060
  knife('diff --name-status /environments/x.json').should_succeed ''
@@ -970,7 +1064,9 @@ EOM
970
1064
  end # with versioned cookbooks
971
1065
 
972
1066
  when_the_chef_server 'has a cookbook' do
973
- cookbook 'x', '1.0.0', { 'metadata.rb' => 'version "1.0.0"' }
1067
+ before do
1068
+ cookbook 'x', '1.0.0'
1069
+ end
974
1070
 
975
1071
  when_the_repository 'is empty' do
976
1072
  it 'knife download /cookbooks/x signs all requests', :ruby_gte_19_only do