chef 11.8.4.ohai7.0 → 11.10.0.alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. checksums.yaml +7 -0
  2. data/distro/common/html/chef-client.8.html +3 -3
  3. data/distro/common/html/chef-expander.8.html +3 -3
  4. data/distro/common/html/chef-expanderctl.8.html +3 -3
  5. data/distro/common/html/chef-server-webui.8.html +3 -3
  6. data/distro/common/html/chef-server.8.html +3 -3
  7. data/distro/common/html/chef-shell.1.html +3 -3
  8. data/distro/common/html/chef-solo.8.html +3 -3
  9. data/distro/common/html/chef-solr.8.html +4 -4
  10. data/distro/common/html/knife-bootstrap.1.html +3 -3
  11. data/distro/common/html/knife-client.1.html +3 -3
  12. data/distro/common/html/knife-configure.1.html +3 -3
  13. data/distro/common/html/knife-cookbook-site.1.html +3 -3
  14. data/distro/common/html/knife-cookbook.1.html +3 -3
  15. data/distro/common/html/knife-data-bag.1.html +3 -3
  16. data/distro/common/html/knife-environment.1.html +3 -3
  17. data/distro/common/html/knife-exec.1.html +3 -3
  18. data/distro/common/html/knife-index.1.html +3 -3
  19. data/distro/common/html/knife-node.1.html +3 -3
  20. data/distro/common/html/knife-role.1.html +3 -3
  21. data/distro/common/html/knife-search.1.html +3 -3
  22. data/distro/common/html/knife-ssh.1.html +3 -3
  23. data/distro/common/html/knife-status.1.html +3 -3
  24. data/distro/common/html/knife-tag.1.html +3 -3
  25. data/distro/common/html/knife.1.html +3 -3
  26. data/distro/common/man/man8/chef-client.8 +3 -3
  27. data/distro/common/man/man8/chef-solo.8 +5 -2
  28. data/lib/chef.rb +2 -0
  29. data/lib/chef/application.rb +7 -2
  30. data/lib/chef/application/apply.rb +6 -0
  31. data/lib/chef/application/client.rb +3 -1
  32. data/lib/chef/application/knife.rb +2 -0
  33. data/lib/chef/application/solo.rb +1 -1
  34. data/lib/chef/client.rb +14 -11
  35. data/lib/chef/config.rb +4 -1
  36. data/lib/chef/cookbook_uploader.rb +14 -7
  37. data/lib/chef/encrypted_data_bag_item.rb +6 -303
  38. data/lib/chef/encrypted_data_bag_item/decryption_failure.rb +22 -0
  39. data/lib/chef/encrypted_data_bag_item/decryptor.rb +201 -0
  40. data/lib/chef/encrypted_data_bag_item/encryptor.rb +142 -0
  41. data/lib/chef/encrypted_data_bag_item/unacceptable_encrypted_data_bag_item_format.rb +22 -0
  42. data/lib/chef/encrypted_data_bag_item/unsupported_cipher.rb +22 -0
  43. data/lib/chef/encrypted_data_bag_item/unsupported_encrypted_data_bag_item_format.rb +22 -0
  44. data/lib/chef/exceptions.rb +1 -0
  45. data/lib/chef/formatters/doc.rb +19 -3
  46. data/lib/chef/http/basic_client.rb +1 -1
  47. data/lib/chef/http/http_request.rb +7 -0
  48. data/lib/chef/knife.rb +8 -1
  49. data/lib/chef/knife/bootstrap.rb +1 -1
  50. data/lib/chef/knife/cookbook_site_share.rb +2 -2
  51. data/lib/chef/knife/cookbook_upload.rb +7 -1
  52. data/lib/chef/knife/core/subcommand_loader.rb +2 -2
  53. data/lib/chef/knife/data_bag_create.rb +7 -0
  54. data/lib/chef/knife/environment_compare.rb +127 -0
  55. data/lib/chef/mixin/command.rb +11 -12
  56. data/lib/chef/mixin/deep_merge.rb +4 -4
  57. data/lib/chef/monkey_patches/net_http.rb +34 -0
  58. data/lib/chef/monkey_patches/uri.rb +70 -0
  59. data/lib/chef/platform/provider_mapping.rb +1 -0
  60. data/lib/chef/provider/cookbook_file.rb +8 -0
  61. data/lib/chef/provider/cron.rb +1 -1
  62. data/lib/chef/provider/directory.rb +7 -0
  63. data/lib/chef/provider/file.rb +17 -4
  64. data/lib/chef/provider/git.rb +23 -5
  65. data/lib/chef/provider/group.rb +30 -11
  66. data/lib/chef/provider/group/dscl.rb +26 -4
  67. data/lib/chef/provider/group/gpasswd.rb +14 -19
  68. data/lib/chef/provider/group/groupadd.rb +41 -1
  69. data/lib/chef/provider/group/groupmod.rb +46 -36
  70. data/lib/chef/provider/group/pw.rb +59 -16
  71. data/lib/chef/provider/group/suse.rb +16 -13
  72. data/lib/chef/provider/group/usermod.rb +38 -15
  73. data/lib/chef/provider/group/windows.rb +13 -6
  74. data/lib/chef/provider/ohai.rb +5 -6
  75. data/lib/chef/provider/remote_file.rb +8 -0
  76. data/lib/chef/provider/template.rb +8 -0
  77. data/lib/chef/provider/user.rb +5 -1
  78. data/lib/chef/provider/user/useradd.rb +7 -0
  79. data/lib/chef/provider/whyrun_safe_ruby_block.rb +30 -0
  80. data/lib/chef/providers.rb +1 -0
  81. data/lib/chef/resource/deploy.rb +18 -0
  82. data/lib/chef/resource/group.rb +11 -0
  83. data/lib/chef/resource/scm.rb +18 -0
  84. data/lib/chef/resource/whyrun_safe_ruby_block.rb +31 -0
  85. data/lib/chef/resources.rb +1 -0
  86. data/lib/chef/run_context.rb +11 -0
  87. data/lib/chef/shell/ext.rb +1 -1
  88. data/lib/chef/util/windows/net_group.rb +5 -1
  89. data/lib/chef/version.rb +1 -1
  90. data/spec/functional/resource/base.rb +3 -1
  91. data/spec/functional/resource/deploy_revision_spec.rb +1 -1
  92. data/spec/functional/resource/git_spec.rb +1 -1
  93. data/spec/functional/resource/group_spec.rb +257 -118
  94. data/spec/integration/client/client_spec.rb +82 -8
  95. data/spec/integration/client/ipv6_spec.rb +133 -0
  96. data/spec/integration/knife/cookbook_api_ipv6_spec.rb +111 -0
  97. data/spec/scripts/ssl-serve.rb +52 -0
  98. data/spec/spec_helper.rb +7 -6
  99. data/spec/support/platform_helpers.rb +21 -0
  100. data/spec/support/shared/functional/windows_script.rb +2 -1
  101. data/spec/support/shared/unit/provider/file.rb +181 -43
  102. data/spec/support/shared/unit/provider/useradd_based_user_provider.rb +18 -0
  103. data/spec/unit/application/client_spec.rb +1 -0
  104. data/spec/unit/client_spec.rb +14 -1
  105. data/spec/unit/config_spec.rb +20 -0
  106. data/spec/unit/encrypted_data_bag_item_spec.rb +32 -18
  107. data/spec/unit/knife/cookbook_upload_spec.rb +14 -0
  108. data/spec/unit/knife/core/subcommand_loader_spec.rb +2 -2
  109. data/spec/unit/knife/data_bag_create_spec.rb +7 -0
  110. data/spec/unit/knife/environment_compare_spec.rb +112 -0
  111. data/spec/unit/knife_spec.rb +6 -1
  112. data/spec/unit/monkey_patches/uri_spec.rb +34 -0
  113. data/spec/unit/provider/cookbook_file_spec.rb +2 -1
  114. data/spec/unit/provider/cron_spec.rb +6 -0
  115. data/spec/unit/provider/file_spec.rb +3 -1
  116. data/spec/unit/provider/git_spec.rb +28 -4
  117. data/spec/unit/provider/group/dscl_spec.rb +1 -0
  118. data/spec/unit/provider/group/gpasswd_spec.rb +16 -9
  119. data/spec/unit/provider/group/groupadd_spec.rb +3 -4
  120. data/spec/unit/provider/group/groupmod_spec.rb +0 -1
  121. data/spec/unit/provider/group/pw_spec.rb +11 -14
  122. data/spec/unit/provider/group/usermod_spec.rb +19 -4
  123. data/spec/unit/provider/group/windows_spec.rb +0 -8
  124. data/spec/unit/provider/group_spec.rb +26 -4
  125. data/spec/unit/provider/ohai_spec.rb +1 -0
  126. data/spec/unit/provider/remote_file_spec.rb +4 -3
  127. data/spec/unit/provider/template_spec.rb +5 -3
  128. data/spec/unit/provider/user_spec.rb +6 -0
  129. data/spec/unit/provider/whyrun_safe_ruby_block_spec.rb +47 -0
  130. data/spec/unit/resource/scm_spec.rb +10 -0
  131. data/spec/unit/rest/auth_credentials_spec.rb +4 -1
  132. data/spec/unit/rest_spec.rb +12 -3
  133. metadata +69 -97
  134. data/spec/functional/resource/ohai_spec.rb +0 -65
@@ -360,4 +360,24 @@ describe Chef::Config do
360
360
  expect{Chef::Config.log_location = missing_path}.to raise_error Chef::Exceptions::ConfigurationError
361
361
  end
362
362
  end
363
+
364
+ describe "Chef::Config[:event_handlers]" do
365
+ it "sets a event_handlers to an empty array by default" do
366
+ Chef::Config[:event_handlers].should eq([])
367
+ end
368
+ it "should be able to add custom handlers" do
369
+ o = Object.new
370
+ Chef::Config[:event_handlers] << o
371
+ Chef::Config[:event_handlers].should be_include(o)
372
+ end
373
+ end
374
+
375
+ describe "Chef::Config[:user_valid_regex]" do
376
+ context "on a platform that is not Windows" do
377
+ it "allows one letter usernames" do
378
+ any_match = Chef::Config[:user_valid_regex].any? { |regex| regex.match('a') }
379
+ expect(any_match).to be_true
380
+ end
381
+ end
382
+ end
363
383
  end
@@ -283,35 +283,49 @@ describe Chef::EncryptedDataBagItem do
283
283
  end
284
284
 
285
285
  describe ".load_secret" do
286
- subject(:loaded_secret) { Chef::EncryptedDataBagItem.load_secret(path) }
287
- let(:path) { "/var/mysecret" }
288
286
  let(:secret) { "opensesame" }
289
- let(:stubbed_path) { path }
290
- before do
291
- ::File.stub(:exist?).with(stubbed_path).and_return(true)
292
- IO.stub(:read).with(stubbed_path).and_return(secret)
293
- Kernel.stub(:open).with(path).and_return(StringIO.new(secret))
287
+
288
+ context "when /var/mysecret exists" do
289
+ before do
290
+ ::File.stub(:exist?).with("/var/mysecret").and_return(true)
291
+ IO.stub(:read).with("/var/mysecret").and_return(secret)
292
+ end
293
+
294
+ it "load_secret('/var/mysecret') reads the secret" do
295
+ Chef::EncryptedDataBagItem.load_secret("/var/mysecret").should eq secret
296
+ end
294
297
  end
295
298
 
296
- it "reads from a specified path" do
297
- loaded_secret.should eq secret
299
+ context "when /etc/chef/encrypted_data_bag_secret exists" do
300
+ before do
301
+ path = Chef::Config.platform_specific_path("/etc/chef/encrypted_data_bag_secret")
302
+ ::File.stub(:exist?).with(path).and_return(true)
303
+ IO.stub(:read).with(path).and_return(secret)
304
+ end
305
+
306
+ it "load_secret(nil) reads the secret" do
307
+ Chef::EncryptedDataBagItem.load_secret(nil).should eq secret
308
+ end
298
309
  end
299
310
 
300
- context "path argument is nil" do
301
- let(:path) { nil }
302
- let(:stubbed_path) { "/etc/chef/encrypted_data_bag_secret" }
311
+ context "when /etc/chef/encrypted_data_bag_secret does not exist" do
312
+ before do
313
+ path = Chef::Config.platform_specific_path("/etc/chef/encrypted_data_bag_secret")
314
+ ::File.stub(:exist?).with(path).and_return(false)
315
+ end
303
316
 
304
- it "reads from Chef::Config[:encrypted_data_bag_secret]" do
305
- Chef::Config[:encrypted_data_bag_secret] = stubbed_path
306
- loaded_secret.should eq secret
317
+ it "load_secret(nil) emits a reasonable error message" do
318
+ lambda { Chef::EncryptedDataBagItem.load_secret(nil) }.should raise_error(ArgumentError, "No secret specified to load_secret and no secret found at #{Chef::Config.platform_specific_path('/etc/chef/encrypted_data_bag_secret')}")
307
319
  end
308
320
  end
309
321
 
310
322
  context "path argument is a URL" do
311
- let(:path) { "http://www.opscode.com/" }
323
+ before do
324
+ Kernel.stub(:open).with("http://www.opscode.com/").and_return(StringIO.new(secret))
325
+ end
312
326
 
313
- it "reads the URL" do
314
- loaded_secret.should eq secret
327
+ it "reads from the URL" do
328
+ Chef::EncryptedDataBagItem.load_secret("http://www.opscode.com/").should eq secret
315
329
  end
316
330
  end
317
331
  end
@@ -40,6 +40,20 @@ describe Chef::Knife::CookbookUpload do
40
40
  @knife.ui.stub!(:stderr).and_return(@output)
41
41
  end
42
42
 
43
+ describe 'with --concurrency' do
44
+ it 'should upload cookbooks with predefined concurrency' do
45
+ @cookbook_uploader = stub(:upload_cookbooks => nil)
46
+ Chef::CookbookVersion.stub(:list_all_versions).and_return({})
47
+ @knife.config[:concurrency] = 3
48
+ @test_cookbook = Chef::CookbookVersion.new('test_cookbook')
49
+ @cookbook_loader.stub!(:each).and_yield("test_cookbook", @test_cookbook)
50
+ @cookbook_loader.stub!(:cookbook_names).and_return(["test_cookbook"])
51
+ Chef::CookbookUploader.should_receive(:new).with( kind_of(Array), kind_of(Array),
52
+ {:force=>nil, :concurrency => 3}).and_return(double("Chef::CookbookUploader", :upload_cookbooks=> true))
53
+ @knife.run
54
+ end
55
+ end
56
+
43
57
  describe 'run' do
44
58
  before(:each) do
45
59
  @cookbook_uploader = stub(:upload_cookbooks => nil)
@@ -45,10 +45,10 @@ describe Chef::Knife::SubcommandLoader do
45
45
  ]
46
46
  $LOAD_PATH.should_receive(:map).and_return([])
47
47
  if Gem::Specification.respond_to? :latest_specs
48
- Gem::Specification.should_receive(:latest_specs).and_return(gems)
48
+ Gem::Specification.should_receive(:latest_specs).with(true).and_return(gems)
49
49
  gems[0].should_receive(:matches_for_glob).with(/chef\/knife\/\*\.rb{(.*),\.rb,(.*)}/).and_return(gem_files)
50
50
  else
51
- Gem.source_index.should_receive(:latest_specs).and_return(gems)
51
+ Gem.source_index.should_receive(:latest_specs).with(true).and_return(gems)
52
52
  gems[0].should_receive(:require_paths).twice.and_return(['lib'])
53
53
  gems[0].should_receive(:full_gem_path).and_return('/usr/lib/ruby/gems/knife-ec2-0.5.12')
54
54
  Dir.should_receive(:[]).with('/usr/lib/ruby/gems/knife-ec2-0.5.12/lib/chef/knife/*.rb').and_return(gem_files)
@@ -53,6 +53,13 @@ describe Chef::Knife::DataBagCreate do
53
53
  @knife.run
54
54
  end
55
55
 
56
+ it "tries to create a data bag with an invalid name when given one argument" do
57
+ @knife.name_args = ['invalid&char']
58
+ @knife.should_receive(:exit).with(1)
59
+
60
+ @knife.run
61
+ end
62
+
56
63
  it "creates a data bag item when given two arguments" do
57
64
  @knife.name_args = ['sudoing_admins', 'ME']
58
65
  user_supplied_hash = {"login_name" => "alphaomega", "id" => "ME"}
@@ -0,0 +1,112 @@
1
+ #
2
+ # Author:: Sander Botman (<sbotman@schubergphilis.com>)
3
+ # Copyright:: Copyright (c) 2013 Sander Botman.
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
+
21
+ describe Chef::Knife::EnvironmentCompare do
22
+ before(:each) do
23
+ @knife = Chef::Knife::EnvironmentCompare.new
24
+
25
+ @environments = {
26
+ "cita" => "http://localhost:4000/environments/cita",
27
+ "citm" => "http://localhost:4000/environments/citm"
28
+ }
29
+
30
+ @knife.stub(:environment_list).and_return(@environments)
31
+
32
+ @constraints = {
33
+ "cita" => { "foo" => "= 1.0.1", "bar" => "= 0.0.4" },
34
+ "citm" => { "foo" => "= 1.0.1", "bar" => "= 0.0.2" }
35
+ }
36
+
37
+ @knife.stub(:constraint_list).and_return(@constraints)
38
+
39
+ @cookbooks = { "foo"=>"= 1.0.1", "bar"=>"= 0.0.1" }
40
+
41
+ @knife.stub(:cookbook_list).and_return(@cookbooks)
42
+
43
+ @rest_double = double('rest')
44
+ @knife.stub(:rest).and_return(@rest_double)
45
+ @cookbook_names = ['apache2', 'mysql', 'foo', 'bar', 'dummy', 'chef_handler']
46
+ @base_url = 'https://server.example.com/cookbooks'
47
+ @cookbook_data = {}
48
+ @cookbook_names.each do |item|
49
+ @cookbook_data[item] = {'url' => "#{@base_url}/#{item}",
50
+ 'versions' => [{'version' => '1.0.1',
51
+ 'url' => "#{@base_url}/#{item}/1.0.1"}]}
52
+ end
53
+
54
+ @rest_double.stub(:get_rest).with("/cookbooks?num_versions=1").and_return(@cookbook_data)
55
+
56
+ @stdout = StringIO.new
57
+ @knife.ui.stub(:stdout).and_return(@stdout)
58
+ end
59
+
60
+ describe 'run' do
61
+ it 'should display only cookbooks with version constraints' do
62
+ @knife.config[:format] = 'summary'
63
+ @knife.run
64
+ @environments.each do |item, url|
65
+ @stdout.string.should match /#{item}/ and @stdout.string.lines.count.should be 4
66
+ end
67
+ end
68
+
69
+ it 'should display 4 number of lines' do
70
+ @knife.config[:format] = 'summary'
71
+ @knife.run
72
+ @stdout.string.lines.count.should be 4
73
+ end
74
+ end
75
+
76
+ describe 'with -m or --mismatch' do
77
+ it 'should display only cookbooks that have mismatching version constraints' do
78
+ @knife.config[:format] = 'summary'
79
+ @knife.config[:mismatch] = true
80
+ @knife.run
81
+ @constraints.each do |item, ver|
82
+ @stdout.string.should match /#{ver[1]}/
83
+ end
84
+ end
85
+
86
+ it 'should display 3 number of lines' do
87
+ @knife.config[:format] = 'summary'
88
+ @knife.config[:mismatch] = true
89
+ @knife.run
90
+ @stdout.string.lines.count.should be 3
91
+ end
92
+ end
93
+
94
+ describe 'with -a or --all' do
95
+ it 'should display all cookbooks' do
96
+ @knife.config[:format] = 'summary'
97
+ @knife.config[:all] = true
98
+ @knife.run
99
+ @constraints.each do |item, ver|
100
+ @stdout.string.should match /#{ver[1]}/
101
+ end
102
+ end
103
+
104
+ it 'should display 8 number of lines' do
105
+ @knife.config[:format] = 'summary'
106
+ @knife.config[:all] = true
107
+ @knife.run
108
+ @stdout.string.lines.count.should be 8
109
+ end
110
+ end
111
+
112
+ end
@@ -46,7 +46,12 @@ describe Chef::Knife do
46
46
  Chef::Knife.reset_config_path!
47
47
  # pwd according to your shell is /home/someuser/prod/chef-repo, but
48
48
  # chef-repo is a symlink to /home/someuser/codes/chef-repo
49
- ENV.stub!(:[]).with("PWD").and_return("/home/someuser/prod/chef-repo")
49
+ if Chef::Platform.windows?
50
+ ENV.should_receive(:[]).with("CD").and_return("/home/someuser/prod/chef-repo")
51
+ else
52
+ ENV.should_receive(:[]).with("PWD").and_return("/home/someuser/prod/chef-repo")
53
+ end
54
+
50
55
  Dir.stub!(:pwd).and_return("/home/someuser/codes/chef-repo")
51
56
  end
52
57
 
@@ -0,0 +1,34 @@
1
+ #--
2
+ # Author:: Daniel DeLeo (<dan@opscode.com>)
3
+ # Copyright:: Copyright (c) 2013 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
+ describe URI do
21
+
22
+ describe "when a URI contains an IPv6 literal" do
23
+
24
+ let(:ipv6_uri) do
25
+ URI.parse("https://[2a00:1450:4009:809::1008]:8443")
26
+ end
27
+
28
+ it "returns the hostname without brackets" do
29
+ ipv6_uri.hostname.should == "2a00:1450:4009:809::1008"
30
+ end
31
+
32
+ end
33
+
34
+ end
@@ -37,7 +37,7 @@ describe Chef::Provider::CookbookFile do
37
37
 
38
38
  let(:provider) do
39
39
  provider = described_class.new(resource, run_context)
40
- provider.stub!(:content).and_return(content)
40
+ provider.stub(:content).and_return(content)
41
41
  provider
42
42
  end
43
43
 
@@ -54,4 +54,5 @@ describe Chef::Provider::CookbookFile do
54
54
 
55
55
  it_behaves_like Chef::Provider::File
56
56
 
57
+ it_behaves_like "a file provider with source field"
57
58
  end
@@ -291,6 +291,12 @@ CRONTAB
291
291
  @provider.cron_different?.should eql(true)
292
292
  end
293
293
 
294
+ it "should return true if mailto doesn't match" do
295
+ @current_resource.mailto "foo@bar.com"
296
+ @new_resource.mailto(nil)
297
+ @provider.cron_different?.should eql(true)
298
+ end
299
+
294
300
  it "should return false if the objects are identical" do
295
301
  @provider.cron_different?.should == false
296
302
  end
@@ -46,10 +46,12 @@ describe Chef::Provider::File do
46
46
 
47
47
  let(:provider) do
48
48
  provider = described_class.new(resource, run_context)
49
- provider.stub!(:content).and_return(content)
49
+ provider.stub(:content).and_return(content)
50
50
  provider
51
51
  end
52
52
 
53
53
  it_behaves_like Chef::Provider::File
54
+
55
+ it_behaves_like "a file provider with content field"
54
56
  end
55
57
 
@@ -172,13 +172,14 @@ SHAS
172
172
  let(:default_options) do
173
173
  {
174
174
  :user => deploy_user,
175
- :environment => { "GIT_SSH" => wrapper },
175
+ :environment => { "GIT_SSH" => wrapper, "HOME" => "/home/deployNinja" },
176
176
  :log_tag => "git[web2.0 app]"
177
177
  }
178
178
  end
179
179
  before do
180
180
  @resource.user deploy_user
181
181
  @resource.ssh_wrapper wrapper
182
+ Etc.stub!(:getpwnam).and_return(double("Struct::Passwd", :name => @resource.user, :dir => "/home/deployNinja"))
182
183
  end
183
184
  context "without a timeout set" do
184
185
  it "clones a repo with default git options" do
@@ -198,11 +199,13 @@ SHAS
198
199
 
199
200
  it "runs a clone command with escaped destination" do
200
201
  @resource.user "deployNinja"
202
+ Etc.stub!(:getpwnam).and_return(double("Struct::Passwd", :name => @resource.user, :dir => "/home/deployNinja"))
201
203
  @resource.destination "/Application Support/with/space"
202
204
  @resource.ssh_wrapper "do_it_this_way.sh"
203
205
  expected_cmd = "git clone \"git://github.com/opscode/chef.git\" \"/Application Support/with/space\""
204
206
  @provider.should_receive(:shell_out!).with(expected_cmd, :user => "deployNinja",
205
- :environment =>{"GIT_SSH"=>"do_it_this_way.sh"},
207
+ :environment =>{"GIT_SSH"=>"do_it_this_way.sh",
208
+ "HOME" => "/home/deployNinja"},
206
209
  :log_tag => "git[web2.0 app]")
207
210
  @provider.clone
208
211
  end
@@ -252,11 +255,14 @@ SHAS
252
255
 
253
256
  it "runs a sync command with the user and group specified in the resource" do
254
257
  @resource.user("whois")
258
+ Etc.stub!(:getpwnam).and_return(double("Struct::Passwd", :name => @resource.user, :dir => "/home/whois"))
255
259
  @resource.group("thisis")
256
260
  @provider.should_receive(:setup_remote_tracking_branches).with(@resource.remote, @resource.repository)
257
261
  expected_cmd = "git fetch origin && git fetch origin --tags && git reset --hard d35af14d41ae22b19da05d7d03a0bafc321b244c"
258
262
  @provider.should_receive(:shell_out!).with(expected_cmd, :cwd => "/my/deploy/dir",
259
- :user => "whois", :group => "thisis", :log_tag => "git[web2.0 app]")
263
+ :user => "whois", :group => "thisis",
264
+ :log_tag => "git[web2.0 app]",
265
+ :environment=>{"HOME"=>"/home/whois"})
260
266
  @provider.fetch_updates
261
267
  end
262
268
 
@@ -296,6 +302,7 @@ SHAS
296
302
  it "runs the config with the user and group specified in the resource" do
297
303
  @resource.user("whois")
298
304
  @resource.group("thisis")
305
+ Etc.stub!(:getpwnam).and_return(double("Struct::Passwd", :name => @resource.user, :dir => "/home/whois"))
299
306
  command_response = double('shell_out')
300
307
  command_response.stub(:exitstatus) { 1 }
301
308
  expected_command = "git config --get remote.#{@resource.remote}.url"
@@ -304,13 +311,15 @@ SHAS
304
311
  :log_tag => "git[web2.0 app]",
305
312
  :user => "whois",
306
313
  :group => "thisis",
314
+ :environment=>{"HOME"=>"/home/whois"},
307
315
  :returns => [0,1,2]).and_return(command_response)
308
316
  add_remote_command = "git remote add #{@resource.remote} #{@resource.repository}"
309
317
  @provider.should_receive(:shell_out!).with(add_remote_command,
310
318
  :cwd => "/my/deploy/dir",
311
319
  :log_tag => "git[web2.0 app]",
312
320
  :user => "whois",
313
- :group => "thisis")
321
+ :group => "thisis",
322
+ :environment=>{"HOME"=>"/home/whois"})
314
323
  @provider.setup_remote_tracking_branches(@resource.remote, @resource.repository)
315
324
  end
316
325
 
@@ -402,6 +411,21 @@ SHAS
402
411
  # @resource.should be_updated
403
412
  end
404
413
 
414
+ it "does not call checkout if enable_checkout is false" do
415
+ # will be invoked in load_current_resource
416
+ ::File.stub!(:exist?).with("/my/deploy/dir/.git").and_return(false)
417
+
418
+ ::File.stub!(:exist?).with("/my/deploy/dir").and_return(true)
419
+ ::File.stub!(:directory?).with("/my/deploy").and_return(true)
420
+ ::Dir.stub!(:entries).with("/my/deploy/dir").and_return(['.','..'])
421
+
422
+ @resource.enable_checkout false
423
+ @provider.should_receive(:clone)
424
+ @provider.should_not_receive(:checkout)
425
+ @provider.should_receive(:enable_submodules)
426
+ @provider.run_action(:checkout)
427
+ end
428
+
405
429
  # REGRESSION TEST: on some OSes, the entries from an empty directory will be listed as
406
430
  # ['..', '.'] but this shouldn't change the behavior
407
431
  it "does a checkout by cloning the repo and then enabling submodules when the directory entries are listed as %w{.. .}" do
@@ -265,6 +265,7 @@ describe Chef::Provider::Group::Dscl do
265
265
  it "should manage the group_name if it changed and the new resources group_name is not null" do
266
266
  @current_resource.group_name("oldval")
267
267
  @new_resource.group_name("newname")
268
+ @provider.should_receive(:set_members).and_return(true)
268
269
  @provider.should_receive(:safe_dscl).with("create /Groups/newname")
269
270
  @provider.should_receive(:safe_dscl).with("create /Groups/newname Password '*'")
270
271
  @provider.manage_group