chef 12.0.0.alpha.0-x86-mingw32 → 12.0.0.alpha.1-x86-mingw32

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
@@ -19,27 +19,31 @@ require 'support/shared/integration/integration_helper'
19
19
  require 'chef/knife/diff'
20
20
 
21
21
  describe 'knife diff' do
22
- extend IntegrationSupport
22
+ include IntegrationSupport
23
23
  include KnifeSupport
24
24
 
25
25
  context 'without versioned cookbooks' do
26
26
  when_the_chef_server "has one of each thing" do
27
- client 'x', '{}'
28
- cookbook 'x', '1.0.0', { 'metadata.rb' => 'version "1.0.0"' }
29
- data_bag 'x', { 'y' => '{}' }
30
- environment 'x', '{}'
31
- node 'x', '{}'
32
- role 'x', '{}'
33
- user 'x', '{}'
27
+ before do
28
+ client 'x', '{}'
29
+ cookbook 'x', '1.0.0'
30
+ data_bag 'x', { 'y' => '{}' }
31
+ environment 'x', '{}'
32
+ node 'x', '{}'
33
+ role 'x', '{}'
34
+ user 'x', '{}'
35
+ end
34
36
 
35
37
  when_the_repository 'has only top-level directories' do
36
- directory 'clients'
37
- directory 'cookbooks'
38
- directory 'data_bags'
39
- directory 'environments'
40
- directory 'nodes'
41
- directory 'roles'
42
- directory 'users'
38
+ before do
39
+ directory 'clients'
40
+ directory 'cookbooks'
41
+ directory 'data_bags'
42
+ directory 'environments'
43
+ directory 'nodes'
44
+ directory 'roles'
45
+ directory 'users'
46
+ end
43
47
 
44
48
  it 'knife diff reports everything as deleted' do
45
49
  knife('diff --name-status /').should_succeed <<EOM
@@ -60,17 +64,19 @@ EOM
60
64
 
61
65
  when_the_repository 'has an identical copy of each thing' do
62
66
 
63
- file 'clients/chef-validator.json', { 'validator' => true, 'public_key' => ChefZero::PUBLIC_KEY }
64
- file 'clients/chef-webui.json', { 'admin' => true, 'public_key' => ChefZero::PUBLIC_KEY }
65
- file 'clients/x.json', { 'public_key' => ChefZero::PUBLIC_KEY }
66
- file 'cookbooks/x/metadata.rb', 'version "1.0.0"'
67
- file 'data_bags/x/y.json', {}
68
- file 'environments/_default.json', { "description" => "The default Chef environment" }
69
- file 'environments/x.json', {}
70
- file 'nodes/x.json', {}
71
- file 'roles/x.json', {}
72
- file 'users/admin.json', { 'admin' => true, 'public_key' => ChefZero::PUBLIC_KEY }
73
- file 'users/x.json', { 'public_key' => ChefZero::PUBLIC_KEY }
67
+ before do
68
+ file 'clients/chef-validator.json', { 'validator' => true, 'public_key' => ChefZero::PUBLIC_KEY }
69
+ file 'clients/chef-webui.json', { 'admin' => true, 'public_key' => ChefZero::PUBLIC_KEY }
70
+ file 'clients/x.json', { 'public_key' => ChefZero::PUBLIC_KEY }
71
+ file 'cookbooks/x/metadata.rb', cb_metadata("x", "1.0.0")
72
+ file 'data_bags/x/y.json', {}
73
+ file 'environments/_default.json', { "description" => "The default Chef environment" }
74
+ file 'environments/x.json', {}
75
+ file 'nodes/x.json', {}
76
+ file 'roles/x.json', {}
77
+ file 'users/admin.json', { 'admin' => true, 'public_key' => ChefZero::PUBLIC_KEY }
78
+ file 'users/x.json', { 'public_key' => ChefZero::PUBLIC_KEY }
79
+ end
74
80
 
75
81
  it 'knife diff reports no differences' do
76
82
  knife('diff /').should_succeed ''
@@ -85,11 +91,14 @@ EOM
85
91
  end
86
92
 
87
93
  context 'except the role file' do
88
- file 'roles/x.json', <<EOM
94
+ before do
95
+ file 'roles/x.json', <<EOM
89
96
  {
90
97
  "foo": "bar"
91
98
  }
92
99
  EOM
100
+ end
101
+
93
102
  it 'knife diff reports the role as different' do
94
103
  knife('diff --name-status /').should_succeed <<EOM
95
104
  M\t/roles/x.json
@@ -98,15 +107,17 @@ EOM
98
107
  end
99
108
 
100
109
  context 'as well as one extra copy of each thing' do
101
- file 'clients/y.json', { 'public_key' => ChefZero::PUBLIC_KEY }
102
- file 'cookbooks/x/blah.rb', ''
103
- file 'cookbooks/y/metadata.rb', 'version "1.0.0"'
104
- file 'data_bags/x/z.json', {}
105
- file 'data_bags/y/zz.json', {}
106
- file 'environments/y.json', {}
107
- file 'nodes/y.json', {}
108
- file 'roles/y.json', {}
109
- file 'users/y.json', { 'public_key' => ChefZero::PUBLIC_KEY }
110
+ before do
111
+ file 'clients/y.json', { 'public_key' => ChefZero::PUBLIC_KEY }
112
+ file 'cookbooks/x/blah.rb', ''
113
+ file 'cookbooks/y/metadata.rb', cb_metadata("y", "1.0.0")
114
+ file 'data_bags/x/z.json', {}
115
+ file 'data_bags/y/zz.json', {}
116
+ file 'environments/y.json', {}
117
+ file 'nodes/y.json', {}
118
+ file 'roles/y.json', {}
119
+ file 'users/y.json', { 'public_key' => ChefZero::PUBLIC_KEY }
120
+ end
110
121
 
111
122
  it 'knife diff reports the new files as added' do
112
123
  knife('diff --name-status /').should_succeed <<EOM
@@ -123,7 +134,7 @@ EOM
123
134
  end
124
135
 
125
136
  context 'when cwd is the data_bags directory' do
126
- cwd 'data_bags'
137
+ before { cwd 'data_bags' }
127
138
  it 'knife diff reports different data bags' do
128
139
  knife('diff --name-status').should_succeed <<EOM
129
140
  A\tx/z.json
@@ -156,12 +167,16 @@ EOM
156
167
  end
157
168
 
158
169
  when_the_repository 'has a cookbook' do
159
- file 'cookbooks/x/metadata.rb', 'version "1.0.0"'
160
- file 'cookbooks/x/onlyin1.0.0.rb', ''
170
+ before do
171
+ file 'cookbooks/x/metadata.rb', cb_metadata("x", "1.0.0")
172
+ file 'cookbooks/x/onlyin1.0.0.rb', ''
173
+ end
161
174
 
162
175
  when_the_chef_server 'has a later version for the cookbook' do
163
- cookbook 'x', '1.0.0', { 'metadata.rb' => 'version "1.0.0"', 'onlyin1.0.0.rb' => ''}
164
- cookbook 'x', '1.0.1', { 'metadata.rb' => 'version "1.0.1"', 'onlyin1.0.1.rb' => '' }
176
+ before do
177
+ cookbook 'x', '1.0.0', { 'onlyin1.0.0.rb' => ''}
178
+ cookbook 'x', '1.0.1', { 'onlyin1.0.1.rb' => '' }
179
+ end
165
180
 
166
181
  it 'knife diff /cookbooks/x shows differences' do
167
182
  knife('diff --name-status /cookbooks/x').should_succeed <<EOM
@@ -180,15 +195,19 @@ EOM
180
195
  end
181
196
 
182
197
  when_the_chef_server 'has an earlier version for the cookbook' do
183
- cookbook 'x', '1.0.0', { 'metadata.rb' => 'version "1.0.0"', 'onlyin1.0.0.rb' => '' }
184
- cookbook 'x', '0.9.9', { 'metadata.rb' => 'version "0.9.9"', 'onlyin0.9.9.rb' => '' }
198
+ before do
199
+ cookbook 'x', '1.0.0', { 'onlyin1.0.0.rb' => '' }
200
+ cookbook 'x', '0.9.9', { 'onlyin0.9.9.rb' => '' }
201
+ end
185
202
  it 'knife diff /cookbooks/x shows no differences' do
186
203
  knife('diff --name-status /cookbooks/x').should_succeed ''
187
204
  end
188
205
  end
189
206
 
190
207
  when_the_chef_server 'has a later version for the cookbook, and no current version' do
191
- cookbook 'x', '1.0.1', { 'metadata.rb' => 'version "1.0.1"', 'onlyin1.0.1.rb' => '' }
208
+ before do
209
+ cookbook 'x', '1.0.1', { 'onlyin1.0.1.rb' => '' }
210
+ end
192
211
 
193
212
  it 'knife diff /cookbooks/x shows the differences' do
194
213
  knife('diff --name-status /cookbooks/x').should_succeed <<EOM
@@ -200,7 +219,9 @@ EOM
200
219
  end
201
220
 
202
221
  when_the_chef_server 'has an earlier version for the cookbook, and no current version' do
203
- cookbook 'x', '0.9.9', { 'metadata.rb' => 'version "0.9.9"', 'onlyin0.9.9.rb' => '' }
222
+ before do
223
+ cookbook 'x', '0.9.9', { 'onlyin0.9.9.rb' => '' }
224
+ end
204
225
 
205
226
  it 'knife diff /cookbooks/x shows the differences' do
206
227
  knife('diff --name-status /cookbooks/x').should_succeed <<EOM
@@ -214,15 +235,18 @@ EOM
214
235
 
215
236
  context 'json diff tests' do
216
237
  when_the_repository 'has an empty environment file' do
217
- file 'environments/x.json', {}
238
+ before do
239
+ file 'environments/x.json', {}
240
+ end
241
+
218
242
  when_the_chef_server 'has an empty environment' do
219
- environment 'x', {}
243
+ before { environment 'x', {} }
220
244
  it 'knife diff returns no differences' do
221
245
  knife('diff /environments/x.json').should_succeed ''
222
246
  end
223
247
  end
224
248
  when_the_chef_server 'has an environment with a different value' do
225
- environment 'x', { 'description' => 'hi' }
249
+ before { environment 'x', { 'description' => 'hi' } }
226
250
  it 'knife diff reports the difference', :pending => (RUBY_VERSION < "1.9") do
227
251
  knife('diff /environments/x.json').should_succeed(/
228
252
  {
@@ -236,15 +260,23 @@ EOM
236
260
  end
237
261
 
238
262
  when_the_repository 'has an environment file with a value in it' do
239
- file 'environments/x.json', { 'description' => 'hi' }
263
+ before do
264
+ file 'environments/x.json', { 'description' => 'hi' }
265
+ end
266
+
240
267
  when_the_chef_server 'has an environment with the same value' do
241
- environment 'x', { 'description' => 'hi' }
268
+ before do
269
+ environment 'x', { 'description' => 'hi' }
270
+ end
242
271
  it 'knife diff returns no differences' do
243
272
  knife('diff /environments/x.json').should_succeed ''
244
273
  end
245
274
  end
246
275
  when_the_chef_server 'has an environment with no value' do
247
- environment 'x', {}
276
+ before do
277
+ environment 'x', {}
278
+ end
279
+
248
280
  it 'knife diff reports the difference', :pending => (RUBY_VERSION < "1.9") do
249
281
  knife('diff /environments/x.json').should_succeed(/
250
282
  {
@@ -256,7 +288,9 @@ EOM
256
288
  end
257
289
  end
258
290
  when_the_chef_server 'has an environment with a different value' do
259
- environment 'x', { 'description' => 'lo' }
291
+ before do
292
+ environment 'x', { 'description' => 'lo' }
293
+ end
260
294
  it 'knife diff reports the difference', :pending => (RUBY_VERSION < "1.9") do
261
295
  knife('diff /environments/x.json').should_succeed(/
262
296
  {
@@ -271,11 +305,13 @@ EOM
271
305
  end
272
306
 
273
307
  when_the_chef_server 'has an environment' do
274
- environment 'x', {}
308
+ before { environment 'x', {} }
275
309
  when_the_repository 'has an environment with bad JSON' do
276
- file 'environments/x.json', '{'
310
+ before { file 'environments/x.json', '{' }
277
311
  it 'knife diff reports an error and does a textual diff' do
278
- knife('diff /environments/x.json').should_succeed(/- "name": "x"/, :stderr => "WARN: Parse error reading #{path_to('environments/x.json')} as JSON: A JSON text must at least contain two octets!\n")
312
+ error_text = "WARN: Parse error reading #{path_to('environments/x.json')} as JSON: parse error: premature EOF"
313
+ error_match = Regexp.new(Regexp.escape(error_text))
314
+ knife('diff /environments/x.json').should_succeed(/- "name": "x"/, :stderr => error_match)
279
315
  end
280
316
  end
281
317
  end
@@ -283,22 +319,26 @@ EOM
283
319
 
284
320
  with_versioned_cookbooks do
285
321
  when_the_chef_server "has one of each thing" do
286
- client 'x', '{}'
287
- cookbook 'x', '1.0.0', { 'metadata.rb' => 'version "1.0.0"' }
288
- data_bag 'x', { 'y' => '{}' }
289
- environment 'x', '{}'
290
- node 'x', '{}'
291
- role 'x', '{}'
292
- user 'x', '{}'
322
+ before do
323
+ client 'x', '{}'
324
+ cookbook 'x', '1.0.0'
325
+ data_bag 'x', { 'y' => '{}' }
326
+ environment 'x', '{}'
327
+ node 'x', '{}'
328
+ role 'x', '{}'
329
+ user 'x', '{}'
330
+ end
293
331
 
294
332
  when_the_repository 'has only top-level directories' do
295
- directory 'clients'
296
- directory 'cookbooks'
297
- directory 'data_bags'
298
- directory 'environments'
299
- directory 'nodes'
300
- directory 'roles'
301
- directory 'users'
333
+ before do
334
+ directory 'clients'
335
+ directory 'cookbooks'
336
+ directory 'data_bags'
337
+ directory 'environments'
338
+ directory 'nodes'
339
+ directory 'roles'
340
+ directory 'users'
341
+ end
302
342
 
303
343
  it 'knife diff reports everything as deleted' do
304
344
  knife('diff --name-status /').should_succeed <<EOM
@@ -318,17 +358,19 @@ EOM
318
358
  end
319
359
 
320
360
  when_the_repository 'has an identical copy of each thing' do
321
- file 'clients/chef-validator.json', { 'validator' => true, 'public_key' => ChefZero::PUBLIC_KEY }
322
- file 'clients/chef-webui.json', { 'admin' => true, 'public_key' => ChefZero::PUBLIC_KEY }
323
- file 'clients/x.json', { 'public_key' => ChefZero::PUBLIC_KEY }
324
- file 'cookbooks/x-1.0.0/metadata.rb', 'version "1.0.0"'
325
- file 'data_bags/x/y.json', {}
326
- file 'environments/_default.json', { "description" => "The default Chef environment" }
327
- file 'environments/x.json', {}
328
- file 'nodes/x.json', {}
329
- file 'roles/x.json', {}
330
- file 'users/admin.json', { 'admin' => true, 'public_key' => ChefZero::PUBLIC_KEY }
331
- file 'users/x.json', { 'public_key' => ChefZero::PUBLIC_KEY }
361
+ before do
362
+ file 'clients/chef-validator.json', { 'validator' => true, 'public_key' => ChefZero::PUBLIC_KEY }
363
+ file 'clients/chef-webui.json', { 'admin' => true, 'public_key' => ChefZero::PUBLIC_KEY }
364
+ file 'clients/x.json', { 'public_key' => ChefZero::PUBLIC_KEY }
365
+ file 'cookbooks/x-1.0.0/metadata.rb', cb_metadata("x", "1.0.0")
366
+ file 'data_bags/x/y.json', {}
367
+ file 'environments/_default.json', { "description" => "The default Chef environment" }
368
+ file 'environments/x.json', {}
369
+ file 'nodes/x.json', {}
370
+ file 'roles/x.json', {}
371
+ file 'users/admin.json', { 'admin' => true, 'public_key' => ChefZero::PUBLIC_KEY }
372
+ file 'users/x.json', { 'public_key' => ChefZero::PUBLIC_KEY }
373
+ end
332
374
 
333
375
  it 'knife diff reports no differences' do
334
376
  knife('diff /').should_succeed ''
@@ -343,11 +385,14 @@ EOM
343
385
  end
344
386
 
345
387
  context 'except the role file' do
346
- file 'roles/x.json', <<EOM
388
+ before do
389
+ file 'roles/x.json', <<EOM
347
390
  {
348
391
  "foo": "bar"
349
392
  }
350
393
  EOM
394
+ end
395
+
351
396
  it 'knife diff reports the role as different' do
352
397
  knife('diff --name-status /').should_succeed <<EOM
353
398
  M\t/roles/x.json
@@ -356,16 +401,18 @@ EOM
356
401
  end
357
402
 
358
403
  context 'as well as one extra copy of each thing' do
359
- file 'clients/y.json', {}
360
- file 'cookbooks/x-1.0.0/blah.rb', ''
361
- file 'cookbooks/x-2.0.0/metadata.rb', 'version "2.0.0"'
362
- file 'cookbooks/y-1.0.0/metadata.rb', 'version "1.0.0"'
363
- file 'data_bags/x/z.json', {}
364
- file 'data_bags/y/zz.json', {}
365
- file 'environments/y.json', {}
366
- file 'nodes/y.json', {}
367
- file 'roles/y.json', {}
368
- file 'users/y.json', {}
404
+ before do
405
+ file 'clients/y.json', {}
406
+ file 'cookbooks/x-1.0.0/blah.rb', ''
407
+ file 'cookbooks/x-2.0.0/metadata.rb', cb_metadata("x", "2.0.0")
408
+ file 'cookbooks/y-1.0.0/metadata.rb', cb_metadata("y", "1.0.0")
409
+ file 'data_bags/x/z.json', {}
410
+ file 'data_bags/y/zz.json', {}
411
+ file 'environments/y.json', {}
412
+ file 'nodes/y.json', {}
413
+ file 'roles/y.json', {}
414
+ file 'users/y.json', {}
415
+ end
369
416
 
370
417
  it 'knife diff reports the new files as added' do
371
418
  knife('diff --name-status /').should_succeed <<EOM
@@ -383,7 +430,7 @@ EOM
383
430
  end
384
431
 
385
432
  context 'when cwd is the data_bags directory' do
386
- cwd 'data_bags'
433
+ before { cwd 'data_bags' }
387
434
  it 'knife diff reports different data bags' do
388
435
  knife('diff --name-status').should_succeed <<EOM
389
436
  A\tx/z.json
@@ -416,12 +463,16 @@ EOM
416
463
  end
417
464
 
418
465
  when_the_repository 'has a cookbook' do
419
- file 'cookbooks/x-1.0.0/metadata.rb', 'version "1.0.0"'
420
- file 'cookbooks/x-1.0.0/onlyin1.0.0.rb', ''
466
+ before do
467
+ file 'cookbooks/x-1.0.0/metadata.rb', cb_metadata("x", "1.0.0")
468
+ file 'cookbooks/x-1.0.0/onlyin1.0.0.rb', ''
469
+ end
421
470
 
422
471
  when_the_chef_server 'has a later version for the cookbook' do
423
- cookbook 'x', '1.0.0', { 'metadata.rb' => 'version "1.0.0"', 'onlyin1.0.0.rb' => ''}
424
- cookbook 'x', '1.0.1', { 'metadata.rb' => 'version "1.0.1"', 'onlyin1.0.1.rb' => '' }
472
+ before do
473
+ cookbook 'x', '1.0.0', { 'onlyin1.0.0.rb' => ''}
474
+ cookbook 'x', '1.0.1', { 'onlyin1.0.1.rb' => '' }
475
+ end
425
476
 
426
477
  it 'knife diff /cookbooks shows differences' do
427
478
  knife('diff --name-status /cookbooks').should_succeed <<EOM
@@ -435,15 +486,19 @@ EOM
435
486
  end
436
487
 
437
488
  when_the_chef_server 'has an earlier version for the cookbook' do
438
- cookbook 'x', '1.0.0', { 'metadata.rb' => 'version "1.0.0"', 'onlyin1.0.0.rb' => '' }
439
- cookbook 'x', '0.9.9', { 'metadata.rb' => 'version "0.9.9"', 'onlyin0.9.9.rb' => '' }
489
+ before do
490
+ cookbook 'x', '1.0.0', { 'onlyin1.0.0.rb' => '' }
491
+ cookbook 'x', '0.9.9', { 'onlyin0.9.9.rb' => '' }
492
+ end
440
493
  it 'knife diff /cookbooks shows the differences' do
441
494
  knife('diff --name-status /cookbooks').should_succeed "D\t/cookbooks/x-0.9.9\n"
442
495
  end
443
496
  end
444
497
 
445
498
  when_the_chef_server 'has a later version for the cookbook, and no current version' do
446
- cookbook 'x', '1.0.1', { 'metadata.rb' => 'version "1.0.1"', 'onlyin1.0.1.rb' => '' }
499
+ before do
500
+ cookbook 'x', '1.0.1', { 'onlyin1.0.1.rb' => '' }
501
+ end
447
502
 
448
503
  it 'knife diff /cookbooks shows the differences' do
449
504
  knife('diff --name-status /cookbooks').should_succeed <<EOM
@@ -454,7 +509,9 @@ EOM
454
509
  end
455
510
 
456
511
  when_the_chef_server 'has an earlier version for the cookbook, and no current version' do
457
- cookbook 'x', '0.9.9', { 'metadata.rb' => 'version "0.9.9"', 'onlyin0.9.9.rb' => '' }
512
+ before do
513
+ cookbook 'x', '0.9.9', { 'onlyin0.9.9.rb' => '' }
514
+ end
458
515
 
459
516
  it 'knife diff /cookbooks shows the differences' do
460
517
  knife('diff --name-status /cookbooks').should_succeed <<EOM
@@ -467,15 +524,15 @@ EOM
467
524
 
468
525
  context 'json diff tests' do
469
526
  when_the_repository 'has an empty environment file' do
470
- file 'environments/x.json', {}
527
+ before { file 'environments/x.json', {} }
471
528
  when_the_chef_server 'has an empty environment' do
472
- environment 'x', {}
529
+ before { environment 'x', {} }
473
530
  it 'knife diff returns no differences' do
474
531
  knife('diff /environments/x.json').should_succeed ''
475
532
  end
476
533
  end
477
534
  when_the_chef_server 'has an environment with a different value' do
478
- environment 'x', { 'description' => 'hi' }
535
+ before { environment 'x', { 'description' => 'hi' } }
479
536
  it 'knife diff reports the difference', :pending => (RUBY_VERSION < "1.9") do
480
537
  knife('diff /environments/x.json').should_succeed(/
481
538
  {
@@ -489,15 +546,20 @@ EOM
489
546
  end
490
547
 
491
548
  when_the_repository 'has an environment file with a value in it' do
492
- file 'environments/x.json', { 'description' => 'hi' }
549
+ before do
550
+ file 'environments/x.json', { 'description' => 'hi' }
551
+ end
552
+
493
553
  when_the_chef_server 'has an environment with the same value' do
494
- environment 'x', { 'description' => 'hi' }
554
+ before do
555
+ environment 'x', { 'description' => 'hi' }
556
+ end
495
557
  it 'knife diff returns no differences' do
496
558
  knife('diff /environments/x.json').should_succeed ''
497
559
  end
498
560
  end
499
561
  when_the_chef_server 'has an environment with no value' do
500
- environment 'x', {}
562
+ before { environment 'x', {} }
501
563
  it 'knife diff reports the difference', :pending => (RUBY_VERSION < "1.9") do
502
564
  knife('diff /environments/x.json').should_succeed(/
503
565
  {
@@ -509,7 +571,9 @@ EOM
509
571
  end
510
572
  end
511
573
  when_the_chef_server 'has an environment with a different value' do
512
- environment 'x', { 'description' => 'lo' }
574
+ before do
575
+ environment 'x', { 'description' => 'lo' }
576
+ end
513
577
  it 'knife diff reports the difference', :pending => (RUBY_VERSION < "1.9") do
514
578
  knife('diff /environments/x.json').should_succeed(/
515
579
  {
@@ -524,11 +588,13 @@ EOM
524
588
  end
525
589
 
526
590
  when_the_chef_server 'has an environment' do
527
- environment 'x', {}
591
+ before { environment 'x', {} }
528
592
  when_the_repository 'has an environment with bad JSON' do
529
- file 'environments/x.json', '{'
593
+ before { file 'environments/x.json', '{' }
530
594
  it 'knife diff reports an error and does a textual diff' do
531
- knife('diff /environments/x.json').should_succeed(/- "name": "x"/, :stderr => "WARN: Parse error reading #{path_to('environments/x.json')} as JSON: A JSON text must at least contain two octets!\n")
595
+ error_text = "WARN: Parse error reading #{path_to('environments/x.json')} as JSON: parse error: premature EOF"
596
+ error_match = Regexp.new(Regexp.escape(error_text))
597
+ knife('diff /environments/x.json').should_succeed(/- "name": "x"/, :stderr => error_match)
532
598
  end
533
599
  end
534
600
  end