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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. checksums.yaml +4 -4
  2. data/lib/chef/application.rb +8 -1
  3. data/lib/chef/application/apply.rb +4 -0
  4. data/lib/chef/application/client.rb +7 -7
  5. data/lib/chef/application/solo.rb +21 -13
  6. data/lib/chef/chef_fs/chef_fs_data_store.rb +60 -6
  7. data/lib/chef/chef_fs/config.rb +78 -4
  8. data/lib/chef/chef_fs/data_handler/acl_data_handler.rb +2 -2
  9. data/lib/chef/chef_fs/data_handler/client_data_handler.rb +1 -1
  10. data/lib/chef/chef_fs/data_handler/container_data_handler.rb +1 -1
  11. data/lib/chef/chef_fs/data_handler/cookbook_data_handler.rb +1 -1
  12. data/lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb +1 -1
  13. data/lib/chef/chef_fs/data_handler/data_handler_base.rb +76 -2
  14. data/lib/chef/chef_fs/data_handler/environment_data_handler.rb +1 -1
  15. data/lib/chef/chef_fs/data_handler/group_data_handler.rb +1 -1
  16. data/lib/chef/chef_fs/data_handler/node_data_handler.rb +1 -1
  17. data/lib/chef/chef_fs/data_handler/organization_data_handler.rb +30 -0
  18. data/lib/chef/chef_fs/data_handler/organization_invites_data_handler.rb +17 -0
  19. data/lib/chef/chef_fs/data_handler/organization_members_data_handler.rb +17 -0
  20. data/lib/chef/chef_fs/data_handler/role_data_handler.rb +1 -1
  21. data/lib/chef/chef_fs/data_handler/user_data_handler.rb +2 -1
  22. data/lib/chef/chef_fs/file_system.rb +0 -1
  23. data/lib/chef/chef_fs/file_system/acl_entry.rb +1 -1
  24. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb +1 -1
  25. data/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +5 -1
  26. data/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb +73 -13
  27. data/lib/chef/chef_fs/file_system/chef_server_root_dir.rb +44 -5
  28. data/lib/chef/chef_fs/file_system/cookbook_dir.rb +1 -1
  29. data/lib/chef/chef_fs/file_system/cookbooks_dir.rb +3 -3
  30. data/lib/chef/chef_fs/file_system/org_entry.rb +34 -0
  31. data/lib/chef/chef_fs/file_system/organization_invites_entry.rb +58 -0
  32. data/lib/chef/chef_fs/file_system/organization_members_entry.rb +57 -0
  33. data/lib/chef/chef_fs/file_system/rest_list_entry.rb +13 -4
  34. data/lib/chef/chef_fs/knife.rb +1 -1
  35. data/lib/chef/client.rb +8 -2
  36. data/lib/chef/config.rb +75 -57
  37. data/lib/chef/config_fetcher.rb +6 -21
  38. data/lib/chef/dsl/data_query.rb +48 -3
  39. data/lib/chef/dsl/platform_introspection.rb +42 -0
  40. data/lib/chef/dsl/reboot_pending.rb +6 -3
  41. data/lib/chef/encrypted_data_bag_item.rb +1 -1
  42. data/lib/chef/encrypted_data_bag_item/encryptor.rb +12 -0
  43. data/lib/chef/exceptions.rb +2 -0
  44. data/lib/chef/http/basic_client.rb +14 -0
  45. data/lib/chef/http/json_output.rb +7 -2
  46. data/lib/chef/knife.rb +36 -121
  47. data/lib/chef/knife/bootstrap.rb +68 -54
  48. data/lib/chef/knife/bootstrap/archlinux-gems.erb +6 -1
  49. data/lib/chef/knife/bootstrap/chef-aix.erb +5 -0
  50. data/lib/chef/knife/bootstrap/chef-full.erb +5 -1
  51. data/lib/chef/knife/core/bootstrap_context.rb +70 -29
  52. data/lib/chef/knife/search.rb +56 -12
  53. data/lib/chef/knife/serve.rb +1 -1
  54. data/lib/chef/local_mode.rb +10 -4
  55. data/lib/chef/mixin/deep_merge.rb +6 -3
  56. data/lib/chef/mixin/shell_out.rb +33 -17
  57. data/lib/chef/null_logger.rb +72 -0
  58. data/lib/chef/platform.rb +2 -1
  59. data/lib/chef/platform/provider_mapping.rb +1 -1
  60. data/lib/chef/platform/rebooter.rb +54 -0
  61. data/lib/chef/provider/ifconfig.rb +15 -16
  62. data/lib/chef/provider/link.rb +1 -1
  63. data/lib/chef/provider/mount/mount.rb +1 -1
  64. data/lib/chef/provider/mount/solaris.rb +102 -64
  65. data/lib/chef/provider/package/aix.rb +4 -12
  66. data/lib/chef/provider/package/ips.rb +8 -12
  67. data/lib/chef/provider/package/macports.rb +4 -12
  68. data/lib/chef/provider/package/pacman.rb +2 -6
  69. data/lib/chef/provider/package/portage.rb +2 -6
  70. data/lib/chef/provider/package/rpm.rb +4 -12
  71. data/lib/chef/provider/package/solaris.rb +4 -12
  72. data/lib/chef/provider/reboot.rb +69 -0
  73. data/lib/chef/provider/service/debian.rb +10 -10
  74. data/lib/chef/provider/service/freebsd.rb +89 -73
  75. data/lib/chef/provider/service/gentoo.rb +2 -2
  76. data/lib/chef/provider/service/init.rb +6 -4
  77. data/lib/chef/provider/service/insserv.rb +3 -3
  78. data/lib/chef/provider/service/macosx.rb +2 -2
  79. data/lib/chef/provider/service/simple.rb +6 -4
  80. data/lib/chef/provider/service/solaris.rb +1 -1
  81. data/lib/chef/provider/service/systemd.rb +9 -9
  82. data/lib/chef/provider/service/upstart.rb +6 -6
  83. data/lib/chef/provider/subversion.rb +6 -6
  84. data/lib/chef/provider/user/dscl.rb +32 -28
  85. data/lib/chef/provider/user/windows.rb +6 -6
  86. data/lib/chef/provider/whyrun_safe_ruby_block.rb +1 -1
  87. data/lib/chef/providers.rb +1 -0
  88. data/lib/chef/recipe.rb +0 -1
  89. data/lib/chef/resource.rb +3 -5
  90. data/lib/chef/resource/mount.rb +9 -0
  91. data/lib/chef/resource/reboot.rb +48 -0
  92. data/lib/chef/resources.rb +1 -0
  93. data/lib/chef/run_context.rb +25 -0
  94. data/lib/chef/search/query.rb +122 -14
  95. data/lib/chef/util/path_helper.rb +54 -6
  96. data/lib/chef/util/windows/net_user.rb +4 -1
  97. data/lib/chef/version.rb +1 -1
  98. data/lib/chef/win32/api/file.rb +1 -5
  99. data/lib/chef/win32/api/net.rb +1 -0
  100. data/lib/chef/workstation_config_loader.rb +177 -0
  101. data/spec/functional/http/simple_spec.rb +57 -1
  102. data/spec/functional/mixin/shell_out_spec.rb +2 -2
  103. data/spec/functional/provider/whyrun_safe_ruby_block_spec.rb +51 -0
  104. data/spec/functional/rebooter_spec.rb +105 -0
  105. data/spec/functional/resource/deploy_revision_spec.rb +0 -4
  106. data/spec/functional/resource/file_spec.rb +26 -3
  107. data/spec/functional/resource/group_spec.rb +5 -3
  108. data/spec/functional/resource/link_spec.rb +16 -16
  109. data/spec/functional/resource/reboot_spec.rb +103 -0
  110. data/spec/integration/client/client_spec.rb +4 -8
  111. data/spec/integration/client/ipv6_spec.rb +1 -1
  112. data/spec/integration/knife/cookbook_api_ipv6_spec.rb +3 -2
  113. data/spec/integration/knife/delete_spec.rb +39 -0
  114. data/spec/integration/knife/deps_spec.rb +30 -20
  115. data/spec/integration/knife/download_spec.rb +77 -1
  116. data/spec/integration/knife/list_spec.rb +221 -0
  117. data/spec/integration/knife/raw_spec.rb +1 -1
  118. data/spec/integration/knife/show_spec.rb +2 -2
  119. data/spec/integration/knife/upload_spec.rb +154 -1
  120. data/spec/support/pedant/run_pedant.rb +0 -1
  121. data/spec/support/shared/functional/http.rb +8 -1
  122. data/spec/support/shared/integration/integration_helper.rb +11 -19
  123. data/spec/support/shared/unit/platform_introspector.rb +22 -0
  124. data/spec/unit/application/apply.rb +11 -1
  125. data/spec/unit/application/solo_spec.rb +19 -3
  126. data/spec/unit/chef_fs/config_spec.rb +58 -0
  127. data/spec/unit/config_fetcher_spec.rb +1 -3
  128. data/spec/unit/config_spec.rb +247 -220
  129. data/spec/unit/dsl/data_query_spec.rb +165 -23
  130. data/spec/unit/dsl/reboot_pending_spec.rb +1 -7
  131. data/spec/unit/encrypted_data_bag_item_spec.rb +1 -1
  132. data/spec/unit/knife/bootstrap_spec.rb +354 -182
  133. data/spec/unit/knife/core/bootstrap_context_spec.rb +67 -30
  134. data/spec/unit/knife_spec.rb +3 -30
  135. data/spec/unit/mixin/deep_merge_spec.rb +14 -0
  136. data/spec/unit/mixin/shell_out_spec.rb +134 -64
  137. data/spec/unit/provider/ifconfig/debian_spec.rb +19 -9
  138. data/spec/unit/provider/ifconfig/redhat_spec.rb +16 -14
  139. data/spec/unit/provider/ifconfig_spec.rb +3 -3
  140. data/spec/unit/provider/link_spec.rb +5 -5
  141. data/spec/unit/provider/mount/mount_spec.rb +10 -1
  142. data/spec/unit/provider/mount/solaris_spec.rb +185 -11
  143. data/spec/unit/provider/package/aix_spec.rb +5 -17
  144. data/spec/unit/provider/package/ips_spec.rb +8 -21
  145. data/spec/unit/provider/package/macports_spec.rb +12 -12
  146. data/spec/unit/provider/package/pacman_spec.rb +4 -12
  147. data/spec/unit/provider/package/portage_spec.rb +5 -15
  148. data/spec/unit/provider/package/rpm_spec.rb +7 -22
  149. data/spec/unit/provider/package/solaris_spec.rb +5 -16
  150. data/spec/unit/provider/service/arch_service_spec.rb +8 -14
  151. data/spec/unit/provider/service/debian_service_spec.rb +1 -1
  152. data/spec/unit/provider/service/freebsd_service_spec.rb +457 -225
  153. data/spec/unit/provider/service/gentoo_service_spec.rb +2 -2
  154. data/spec/unit/provider/service/init_service_spec.rb +10 -10
  155. data/spec/unit/provider/service/insserv_service_spec.rb +3 -4
  156. data/spec/unit/provider/service/invokercd_service_spec.rb +8 -9
  157. data/spec/unit/provider/service/macosx_spec.rb +5 -5
  158. data/spec/unit/provider/service/simple_service_spec.rb +4 -6
  159. data/spec/unit/provider/service/solaris_smf_service_spec.rb +1 -3
  160. data/spec/unit/provider/service/systemd_service_spec.rb +20 -20
  161. data/spec/unit/provider/service/upstart_service_spec.rb +15 -17
  162. data/spec/unit/provider/subversion_spec.rb +5 -6
  163. data/spec/unit/provider/user/dscl_spec.rb +2 -1
  164. data/spec/unit/provider/user/windows_spec.rb +7 -0
  165. data/spec/unit/provider/whyrun_safe_ruby_block_spec.rb +2 -2
  166. data/spec/unit/resource/mount_spec.rb +9 -0
  167. data/spec/unit/resource_spec.rb +0 -4
  168. data/spec/unit/rest_spec.rb +1 -1
  169. data/spec/unit/run_context_spec.rb +15 -0
  170. data/spec/unit/search/query_spec.rb +196 -40
  171. data/spec/unit/util/path_helper_spec.rb +111 -28
  172. data/spec/unit/workstation_config_loader_spec.rb +283 -0
  173. metadata +36 -20
  174. data/lib/chef/knife/bootstrap/centos5-gems.erb +0 -62
  175. data/lib/chef/knife/bootstrap/fedora13-gems.erb +0 -44
  176. data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +0 -53
  177. data/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb +0 -48
  178. data/lib/chef/knife/bootstrap/ubuntu12.04-gems.erb +0 -46
  179. data/spec/support/shared/integration/chef_zero_support.rb +0 -130
  180. data/spec/unit/knife/config_file_selection_spec.rb +0 -135
@@ -487,7 +487,7 @@ EOM
487
487
  Updated /cookbooks/x
488
488
  EOM
489
489
  # Modify a file and attempt to upload
490
- file 'cookbooks/x/metadata.rb', "name 'x'; version '1.0.0'#different"
490
+ file 'cookbooks/x/metadata.rb', 'name "x"; version "1.0.0"#different'
491
491
  knife('upload /cookbooks/x').should_fail "ERROR: /cookbooks failed to write: Cookbook x is frozen\n"
492
492
  end
493
493
  end
@@ -1216,4 +1216,157 @@ EOM
1216
1216
  end
1217
1217
  end
1218
1218
  end
1219
+
1220
+ when_the_chef_server "is in Enterprise mode", :osc_compat => false, :single_org => false do
1221
+ before do
1222
+ user 'foo', {}
1223
+ user 'bar', {}
1224
+ user 'foobar', {}
1225
+ organization 'foo', { 'full_name' => 'Something'}
1226
+ end
1227
+
1228
+ before :each do
1229
+ Chef::Config.chef_server_url = URI.join(Chef::Config.chef_server_url, '/organizations/foo')
1230
+ end
1231
+
1232
+ context 'and has nothing but a single group named blah' do
1233
+ group 'blah', {}
1234
+
1235
+ when_the_repository 'has one of each thing' do
1236
+
1237
+ before do
1238
+ # TODO We have to upload acls for an existing group due to a lack of
1239
+ # dependency detection during upload. Fix that!
1240
+ file 'acls/groups/blah.json', {}
1241
+ file 'clients/x.json', { 'public_key' => ChefZero::PUBLIC_KEY }
1242
+ file 'containers/x.json', {}
1243
+ file 'cookbooks/x/metadata.rb', cb_metadata("x", "1.0.0")
1244
+ file 'data_bags/x/y.json', {}
1245
+ file 'environments/x.json', {}
1246
+ file 'groups/x.json', {}
1247
+ file 'invitations.json', [ 'foo' ]
1248
+ file 'members.json', [ 'bar' ]
1249
+ file 'nodes/x.json', {}
1250
+ file 'org.json', { 'full_name' => 'wootles' }
1251
+ file 'roles/x.json', {}
1252
+ end
1253
+
1254
+ it 'knife upload / uploads everything' do
1255
+ knife('upload /').should_succeed <<EOM
1256
+ Updated /acls/groups/blah.json
1257
+ Created /clients/x.json
1258
+ Created /containers/x.json
1259
+ Created /cookbooks/x
1260
+ Created /data_bags/x
1261
+ Created /data_bags/x/y.json
1262
+ Created /environments/x.json
1263
+ Created /groups/x.json
1264
+ Updated /invitations.json
1265
+ Updated /members.json
1266
+ Created /nodes/x.json
1267
+ Updated /org.json
1268
+ Created /roles/x.json
1269
+ EOM
1270
+ api.get('association_requests').map { |a| a['username'] }.should == [ 'foo' ]
1271
+ api.get('users').map { |a| a['user']['username'] }.should == [ 'bar' ]
1272
+ end
1273
+ end
1274
+
1275
+ when_the_repository 'has an org.json that does not change full_name' do
1276
+ before do
1277
+ file 'org.json', { 'full_name' => 'Something' }
1278
+ end
1279
+
1280
+ it 'knife upload / emits a warning for bar and adds foo and foobar' do
1281
+ knife('upload /').should_succeed ''
1282
+ api.get('/')['full_name'].should == 'Something'
1283
+ end
1284
+ end
1285
+
1286
+ when_the_repository 'has an org.json that changes full_name' do
1287
+ before do
1288
+ file 'org.json', { 'full_name' => 'Something Else'}
1289
+ end
1290
+
1291
+ it 'knife upload / emits a warning for bar and adds foo and foobar' do
1292
+ knife('upload /').should_succeed "Updated /org.json\n"
1293
+ api.get('/')['full_name'].should == 'Something Else'
1294
+ end
1295
+ end
1296
+
1297
+ context 'and has invited foo and bar is already a member' do
1298
+ org_invite 'foo'
1299
+ org_member 'bar'
1300
+
1301
+ when_the_repository 'wants to invite foo, bar and foobar' do
1302
+ before do
1303
+ file 'invitations.json', [ 'foo', 'bar', 'foobar' ]
1304
+ end
1305
+
1306
+ it 'knife upload / emits a warning for bar and invites foobar' do
1307
+ knife('upload /').should_succeed "Updated /invitations.json\n", :stderr => "WARN: Could not invite bar to organization foo: User bar is already in organization foo\n"
1308
+ api.get('association_requests').map { |a| a['username'] }.should == [ 'foo', 'foobar' ]
1309
+ api.get('users').map { |a| a['user']['username'] }.should == [ 'bar' ]
1310
+ end
1311
+ end
1312
+
1313
+ when_the_repository 'wants to make foo, bar and foobar members' do
1314
+ before do
1315
+ file 'members.json', [ 'foo', 'bar', 'foobar' ]
1316
+ end
1317
+
1318
+ it 'knife upload / emits a warning for bar and adds foo and foobar' do
1319
+ knife('upload /').should_succeed "Updated /members.json\n"
1320
+ api.get('association_requests').map { |a| a['username'] }.should == [ ]
1321
+ api.get('users').map { |a| a['user']['username'] }.should == [ 'bar', 'foo', 'foobar' ]
1322
+ end
1323
+ end
1324
+
1325
+ when_the_repository 'wants to invite foo and have bar as a member' do
1326
+ before do
1327
+ file 'invitations.json', [ 'foo' ]
1328
+ file 'members.json', [ 'bar' ]
1329
+ end
1330
+
1331
+ it 'knife upload / does nothing' do
1332
+ knife('upload /').should_succeed ''
1333
+ api.get('association_requests').map { |a| a['username'] }.should == [ 'foo' ]
1334
+ api.get('users').map { |a| a['user']['username'] }.should == [ 'bar' ]
1335
+ end
1336
+ end
1337
+ end
1338
+
1339
+ context 'and has invited bar and foo' do
1340
+ org_invite 'bar', 'foo'
1341
+
1342
+ when_the_repository 'wants to invite foo and bar (different order)' do
1343
+ before do
1344
+ file 'invitations.json', [ 'foo', 'bar' ]
1345
+ end
1346
+
1347
+ it 'knife upload / does nothing' do
1348
+ knife('upload /').should_succeed ''
1349
+ api.get('association_requests').map { |a| a['username'] }.should == [ 'bar', 'foo' ]
1350
+ api.get('users').map { |a| a['user']['username'] }.should == [ ]
1351
+ end
1352
+ end
1353
+ end
1354
+
1355
+ context 'and has already added bar and foo as members of the org' do
1356
+ org_member 'bar', 'foo'
1357
+
1358
+ when_the_repository 'wants to add foo and bar (different order)' do
1359
+ before do
1360
+ file 'members.json', [ 'foo', 'bar' ]
1361
+ end
1362
+
1363
+ it 'knife upload / does nothing' do
1364
+ knife('upload /').should_succeed ''
1365
+ api.get('association_requests').map { |a| a['username'] }.should == [ ]
1366
+ api.get('users').map { |a| a['user']['username'] }.should == [ 'bar', 'foo' ]
1367
+ end
1368
+ end
1369
+ end
1370
+ end
1371
+ end
1219
1372
  end
@@ -25,7 +25,6 @@ def start_server(chef_repo_path)
25
25
  Chef::Config.versioned_cookbooks = true
26
26
  chef_fs = Chef::ChefFS::Config.new.local_fs
27
27
  data_store = Chef::ChefFS::ChefFSDataStore.new(chef_fs)
28
- data_store = ChefZero::DataStore::V1ToV2Adapter.new(data_store, 'chef', :org_defaults => ChefZero::DataStore::V1ToV2Adapter::ORG_DEFAULTS)
29
28
  server = ChefZero::Server.new(:port => 8889.upto(9999), :data_store => data_store)#, :log_level => :debug)
30
29
  server.start_background
31
30
  server
@@ -155,6 +155,14 @@ module ChefHTTPShared
155
155
  }
156
156
  )
157
157
 
158
+ @api.post('/posty', 200, 'Hi!')
159
+
160
+ #
161
+ # 400 with an error
162
+ #
163
+ @api.get('/bad_request', 400, '{ "error": [ "Your request is just terrible." ] }')
164
+ @api.post('/bad_request', 400, '{ "error": [ "Your request is just terrible." ] }')
165
+
158
166
  end
159
167
 
160
168
  def stop_tiny_server
@@ -239,4 +247,3 @@ shared_examples_for "downloading all the things" do
239
247
  it_behaves_like "a 403 after a successful request when reusing the request object"
240
248
  end
241
249
  end
242
-
@@ -20,33 +20,23 @@
20
20
  require 'tmpdir'
21
21
  require 'fileutils'
22
22
  require 'chef/config'
23
-
24
- # Temporarily use our own copy of chef-zero rspec integration.
25
- # See support/shared/integration/chef_zero_support for details
26
- #require 'chef_zero/rspec'
27
- require 'support/shared/integration/chef_zero_support'
28
-
29
23
  require 'chef/json_compat'
24
+ require 'chef/server_api'
25
+ require 'chef_zero/rspec'
30
26
  require 'support/shared/integration/knife_support'
31
27
  require 'support/shared/integration/app_server_support'
32
28
  require 'spec_helper'
33
29
 
34
30
  module IntegrationSupport
35
- include ChefZeroSupport
31
+ include ChefZero::RSpec
36
32
 
37
33
  module ClassMethods
38
-
39
- def when_the_chef_server(desc, *tags, &block)
40
- context("when the chef server #{desc}", *tags) do
41
- #include ChefZero::RSpec::Fixtures
42
- include_context "With chef-zero running"
43
- module_eval(&block)
44
- end
45
- end
34
+ include ChefZero::RSpec
46
35
 
47
36
  def when_the_repository(desc, *tags, &block)
48
37
  context("when the chef repo #{desc}", *tags) do
49
38
  include_context "with a chef repo"
39
+
50
40
  module_eval(&block)
51
41
  end
52
42
  end
@@ -63,6 +53,10 @@ module IntegrationSupport
63
53
  includer_class.extend(ClassMethods)
64
54
  end
65
55
 
56
+ def api
57
+ Chef::ServerAPI.new
58
+ end
59
+
66
60
  def directory(relative_path, &block)
67
61
  old_parent_path = @parent_path
68
62
  @parent_path = path_to(relative_path)
@@ -77,10 +71,8 @@ module IntegrationSupport
77
71
  FileUtils.mkdir_p(dir) unless dir == '.'
78
72
  File.open(filename, 'w') do |file|
79
73
  raw = case contents
80
- when Hash
74
+ when Hash, Array
81
75
  JSON.pretty_generate(contents)
82
- when Array
83
- contents.join("\n")
84
76
  else
85
77
  contents
86
78
  end
@@ -101,7 +93,7 @@ module IntegrationSupport
101
93
  end
102
94
 
103
95
  def cb_metadata(name, version, extra_text="")
104
- "name '#{name}'; version '#{version}'#{extra_text}"
96
+ "name #{name.inspect}; version #{version.inspect}#{extra_text}"
105
97
  end
106
98
 
107
99
  def cwd(relative_path)
@@ -29,6 +29,10 @@ shared_examples_for "a platform introspector" do
29
29
  end
30
30
  @platform_hash["debian"] = {["5", "6"] => "debian-5/6", "default" => "debian"}
31
31
  @platform_hash["default"] = "default"
32
+ # The following @platform_hash keys are used for testing version constraints
33
+ @platform_hash['exact_match'] = { '1.2.3' => 'exact', '>= 1.0' => 'not exact'}
34
+ @platform_hash['multiple_matches'] = { '~> 2.3.4' => 'matched ~> 2.3.4', '>= 2.3' => 'matched >=2.3' }
35
+ @platform_hash['successful_matches'] = { '< 3.0' => 'matched < 3.0', '>= 3.0' => 'matched >= 3.0' }
32
36
 
33
37
  @platform_family_hash = {
34
38
  "debian" => "debian value",
@@ -79,6 +83,24 @@ shared_examples_for "a platform introspector" do
79
83
  platform_introspector.value_for_platform(@platform_hash).should == "openbsd"
80
84
  end
81
85
 
86
+ it 'returns the exact match' do
87
+ node.automatic_attrs[:platform] = 'exact_match'
88
+ node.automatic_attrs[:platform_version] = '1.2.3'
89
+ platform_introspector.value_for_platform(@platform_hash).should == 'exact'
90
+ end
91
+
92
+ it 'raises RuntimeError' do
93
+ node.automatic_attrs[:platform] = 'multiple_matches'
94
+ node.automatic_attrs[:platform_version] = '2.3.4'
95
+ expect {platform_introspector.value_for_platform(@platform_hash)}.to raise_error(RuntimeError)
96
+ end
97
+
98
+ it 'should return the value for that match' do
99
+ node.automatic_attrs[:platform] = 'successful_matches'
100
+ node.automatic_attrs[:platform_version] = '2.9'
101
+ platform_introspector.value_for_platform(@platform_hash).should == 'matched < 3.0'
102
+ end
103
+
82
104
  describe "when platform versions is an array" do
83
105
  it "returns a version-specific value based on the current platform" do
84
106
  node.automatic_attrs[:platform] = "debian"
@@ -20,7 +20,7 @@ require 'spec_helper'
20
20
  describe Chef::Application::Apply do
21
21
 
22
22
  before do
23
- @app = Chef::Application::Recipe.new
23
+ @app = Chef::Application::Apply.new
24
24
  @app.stub(:configure_logging).and_return(true)
25
25
  @recipe_text = "package 'nyancat'"
26
26
  Chef::Config[:solo] = true
@@ -73,4 +73,14 @@ describe Chef::Application::Apply do
73
73
  @recipe_fh.path.should == @app.instance_variable_get(:@recipe_filename)
74
74
  end
75
75
  end
76
+ describe "recipe_file_arg" do
77
+ before do
78
+ ARGV.clear
79
+ end
80
+ it "should exit and log message" do
81
+ Chef::Log.should_receive(:debug).with(/^No recipe file provided/)
82
+ lambda { @app.run }.should raise_error(SystemExit) { |e| e.status.should == 1 }
83
+ end
84
+
85
+ end
76
86
  end
@@ -49,7 +49,6 @@ describe Chef::Application::Solo do
49
49
  end
50
50
 
51
51
  describe "when the json_attribs configuration option is specified" do
52
-
53
52
  let(:json_attribs) { {"a" => "b"} }
54
53
  let(:config_fetcher) { double(Chef::ConfigFetcher, :fetch_json => json_attribs) }
55
54
  let(:json_source) { "https://foo.com/foo.json" }
@@ -66,8 +65,6 @@ describe Chef::Application::Solo do
66
65
  end
67
66
  end
68
67
 
69
-
70
-
71
68
  describe "when the recipe_url configuration option is specified" do
72
69
  before do
73
70
  Chef::Config[:cookbook_path] = "#{Dir.tmpdir}/chef-solo/cookbooks"
@@ -104,6 +101,25 @@ describe Chef::Application::Solo do
104
101
  end
105
102
  end
106
103
 
104
+ describe "when the json_attribs and recipe_url configuration options are both specified" do
105
+ let(:json_attribs) { {"a" => "b"} }
106
+ let(:config_fetcher) { double(Chef::ConfigFetcher, :fetch_json => json_attribs) }
107
+ let(:json_source) { "https://foo.com/foo.json" }
108
+
109
+ before do
110
+ Chef::Config[:json_attribs] = json_source
111
+ Chef::Config[:recipe_url] = "http://icanhas.cheezburger.com/lolcats"
112
+ Chef::Config[:cookbook_path] = "#{Dir.tmpdir}/chef-solo/cookbooks"
113
+ FileUtils.stub(:mkdir_p).and_return(true)
114
+ Chef::Mixin::Command.stub(:run_command).and_return(true)
115
+ end
116
+
117
+ it "should fetch the recipe_url first" do
118
+ @app.should_receive(:fetch_recipe_tarball).ordered
119
+ Chef::ConfigFetcher.should_receive(:new).ordered.and_return(config_fetcher)
120
+ @app.reconfigure
121
+ end
122
+ end
107
123
 
108
124
  describe "after the application has been configured" do
109
125
  before do
@@ -0,0 +1,58 @@
1
+ #
2
+ # Author:: Jess Mink (<jmink@getchef.com>)
3
+ # Copyright:: Copyright (c) 2014 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'spec_helper'
20
+ require 'chef/exceptions'
21
+ require 'lib/chef/chef_fs/config.rb'
22
+
23
+ describe Chef::ChefFS::Config do
24
+ describe "initialize" do
25
+ it "warns when hosted setups use 'everything'" do
26
+ base_config = Hash.new()
27
+ base_config[:repo_mode] = 'everything'
28
+ base_config[:chef_server_url] = 'http://foo.com/organizations/fake_org/'
29
+
30
+ ui = double("ui")
31
+ expect(ui).to receive(:warn)
32
+
33
+ Chef::ChefFS::Config.new(base_config, Dir.pwd, {}, ui)
34
+ end
35
+
36
+ it "doesn't warn when hosted setups use 'hosted_everything'" do
37
+ base_config = Hash.new()
38
+ base_config[:repo_mode] = 'hosted_everything'
39
+ base_config[:chef_server_url] = 'http://foo.com/organizations/fake_org/'
40
+
41
+ ui = double("ui")
42
+ expect(ui).to receive(:warn).exactly(0).times
43
+
44
+ Chef::ChefFS::Config.new(base_config, Dir.pwd, {}, ui)
45
+ end
46
+
47
+ it "doesn't warn when non-hosted setups use 'everything'" do
48
+ base_config = Hash.new()
49
+ base_config[:repo_mode] = 'everything'
50
+ base_config[:chef_server_url] = 'http://foo.com/'
51
+
52
+ ui = double("ui")
53
+ expect(ui).to receive(:warn).exactly(0).times
54
+
55
+ Chef::ChefFS::Config.new(base_config, Dir.pwd, {}, ui)
56
+ end
57
+ end
58
+ end
@@ -8,9 +8,7 @@ describe Chef::ConfigFetcher do
8
8
  let(:config_location_regex) { Regexp.escape(config_location) }
9
9
  let(:invalid_json_error_regex) { %r[Could not parse the provided JSON file \(#{config_location_regex}\)] }
10
10
 
11
- let(:config_jail_path) { nil }
12
-
13
- let(:fetcher) { Chef::ConfigFetcher.new(config_location, config_jail_path) }
11
+ let(:fetcher) { Chef::ConfigFetcher.new(config_location) }
14
12
 
15
13
  context "when loading a local file" do
16
14
  let(:config_location) { "/etc/chef/client.rb" }
@@ -19,6 +19,7 @@
19
19
 
20
20
  require 'spec_helper'
21
21
  require 'chef/exceptions'
22
+ require 'chef/util/path_helper'
22
23
 
23
24
  describe Chef::Config do
24
25
  describe "config attribute writer: chef_server_url" do
@@ -117,278 +118,304 @@ describe Chef::Config do
117
118
 
118
119
  end
119
120
 
120
- describe "class method: plaform_specific_path" do
121
- it "should return given path on non-windows systems" do
122
- platform_mock :unix do
123
- path = "/etc/chef/cookbooks"
124
- Chef::Config.platform_specific_path(path).should == "/etc/chef/cookbooks"
125
- end
126
- end
121
+ [ false, true ].each do |is_windows|
127
122
 
128
- it "should return a windows path on windows systems" do
129
- platform_mock :windows do
130
- path = "/etc/chef/cookbooks"
131
- Chef::Config.stub(:env).and_return({ 'SYSTEMDRIVE' => 'C:' })
132
- # match on a regex that looks for the base path with an optional
133
- # system drive at the beginning (c:)
134
- # system drive is not hardcoded b/c it can change and b/c it is not present on linux systems
135
- Chef::Config.platform_specific_path(path).should == "C:\\chef\\cookbooks"
123
+ context "On #{is_windows ? 'Windows' : 'Unix'}" do
124
+ def to_platform(*args)
125
+ Chef::Config.platform_specific_path(*args)
136
126
  end
137
- end
138
- end
139
127
 
140
- describe "default values" do
141
- def primary_cache_path
142
- if windows?
143
- "#{Chef::Config.env['SYSTEMDRIVE']}\\chef"
144
- else
145
- "/var/chef"
128
+ before :each do
129
+ Chef::Platform.stub(:windows?).and_return(is_windows)
146
130
  end
147
- end
148
131
 
149
- def secondary_cache_path
150
- if windows?
151
- "#{Chef::Config[:user_home]}\\.chef"
152
- else
153
- "#{Chef::Config[:user_home]}/.chef"
132
+ describe "class method: platform_specific_path" do
133
+ if is_windows
134
+ it "should return a windows path on windows systems" do
135
+ path = "/etc/chef/cookbooks"
136
+ Chef::Config.stub(:env).and_return({ 'SYSTEMDRIVE' => 'C:' })
137
+ # match on a regex that looks for the base path with an optional
138
+ # system drive at the beginning (c:)
139
+ # system drive is not hardcoded b/c it can change and b/c it is not present on linux systems
140
+ Chef::Config.platform_specific_path(path).should == "C:\\chef\\cookbooks"
141
+ end
142
+ else
143
+ it "should return given path on non-windows systems" do
144
+ path = "/etc/chef/cookbooks"
145
+ Chef::Config.platform_specific_path(path).should == "/etc/chef/cookbooks"
146
+ end
147
+ end
154
148
  end
155
- end
156
149
 
157
- before do
158
- if windows?
159
- Chef::Config.stub(:env).and_return({ 'SYSTEMDRIVE' => 'C:' })
160
- Chef::Config[:user_home] = 'C:\Users\charlie'
161
- else
162
- Chef::Config[:user_home] = '/Users/charlie'
163
- end
150
+ describe "default values" do
151
+ let :primary_cache_path do
152
+ if is_windows
153
+ "#{Chef::Config.env['SYSTEMDRIVE']}\\chef"
154
+ else
155
+ "/var/chef"
156
+ end
157
+ end
164
158
 
165
- Chef::Config.stub(:path_accessible?).and_return(false)
166
- end
159
+ let :secondary_cache_path do
160
+ if is_windows
161
+ "#{Chef::Config[:user_home]}\\.chef"
162
+ else
163
+ "#{Chef::Config[:user_home]}/.chef"
164
+ end
165
+ end
167
166
 
168
- describe "Chef::Config[:cache_path]" do
169
- context "when /var/chef exists and is accessible" do
170
- it "defaults to /var/chef" do
171
- Chef::Config.stub(:path_accessible?).with(Chef::Config.platform_specific_path("/var/chef")).and_return(true)
172
- Chef::Config[:cache_path].should == primary_cache_path
167
+ before do
168
+ if is_windows
169
+ Chef::Config.stub(:env).and_return({ 'SYSTEMDRIVE' => 'C:' })
170
+ Chef::Config[:user_home] = 'C:\Users\charlie'
171
+ else
172
+ Chef::Config[:user_home] = '/Users/charlie'
173
+ end
174
+
175
+ Chef::Config.stub(:path_accessible?).and_return(false)
173
176
  end
174
- end
175
177
 
176
- context "when /var/chef does not exist and /var is accessible" do
177
- it "defaults to /var/chef" do
178
- File.stub(:exists?).with(Chef::Config.platform_specific_path("/var/chef")).and_return(false)
179
- Chef::Config.stub(:path_accessible?).with(Chef::Config.platform_specific_path("/var")).and_return(true)
180
- Chef::Config[:cache_path].should == primary_cache_path
178
+ describe "Chef::Config[:cache_path]" do
179
+ context "when /var/chef exists and is accessible" do
180
+ it "defaults to /var/chef" do
181
+ Chef::Config.stub(:path_accessible?).with(to_platform("/var/chef")).and_return(true)
182
+ Chef::Config[:cache_path].should == primary_cache_path
183
+ end
184
+ end
185
+
186
+ context "when /var/chef does not exist and /var is accessible" do
187
+ it "defaults to /var/chef" do
188
+ File.stub(:exists?).with(to_platform("/var/chef")).and_return(false)
189
+ Chef::Config.stub(:path_accessible?).with(to_platform("/var")).and_return(true)
190
+ Chef::Config[:cache_path].should == primary_cache_path
191
+ end
192
+ end
193
+
194
+ context "when /var/chef does not exist and /var is not accessible" do
195
+ it "defaults to $HOME/.chef" do
196
+ File.stub(:exists?).with(to_platform("/var/chef")).and_return(false)
197
+ Chef::Config.stub(:path_accessible?).with(to_platform("/var")).and_return(false)
198
+ Chef::Config[:cache_path].should == secondary_cache_path
199
+ end
200
+ end
201
+
202
+ context "when /var/chef exists and is not accessible" do
203
+ it "defaults to $HOME/.chef" do
204
+ File.stub(:exists?).with(to_platform("/var/chef")).and_return(true)
205
+ File.stub(:readable?).with(to_platform("/var/chef")).and_return(true)
206
+ File.stub(:writable?).with(to_platform("/var/chef")).and_return(false)
207
+
208
+ Chef::Config[:cache_path].should == secondary_cache_path
209
+ end
210
+ end
211
+
212
+ context "when chef is running in local mode" do
213
+ before do
214
+ Chef::Config.local_mode = true
215
+ end
216
+
217
+ context "and config_dir is /a/b/c" do
218
+ before do
219
+ Chef::Config.config_dir to_platform('/a/b/c')
220
+ end
221
+
222
+ it "cache_path is /a/b/c/local-mode-cache" do
223
+ Chef::Config.cache_path.should == to_platform('/a/b/c/local-mode-cache')
224
+ end
225
+ end
226
+
227
+ context "and config_dir is /a/b/c/" do
228
+ before do
229
+ Chef::Config.config_dir to_platform('/a/b/c/')
230
+ end
231
+
232
+ it "cache_path is /a/b/c/local-mode-cache" do
233
+ Chef::Config.cache_path.should == to_platform('/a/b/c/local-mode-cache')
234
+ end
235
+ end
236
+ end
181
237
  end
182
- end
183
238
 
184
- context "when /var/chef does not exist and /var is not accessible" do
185
- it "defaults to $HOME/.chef" do
186
- File.stub(:exists?).with(Chef::Config.platform_specific_path("/var/chef")).and_return(false)
187
- Chef::Config.stub(:path_accessible?).with(Chef::Config.platform_specific_path("/var")).and_return(false)
188
- Chef::Config[:cache_path].should == secondary_cache_path
239
+ it "Chef::Config[:file_backup_path] defaults to /var/chef/backup" do
240
+ Chef::Config.stub(:cache_path).and_return(primary_cache_path)
241
+ backup_path = is_windows ? "#{primary_cache_path}\\backup" : "#{primary_cache_path}/backup"
242
+ Chef::Config[:file_backup_path].should == backup_path
189
243
  end
190
- end
191
244
 
192
- context "when /var/chef exists and is not accessible" do
193
- it "defaults to $HOME/.chef" do
194
- File.stub(:exists?).with(Chef::Config.platform_specific_path("/var/chef")).and_return(true)
195
- File.stub(:readable?).with(Chef::Config.platform_specific_path("/var/chef")).and_return(true)
196
- File.stub(:writable?).with(Chef::Config.platform_specific_path("/var/chef")).and_return(false)
245
+ it "Chef::Config[:ssl_verify_mode] defaults to :verify_none" do
246
+ Chef::Config[:ssl_verify_mode].should == :verify_none
247
+ end
197
248
 
198
- Chef::Config[:cache_path].should == secondary_cache_path
249
+ it "Chef::Config[:ssl_ca_path] defaults to nil" do
250
+ Chef::Config[:ssl_ca_path].should be_nil
199
251
  end
200
- end
201
- end
202
252
 
203
- it "Chef::Config[:file_backup_path] defaults to /var/chef/backup" do
204
- Chef::Config.stub(:cache_path).and_return(primary_cache_path)
205
- backup_path = windows? ? "#{primary_cache_path}\\backup" : "#{primary_cache_path}/backup"
206
- Chef::Config[:file_backup_path].should == backup_path
207
- end
253
+ # TODO can this be removed?
254
+ if !is_windows
255
+ it "Chef::Config[:ssl_ca_file] defaults to nil" do
256
+ Chef::Config[:ssl_ca_file].should be_nil
257
+ end
258
+ end
208
259
 
209
- it "Chef::Config[:ssl_verify_mode] defaults to :verify_none" do
210
- Chef::Config[:ssl_verify_mode].should == :verify_none
211
- end
260
+ it "Chef::Config[:data_bag_path] defaults to /var/chef/data_bags" do
261
+ Chef::Config.stub(:cache_path).and_return(primary_cache_path)
262
+ data_bag_path = is_windows ? "#{primary_cache_path}\\data_bags" : "#{primary_cache_path}/data_bags"
263
+ Chef::Config[:data_bag_path].should == data_bag_path
264
+ end
212
265
 
213
- it "Chef::Config[:ssl_ca_path] defaults to nil" do
214
- Chef::Config[:ssl_ca_path].should be_nil
215
- end
266
+ it "Chef::Config[:environment_path] defaults to /var/chef/environments" do
267
+ Chef::Config.stub(:cache_path).and_return(primary_cache_path)
268
+ environment_path = is_windows ? "#{primary_cache_path}\\environments" : "#{primary_cache_path}/environments"
269
+ Chef::Config[:environment_path].should == environment_path
270
+ end
216
271
 
217
- describe "when on UNIX" do
218
- before do
219
- Chef::Config.stub(:on_windows?).and_return(false)
220
- end
272
+ describe "setting the config dir" do
221
273
 
222
- it "Chef::Config[:ssl_ca_file] defaults to nil" do
223
- Chef::Config[:ssl_ca_file].should be_nil
224
- end
225
- end
274
+ context "when the config file is /etc/chef/client.rb" do
226
275
 
227
- it "Chef::Config[:data_bag_path] defaults to /var/chef/data_bags" do
228
- Chef::Config.stub(:cache_path).and_return(primary_cache_path)
229
- data_bag_path = windows? ? "#{primary_cache_path}\\data_bags" : "#{primary_cache_path}/data_bags"
230
- Chef::Config[:data_bag_path].should == data_bag_path
231
- end
276
+ before do
277
+ Chef::Config.config_file = to_platform("/etc/chef/client.rb")
278
+ end
232
279
 
233
- it "Chef::Config[:environment_path] defaults to /var/chef/environments" do
234
- Chef::Config.stub(:cache_path).and_return(primary_cache_path)
235
- environment_path = windows? ? "#{primary_cache_path}\\environments" : "#{primary_cache_path}/environments"
236
- Chef::Config[:environment_path].should == environment_path
237
- end
280
+ it "config_dir is /etc/chef" do
281
+ Chef::Config.config_dir.should == to_platform("/etc/chef")
282
+ end
238
283
 
239
- describe "joining platform specific paths" do
284
+ context "and chef is running in local mode" do
285
+ before do
286
+ Chef::Config.local_mode = true
287
+ end
240
288
 
241
- context "on UNIX" do
242
- before do
243
- Chef::Config.stub(:on_windows?).and_return(false)
244
- end
289
+ it "config_dir is /etc/chef" do
290
+ Chef::Config.config_dir.should == to_platform("/etc/chef")
291
+ end
292
+ end
245
293
 
246
- it "joins components when some end with separators" do
247
- Chef::Config.path_join("/foo/", "bar", "baz").should == "/foo/bar/baz"
248
- end
294
+ context "when config_dir is set to /other/config/dir/" do
295
+ before do
296
+ Chef::Config.config_dir = to_platform("/other/config/dir/")
297
+ end
249
298
 
250
- it "joins components that don't end in separators" do
251
- Chef::Config.path_join("/foo", "bar", "baz").should == "/foo/bar/baz"
252
- end
299
+ it "yields the explicit value" do
300
+ Chef::Config.config_dir.should == to_platform("/other/config/dir/")
301
+ end
302
+ end
253
303
 
254
- end
304
+ end
255
305
 
256
- context "on Windows" do
257
- before do
258
- Chef::Config.stub(:on_windows?).and_return(true)
259
- end
306
+ context "when the user's home dir is /home/charlie/" do
307
+ before do
308
+ Chef::Config.user_home = to_platform("/home/charlie")
309
+ end
260
310
 
261
- it "joins components with the windows separator" do
262
- Chef::Config.path_join('c:\\foo\\', 'bar', "baz").should == 'c:\\foo\\bar\\baz'
263
- end
264
- end
265
- end
311
+ it "config_dir is /home/charlie/.chef/" do
312
+ Chef::Config.config_dir.should == Chef::Util::PathHelper.join(to_platform("/home/charlie/.chef"), '')
313
+ end
266
314
 
267
- describe "setting the config dir" do
315
+ context "and chef is running in local mode" do
316
+ before do
317
+ Chef::Config.local_mode = true
318
+ end
268
319
 
269
- before do
270
- Chef::Config.stub(:on_windows?).and_return(false)
271
- Chef::Config.config_file = "/etc/chef/client.rb"
272
- end
320
+ it "config_dir is /home/charlie/.chef/" do
321
+ Chef::Config.config_dir.should == Chef::Util::PathHelper.join(to_platform("/home/charlie/.chef"), '')
322
+ end
323
+ end
324
+ end
273
325
 
274
- context "by default" do
275
- it "is the parent dir of the config file" do
276
- Chef::Config.config_dir.should == "/etc/chef"
277
- end
278
- end
279
-
280
- context "when chef is running in local mode" do
281
- before do
282
- Chef::Config.local_mode = true
283
- Chef::Config.user_home = "/home/charlie"
284
326
  end
285
327
 
286
- it "is in the user's home dir" do
287
- Chef::Config.config_dir.should == "/home/charlie/.chef/"
328
+ if is_windows
329
+ describe "finding the windows embedded dir" do
330
+ let(:default_config_location) { "c:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.0/lib/chef/config.rb" }
331
+ let(:alternate_install_location) { "c:/my/alternate/install/place/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.0/lib/chef/config.rb" }
332
+ let(:non_omnibus_location) { "c:/my/dev/stuff/lib/ruby/gems/1.9.1/gems/chef-11.6.0/lib/chef/config.rb" }
333
+
334
+ let(:default_ca_file) { "c:/opscode/chef/embedded/ssl/certs/cacert.pem" }
335
+
336
+ it "finds the embedded dir in the default location" do
337
+ Chef::Config.stub(:_this_file).and_return(default_config_location)
338
+ Chef::Config.embedded_dir.should == "c:/opscode/chef/embedded"
339
+ end
340
+
341
+ it "finds the embedded dir in a custom install location" do
342
+ Chef::Config.stub(:_this_file).and_return(alternate_install_location)
343
+ Chef::Config.embedded_dir.should == "c:/my/alternate/install/place/chef/embedded"
344
+ end
345
+
346
+ it "doesn't error when not in an omnibus install" do
347
+ Chef::Config.stub(:_this_file).and_return(non_omnibus_location)
348
+ Chef::Config.embedded_dir.should be_nil
349
+ end
350
+
351
+ it "sets the ssl_ca_cert path if the cert file is available" do
352
+ Chef::Config.stub(:_this_file).and_return(default_config_location)
353
+ File.stub(:exist?).with(default_ca_file).and_return(true)
354
+ Chef::Config.ssl_ca_file.should == default_ca_file
355
+ end
356
+ end
288
357
  end
289
358
  end
290
359
 
291
- context "when explicitly set" do
292
- before do
293
- Chef::Config.config_dir = "/other/config/dir/"
360
+ describe "Chef::Config[:user_home]" do
361
+ it "should set when HOME is provided" do
362
+ expected = to_platform("/home/kitten")
363
+ Chef::Config.stub(:env).and_return({ 'HOME' => expected })
364
+ Chef::Config[:user_home].should == expected
294
365
  end
295
366
 
296
- it "uses the explicit value" do
297
- Chef::Config.config_dir.should == "/other/config/dir/"
367
+ it "should be set when only USERPROFILE is provided" do
368
+ expected = to_platform("/users/kitten")
369
+ Chef::Config.stub(:env).and_return({ 'USERPROFILE' => expected })
370
+ Chef::Config[:user_home].should == expected
298
371
  end
299
- end
300
372
 
301
- end
302
-
303
- describe "finding the windows embedded dir" do
304
- let(:default_config_location) { "c:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.0/lib/chef/config.rb" }
305
- let(:alternate_install_location) { "c:/my/alternate/install/place/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.0/lib/chef/config.rb" }
306
- let(:non_omnibus_location) { "c:/my/dev/stuff/lib/ruby/gems/1.9.1/gems/chef-11.6.0/lib/chef/config.rb" }
307
-
308
- let(:default_ca_file) { "c:/opscode/chef/embedded/ssl/certs/cacert.pem" }
309
-
310
- it "finds the embedded dir in the default location" do
311
- Chef::Config.stub(:_this_file).and_return(default_config_location)
312
- Chef::Config.embedded_dir.should == "c:/opscode/chef/embedded"
313
- end
314
-
315
- it "finds the embedded dir in a custom install location" do
316
- Chef::Config.stub(:_this_file).and_return(alternate_install_location)
317
- Chef::Config.embedded_dir.should == "c:/my/alternate/install/place/chef/embedded"
318
- end
319
-
320
- it "doesn't error when not in an omnibus install" do
321
- Chef::Config.stub(:_this_file).and_return(non_omnibus_location)
322
- Chef::Config.embedded_dir.should be_nil
323
- end
324
-
325
- it "sets the ssl_ca_cert path if the cert file is available" do
326
- Chef::Config.stub(:_this_file).and_return(default_config_location)
327
- Chef::Config.stub(:on_windows?).and_return(true)
328
- File.stub(:exist?).with(default_ca_file).and_return(true)
329
- Chef::Config.ssl_ca_file.should == default_ca_file
373
+ it "falls back to the current working directory when HOME and USERPROFILE is not set" do
374
+ Chef::Config.stub(:env).and_return({})
375
+ Chef::Config[:user_home].should == Dir.pwd
376
+ end
330
377
  end
331
- end
332
- end
333
-
334
- describe "Chef::Config[:user_home]" do
335
- it "should set when HOME is provided" do
336
- Chef::Config.stub(:env).and_return({ 'HOME' => "/home/kitten" })
337
- Chef::Config[:user_home].should == "/home/kitten"
338
- end
339
378
 
340
- it "should be set when only USERPROFILE is provided" do
341
- Chef::Config.stub(:env).and_return({ 'USERPROFILE' => "/users/kitten" })
342
- Chef::Config[:user_home].should == "/users/kitten"
343
- end
344
-
345
- it "falls back to the current working directory when HOME and USERPROFILE is not set" do
346
- Chef::Config.stub(:env).and_return({})
347
- Chef::Config[:user_home].should == Dir.pwd
348
- end
349
- end
350
-
351
- describe "Chef::Config[:encrypted_data_bag_secret]" do
352
- db_secret_default_path =
353
- Chef::Config.platform_specific_path("/etc/chef/encrypted_data_bag_secret")
379
+ describe "Chef::Config[:encrypted_data_bag_secret]" do
380
+ let(:db_secret_default_path){ to_platform("/etc/chef/encrypted_data_bag_secret") }
354
381
 
355
- let(:db_secret_default_path){ db_secret_default_path }
382
+ before do
383
+ File.stub(:exist?).with(db_secret_default_path).and_return(secret_exists)
384
+ end
356
385
 
357
- before do
358
- File.stub(:exist?).with(db_secret_default_path).and_return(secret_exists)
359
- end
386
+ context "/etc/chef/encrypted_data_bag_secret exists" do
387
+ let(:secret_exists) { true }
388
+ it "sets the value to /etc/chef/encrypted_data_bag_secret" do
389
+ Chef::Config[:encrypted_data_bag_secret].should eq db_secret_default_path
390
+ end
391
+ end
360
392
 
361
- context "#{db_secret_default_path} exists" do
362
- let(:secret_exists) { true }
363
- it "sets the value to #{db_secret_default_path}" do
364
- Chef::Config[:encrypted_data_bag_secret].should eq db_secret_default_path
393
+ context "/etc/chef/encrypted_data_bag_secret does not exist" do
394
+ let(:secret_exists) { false }
395
+ it "sets the value to nil" do
396
+ Chef::Config[:encrypted_data_bag_secret].should be_nil
397
+ end
398
+ end
365
399
  end
366
- end
367
400
 
368
- context "#{db_secret_default_path} does not exist" do
369
- let(:secret_exists) { false }
370
- it "sets the value to nil" do
371
- Chef::Config[:encrypted_data_bag_secret].should be_nil
401
+ describe "Chef::Config[:event_handlers]" do
402
+ it "sets a event_handlers to an empty array by default" do
403
+ Chef::Config[:event_handlers].should eq([])
404
+ end
405
+ it "should be able to add custom handlers" do
406
+ o = Object.new
407
+ Chef::Config[:event_handlers] << o
408
+ Chef::Config[:event_handlers].should be_include(o)
409
+ end
372
410
  end
373
- end
374
- end
375
411
 
376
- describe "Chef::Config[:event_handlers]" do
377
- it "sets a event_handlers to an empty array by default" do
378
- Chef::Config[:event_handlers].should eq([])
379
- end
380
- it "should be able to add custom handlers" do
381
- o = Object.new
382
- Chef::Config[:event_handlers] << o
383
- Chef::Config[:event_handlers].should be_include(o)
384
- end
385
- end
386
-
387
- describe "Chef::Config[:user_valid_regex]" do
388
- context "on a platform that is not Windows" do
389
- it "allows one letter usernames" do
390
- any_match = Chef::Config[:user_valid_regex].any? { |regex| regex.match('a') }
391
- expect(any_match).to be_true
412
+ describe "Chef::Config[:user_valid_regex]" do
413
+ context "on a platform that is not Windows" do
414
+ it "allows one letter usernames" do
415
+ any_match = Chef::Config[:user_valid_regex].any? { |regex| regex.match('a') }
416
+ expect(any_match).to be_true
417
+ end
418
+ end
392
419
  end
393
420
  end
394
421
  end