diff options
author | Thom May <thom@may.lt> | 2016-05-03 18:10:00 +0100 |
---|---|---|
committer | Thom May <thom@may.lt> | 2016-05-03 18:10:00 +0100 |
commit | bf4e7bdeeee19f53b7b900936b4d7389d7480659 (patch) | |
tree | ef5006facd1257588ed67389136921d90b6cd7f3 /spec | |
parent | fa349bbdfde9278eb6ed0cf80605b40c09614201 (diff) | |
parent | 51cac6df6838ae4fe8d0981da2093e632d49d5f9 (diff) | |
download | chef-bf4e7bdeeee19f53b7b900936b4d7389d7480659.tar.gz |
Merge pull request #4873 from joshburt/jb_git_hwrp_shell_out_cleanup
Consolidate shell_out usage when calling git within it's HWRP.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/unit/provider/git_spec.rb | 59 |
1 files changed, 41 insertions, 18 deletions
diff --git a/spec/unit/provider/git_spec.rb b/spec/unit/provider/git_spec.rb index 97f04a5a77..36c33d313c 100644 --- a/spec/unit/provider/git_spec.rb +++ b/spec/unit/provider/git_spec.rb @@ -58,7 +58,7 @@ describe Chef::Provider::Git do it "determines the current revision when there is one" do expect(::File).to receive(:exist?).with("/my/deploy/dir/.git").and_return(true) @stdout = "9b4d8dc38dd471246e7cfb1c3c1ad14b0f2bee13\n" - expect(@provider).to receive(:shell_out!).with("git rev-parse HEAD", { :cwd => "/my/deploy/dir", :returns => [0, 128] }).and_return(double("ShellOut result", :stdout => @stdout)) + expect(@provider).to receive(:shell_out!).with("git rev-parse HEAD", { :cwd => "/my/deploy/dir", :returns => [0, 128], :log_tag => "git[web2.0 app]" }).and_return(double("ShellOut result", :stdout => @stdout)) expect(@provider.find_current_revision).to eql("9b4d8dc38dd471246e7cfb1c3c1ad14b0f2bee13") end @@ -66,7 +66,7 @@ describe Chef::Provider::Git do expect(::File).to receive(:exist?).with("/my/deploy/dir/.git").and_return(true) @stderr = "fatal: Not a git repository (or any of the parent directories): .git" @stdout = "" - expect(@provider).to receive(:shell_out!).with("git rev-parse HEAD", :cwd => "/my/deploy/dir", :returns => [0, 128]).and_return(double("ShellOut result", :stdout => "", :stderr => @stderr)) + expect(@provider).to receive(:shell_out!).with("git rev-parse HEAD", :cwd => "/my/deploy/dir", :returns => [0, 128], :log_tag => "git[web2.0 app]" ).and_return(double("ShellOut result", :stdout => "", :stderr => @stderr)) expect(@provider.find_current_revision).to be_nil end end @@ -218,7 +218,7 @@ SHAS context "with an ssh wrapper" do let(:deploy_user) { "deployNinja" } let(:wrapper) { "do_it_this_way.sh" } - let(:expected_cmd) { 'git clone "git://github.com/opscode/chef.git" "/my/deploy/dir"' } + let(:expected_cmd) { 'git clone "git://github.com/opscode/chef.git" "/my/deploy/dir"' } let(:default_options) do { :user => deploy_user, @@ -272,11 +272,11 @@ SHAS allow(Etc).to receive(:getpwnam).and_return(double("Struct::Passwd", :name => @resource.user, :dir => "/home/deployNinja")) @resource.destination "/Application Support/with/space" @resource.ssh_wrapper "do_it_this_way.sh" - expected_cmd = "git clone \"git://github.com/opscode/chef.git\" \"/Application Support/with/space\"" + expected_cmd = "git clone \"git://github.com/opscode/chef.git\" \"/Application Support/with/space\"" expect(@provider).to receive(:shell_out!).with(expected_cmd, :user => "deployNinja", - :environment => { "GIT_SSH" => "do_it_this_way.sh", - "HOME" => "/home/deployNinja" }, - :log_tag => "git[web2.0 app]") + :log_tag => "git[web2.0 app]", + :environment => { "HOME" => "/home/deployNinja", + "GIT_SSH" => "do_it_this_way.sh" }) @provider.clone end @@ -334,8 +334,12 @@ SHAS it "runs a sync command with default options" do expect(@provider).to receive(:setup_remote_tracking_branches).with(@resource.remote, @resource.repository) - expected_cmd = "git fetch origin && git fetch origin --tags && git reset --hard d35af14d41ae22b19da05d7d03a0bafc321b244c" - expect(@provider).to receive(:shell_out!).with(expected_cmd, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]") + expected_cmd1 = "git fetch origin" + expect(@provider).to receive(:shell_out!).with(expected_cmd1, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]") + expected_cmd2 = "git fetch origin --tags" + expect(@provider).to receive(:shell_out!).with(expected_cmd2, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]") + expected_cmd3 = "git reset --hard d35af14d41ae22b19da05d7d03a0bafc321b244c" + expect(@provider).to receive(:shell_out!).with(expected_cmd3, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]") @provider.fetch_updates end @@ -344,27 +348,46 @@ SHAS allow(Etc).to receive(:getpwnam).and_return(double("Struct::Passwd", :name => @resource.user, :dir => "/home/whois")) @resource.group("thisis") expect(@provider).to receive(:setup_remote_tracking_branches).with(@resource.remote, @resource.repository) - expected_cmd = "git fetch origin && git fetch origin --tags && git reset --hard d35af14d41ae22b19da05d7d03a0bafc321b244c" - expect(@provider).to receive(:shell_out!).with(expected_cmd, :cwd => "/my/deploy/dir", - :user => "whois", :group => "thisis", - :log_tag => "git[web2.0 app]", - :environment => { "HOME" => "/home/whois" }) + + expected_cmd1 = "git fetch origin" + expect(@provider).to receive(:shell_out!).with(expected_cmd1, :cwd => "/my/deploy/dir", + :user => "whois", :group => "thisis", + :log_tag => "git[web2.0 app]", + :environment => { "HOME" => "/home/whois" }) + expected_cmd2 = "git fetch origin --tags" + expect(@provider).to receive(:shell_out!).with(expected_cmd2, :cwd => "/my/deploy/dir", + :user => "whois", :group => "thisis", + :log_tag => "git[web2.0 app]", + :environment => { "HOME" => "/home/whois" }) + expected_cmd3 = "git reset --hard d35af14d41ae22b19da05d7d03a0bafc321b244c" + expect(@provider).to receive(:shell_out!).with(expected_cmd3, :cwd => "/my/deploy/dir", + :user => "whois", :group => "thisis", + :log_tag => "git[web2.0 app]", + :environment => { "HOME" => "/home/whois" }) @provider.fetch_updates end it "configures remote tracking branches when remote is ``origin''" do @resource.remote "origin" expect(@provider).to receive(:setup_remote_tracking_branches).with(@resource.remote, @resource.repository) - fetch_command = "git fetch origin && git fetch origin --tags && git reset --hard d35af14d41ae22b19da05d7d03a0bafc321b244c" - expect(@provider).to receive(:shell_out!).with(fetch_command, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]") + fetch_command1 = "git fetch origin" + expect(@provider).to receive(:shell_out!).with(fetch_command1, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]") + fetch_command2 = "git fetch origin --tags" + expect(@provider).to receive(:shell_out!).with(fetch_command2, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]") + fetch_command3 = "git reset --hard d35af14d41ae22b19da05d7d03a0bafc321b244c" + expect(@provider).to receive(:shell_out!).with(fetch_command3, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]") @provider.fetch_updates end it "configures remote tracking branches when remote is not ``origin''" do @resource.remote "opscode" expect(@provider).to receive(:setup_remote_tracking_branches).with(@resource.remote, @resource.repository) - fetch_command = "git fetch opscode && git fetch opscode --tags && git reset --hard d35af14d41ae22b19da05d7d03a0bafc321b244c" - expect(@provider).to receive(:shell_out!).with(fetch_command, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]") + fetch_command1 = "git fetch opscode" + expect(@provider).to receive(:shell_out!).with(fetch_command1, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]") + fetch_command2 = "git fetch opscode --tags" + expect(@provider).to receive(:shell_out!).with(fetch_command2, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]") + fetch_command3 = "git reset --hard d35af14d41ae22b19da05d7d03a0bafc321b244c" + expect(@provider).to receive(:shell_out!).with(fetch_command3, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]") @provider.fetch_updates end |