summaryrefslogtreecommitdiff
path: root/spec/unit/provider/git_spec.rb
diff options
context:
space:
mode:
authorPawel Kozlowski <pawel.kozlowski@u2i.com>2012-11-12 01:05:16 +0100
committerBryan McLellan <btm@opscode.com>2013-06-18 11:09:12 -0700
commita961f079d07542030140df355c167f3a506a764c (patch)
tree928c8e69882accafe8d56a47c859b6d86e4852a4 /spec/unit/provider/git_spec.rb
parent88db604600b118203f999c1218d7a6fccdc83eb6 (diff)
downloadchef-a961f079d07542030140df355c167f3a506a764c.tar.gz
[CHEF-955] Changed behavior of setup_remote_tracking_branches method
Refactored the method to use appropriate git command depending on the current status of git config.
Diffstat (limited to 'spec/unit/provider/git_spec.rb')
-rw-r--r--spec/unit/provider/git_spec.rb95
1 files changed, 86 insertions, 9 deletions
diff --git a/spec/unit/provider/git_spec.rb b/spec/unit/provider/git_spec.rb
index 886d43014b..5dbe40019f 100644
--- a/spec/unit/provider/git_spec.rb
+++ b/spec/unit/provider/git_spec.rb
@@ -258,11 +258,21 @@ SHAS
end
context "configuring remote tracking branches" do
- it "overwrites sets the remote url and fetch config variables" do
- @resource.remote "opscode"
- conf_tracking_branches = "git config remote.opscode.url git://github.com/opscode/chef.git && " +
- "git config remote.opscode.fetch +refs/heads/*:refs/remotes/opscode/*"
- @provider.should_receive(:shell_out!).with(conf_tracking_branches, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]", :log_level => :debug)
+
+ it "checks if a remote with this name already exists" do
+ command_response = double('shell_out')
+ command_response.stub(:exitstatus) { 1 }
+ expected_command = "git config --get remote.#{@resource.remote}.url"
+ @provider.should_receive(:shell_out!).with(expected_command,
+ :cwd => "/my/deploy/dir",
+ :log_tag => "git[web2.0 app]",
+ :log_level => :debug,
+ :returns => [0,1,2]).and_return(command_response)
+ add_remote_command = "git remote add #{@resource.remote} #{@resource.repository}"
+ @provider.should_receive(:shell_out!).with(add_remote_command,
+ :cwd => "/my/deploy/dir",
+ :log_tag => "git[web2.0 app]",
+ :log_level => :debug)
@provider.setup_remote_tracking_branches
@provider.converge
end
@@ -270,10 +280,77 @@ SHAS
it "runs the config with the user and group specified in the resource" do
@resource.user("whois")
@resource.group("thisis")
- conf_tracking_branches = "git config remote.origin.url git://github.com/opscode/chef.git && " +
- "git config remote.origin.fetch +refs/heads/*:refs/remotes/origin/*"
- @provider.should_receive(:shell_out!).with(conf_tracking_branches, :cwd => "/my/deploy/dir",
- :user => "whois", :group => "thisis", :log_tag => "git[web2.0 app]", :log_level => :debug)
+ command_response = double('shell_out')
+ command_response.stub(:exitstatus) { 1 }
+ expected_command = "git config --get remote.#{@resource.remote}.url"
+ @provider.should_receive(:shell_out!).with(expected_command,
+ :cwd => "/my/deploy/dir",
+ :log_tag => "git[web2.0 app]",
+ :log_level => :debug,
+ :user => "whois",
+ :group => "thisis",
+ :returns => [0,1,2]).and_return(command_response)
+ add_remote_command = "git remote add #{@resource.remote} #{@resource.repository}"
+ @provider.should_receive(:shell_out!).with(add_remote_command,
+ :cwd => "/my/deploy/dir",
+ :log_tag => "git[web2.0 app]",
+ :log_level => :debug,
+ :user => "whois",
+ :group => "thisis")
+ @provider.setup_remote_tracking_branches
+ @provider.converge
+ end
+
+ it "adds a new remote when one with this name hasn't been configured yet" do
+ command_response = double('shell_out')
+ command_response.stub(:exitstatus) { 1 }
+ check_remote_command = "git config --get remote.#{@resource.remote}.url"
+ @provider.should_receive(:shell_out!).with(check_remote_command,
+ :cwd => "/my/deploy/dir",
+ :log_tag => "git[web2.0 app]",
+ :log_level => :debug,
+ :returns => [0,1,2]).and_return(command_response)
+ expected_command = "git remote add #{@resource.remote} #{@resource.repository}"
+ @provider.should_receive(:shell_out!).with(expected_command,
+ :cwd => "/my/deploy/dir",
+ :log_tag => "git[web2.0 app]",
+ :log_level => :debug)
+ @provider.setup_remote_tracking_branches
+ @provider.converge
+ end
+
+ it "updates remote url when one with the same name exists" do
+ command_response = double('shell_out')
+ command_response.stub(:exitstatus) { 0 }
+ check_remote_command = "git config --get remote.#{@resource.remote}.url"
+ @provider.should_receive(:shell_out!).with(check_remote_command,
+ :cwd => "/my/deploy/dir",
+ :log_tag => "git[web2.0 app]",
+ :log_level => :debug,
+ :returns => [0,1,2]).and_return(command_response)
+ expected_command = "git remote set-url #{@resource.remote} #{@resource.repository}"
+ @provider.should_receive(:shell_out!).with(expected_command,
+ :cwd => "/my/deploy/dir",
+ :log_tag => "git[web2.0 app]",
+ :log_level => :debug)
+ @provider.setup_remote_tracking_branches
+ @provider.converge
+ end
+
+ it "resets remote url when it has multiple values" do
+ command_response = double('shell_out')
+ command_response.stub(:exitstatus) { 2 }
+ check_remote_command = "git config --get remote.#{@resource.remote}.url"
+ @provider.should_receive(:shell_out!).with(check_remote_command,
+ :cwd => "/my/deploy/dir",
+ :log_tag => "git[web2.0 app]",
+ :log_level => :debug,
+ :returns => [0,1,2]).and_return(command_response)
+ expected_command = "git config --replace-all remote.#{@resource.remote}.url #{@resource.repository}"
+ @provider.should_receive(:shell_out!).with(expected_command,
+ :cwd => "/my/deploy/dir",
+ :log_tag => "git[web2.0 app]",
+ :log_level => :debug)
@provider.setup_remote_tracking_branches
@provider.converge
end