summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsawanoboly <sawanoboriyu@higanworks.com>2014-06-26 14:53:30 +0900
committerLamont Granquist <lamont@scriptkiddie.org>2014-08-21 11:44:46 -0700
commiteff4d2b6e712aa6cb76611d1ad8e317a1f962826 (patch)
tree24c45bfe3e533313a158425cb0d3b931f5f301e0
parentb49767dd1ed9c778f94bef597e52a61d48491b50 (diff)
downloadchef-eff4d2b6e712aa6cb76611d1ad8e317a1f962826.tar.gz
add_env_to_scm_resource
-rw-r--r--lib/chef/provider/git.rb1
-rw-r--r--lib/chef/resource/scm.rb10
-rw-r--r--spec/unit/provider/git_spec.rb45
3 files changed, 39 insertions, 17 deletions
diff --git a/lib/chef/provider/git.rb b/lib/chef/provider/git.rb
index 525249a726..744c8a236d 100644
--- a/lib/chef/provider/git.rb
+++ b/lib/chef/provider/git.rb
@@ -284,6 +284,7 @@ class Chef
run_opts[:log_tag] = @new_resource.to_s
run_opts[:timeout] = @new_resource.timeout if @new_resource.timeout
run_opts[:environment] = env unless env.empty?
+ run_opts[:environment] = env.merge(@new_resource.environment)
run_opts
end
diff --git a/lib/chef/resource/scm.rb b/lib/chef/resource/scm.rb
index 91782e4114..55a6d8a7be 100644
--- a/lib/chef/resource/scm.rb
+++ b/lib/chef/resource/scm.rb
@@ -40,6 +40,7 @@ class Chef
@allowed_actions.push(:checkout, :export, :sync, :diff, :log)
@action = [:sync]
@checkout_branch = "deploy"
+ @environment = {}
end
def destination(arg=nil)
@@ -172,6 +173,15 @@ class Chef
)
end
+ def environment(arg=nil)
+ set_or_return(
+ :environment,
+ arg,
+ :kind_of => [ Hash ]
+ )
+ end
+
+ alias :env :environment
end
end
end
diff --git a/spec/unit/provider/git_spec.rb b/spec/unit/provider/git_spec.rb
index ec1e0927b8..3828c75d78 100644
--- a/spec/unit/provider/git_spec.rb
+++ b/spec/unit/provider/git_spec.rb
@@ -93,7 +93,7 @@ describe Chef::Provider::Git do
@resource.revision "v1.0"
@stdout = ("d03c22a5e41f5ae3193460cca044ed1435029f53\trefs/heads/0.8-alpha\n" +
"503c22a5e41f5ae3193460cca044ed1435029f53\trefs/heads/v1.0\n")
- @provider.should_receive(:shell_out!).with(@git_ls_remote + "\"v1.0*\"", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout))
+ @provider.should_receive(:shell_out!).with(@git_ls_remote + "\"v1.0*\"", {:log_tag=>"git[web2.0 app]", :environment=>{}}).and_return(double("ShellOut result", :stdout => @stdout))
@provider.target_revision.should eql("503c22a5e41f5ae3193460cca044ed1435029f53")
end
@@ -102,7 +102,7 @@ describe Chef::Provider::Git do
@stdout = ("d03c22a5e41f5ae3193460cca044ed1435029f53\trefs/heads/0.8-alpha\n" +
"503c22a5e41f5ae3193460cca044ed1435029f53\trefs/heads/v1.0\n" +
"663c22a5e41f5ae3193460cca044ed1435029f53\trefs/heads/v1.0^{}\n")
- @provider.should_receive(:shell_out!).with(@git_ls_remote + "\"v1.0*\"", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout))
+ @provider.should_receive(:shell_out!).with(@git_ls_remote + "\"v1.0*\"", {:log_tag=>"git[web2.0 app]", :environment=>{}}).and_return(double("ShellOut result", :stdout => @stdout))
@provider.target_revision.should eql("663c22a5e41f5ae3193460cca044ed1435029f53")
end
@@ -131,7 +131,7 @@ describe Chef::Provider::Git do
it "does not raise an error when the revision is valid and assertions are run." do
@resource.revision "0.8-alpha"
@stdout = "503c22a5e41f5ae3193460cca044ed1435029f53\trefs/heads/0.8-alpha\n"
- @provider.should_receive(:shell_out!).with(@git_ls_remote + "\"0.8-alpha*\"", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout))
+ @provider.should_receive(:shell_out!).with(@git_ls_remote + "\"0.8-alpha*\"", {:log_tag=>"git[web2.0 app]", :environment=>{}}).and_return(double("ShellOut result", :stdout => @stdout))
@provider.action = :checkout
::File.stub(:directory?).with("/my/deploy").and_return(true)
@provider.define_resource_requirements
@@ -156,7 +156,7 @@ b7d19519a1c15f1c1a324e2683bd728b6198ce5a\trefs/tags/0.7.8^{}
ebc1b392fe7e8f0fbabc305c299b4d365d2b4d9b\trefs/tags/chef-server-package
SHAS
@resource.revision ''
- @provider.should_receive(:shell_out!).with(@git_ls_remote + "\"HEAD\"", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout))
+ @provider.should_receive(:shell_out!).with(@git_ls_remote + "\"HEAD\"", {:log_tag=>"git[web2.0 app]", :environment=>{}}).and_return(double("ShellOut result", :stdout => @stdout))
@provider.target_revision.should eql("28af684d8460ba4793eda3e7ac238c864a5d029a")
end
end
@@ -213,21 +213,22 @@ SHAS
it "compiles a clone command using --depth for shallow cloning" do
@resource.depth 5
expected_cmd = "git clone --depth 5 \"git://github.com/opscode/chef.git\" \"/my/deploy/dir\""
- @provider.should_receive(:shell_out!).with(expected_cmd, :log_tag => "git[web2.0 app]")
+ @provider.should_receive(:shell_out!).with(expected_cmd, :log_tag => "git[web2.0 app]", :environment=>{})
@provider.clone
end
it "compiles a clone command with a remote other than ``origin''" do
@resource.remote "opscode"
expected_cmd = "git clone -o opscode \"git://github.com/opscode/chef.git\" \"/my/deploy/dir\""
- @provider.should_receive(:shell_out!).with(expected_cmd, :log_tag => "git[web2.0 app]")
+ @provider.should_receive(:shell_out!).with(expected_cmd, :log_tag => "git[web2.0 app]", :environment=>{})
@provider.clone
end
it "runs a checkout command with default options and uses -B to reset branches if necessary" do
expected_cmd = 'git checkout -B deploy d35af14d41ae22b19da05d7d03a0bafc321b244c'
@provider.should_receive(:shell_out!).with(expected_cmd, :cwd => "/my/deploy/dir",
- :log_tag => "git[web2.0 app]")
+ :log_tag => "git[web2.0 app]",
+ :environment=>{})
@provider.checkout
end
@@ -235,9 +236,9 @@ SHAS
@resource.enable_submodules true
expected_cmd = "git submodule sync"
@provider.should_receive(:shell_out!).with(expected_cmd, :cwd => "/my/deploy/dir",
- :log_tag => "git[web2.0 app]")
+ :log_tag => "git[web2.0 app]", :environment=>{})
expected_cmd = "git submodule update --init --recursive"
- @provider.should_receive(:shell_out!).with(expected_cmd, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]")
+ @provider.should_receive(:shell_out!).with(expected_cmd, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]", :environment=>{})
@provider.enable_submodules
end
@@ -249,7 +250,7 @@ SHAS
it "runs a sync command with default options" do
@provider.should_receive(:setup_remote_tracking_branches).with(@resource.remote, @resource.repository)
expected_cmd = "git fetch origin && git fetch origin --tags && git reset --hard d35af14d41ae22b19da05d7d03a0bafc321b244c"
- @provider.should_receive(:shell_out!).with(expected_cmd, :cwd=> "/my/deploy/dir", :log_tag => "git[web2.0 app]")
+ @provider.should_receive(:shell_out!).with(expected_cmd, :cwd=> "/my/deploy/dir", :log_tag => "git[web2.0 app]", :environment=>{})
@provider.fetch_updates
end
@@ -270,7 +271,7 @@ SHAS
@resource.remote "origin"
@provider.should_receive(:setup_remote_tracking_branches).with(@resource.remote, @resource.repository)
fetch_command = "git fetch origin && git fetch origin --tags && git reset --hard d35af14d41ae22b19da05d7d03a0bafc321b244c"
- @provider.should_receive(:shell_out!).with(fetch_command, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]")
+ @provider.should_receive(:shell_out!).with(fetch_command, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]", :environment=>{})
@provider.fetch_updates
end
@@ -278,7 +279,7 @@ SHAS
@resource.remote "opscode"
@provider.should_receive(:setup_remote_tracking_branches).with(@resource.remote, @resource.repository)
fetch_command = "git fetch opscode && git fetch opscode --tags && git reset --hard d35af14d41ae22b19da05d7d03a0bafc321b244c"
- @provider.should_receive(:shell_out!).with(fetch_command, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]")
+ @provider.should_receive(:shell_out!).with(fetch_command, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]", :environment=>{})
@provider.fetch_updates
end
@@ -291,11 +292,13 @@ SHAS
@provider.should_receive(:shell_out!).with(expected_command,
:cwd => "/my/deploy/dir",
:log_tag => "git[web2.0 app]",
+ :environment=>{},
: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_tag => "git[web2.0 app]",
+ :environment=>{})
@provider.setup_remote_tracking_branches(@resource.remote, @resource.repository)
end
@@ -331,11 +334,13 @@ SHAS
@provider.should_receive(:shell_out!).with(check_remote_command,
:cwd => "/my/deploy/dir",
:log_tag => "git[web2.0 app]",
+ :environment=>{},
: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_tag => "git[web2.0 app]",
+ :environment=>{})
@provider.setup_remote_tracking_branches(@resource.remote, @resource.repository)
end
end
@@ -349,11 +354,13 @@ SHAS
@provider.should_receive(:shell_out!).with(check_remote_command,
:cwd => "/my/deploy/dir",
:log_tag => "git[web2.0 app]",
+ :environment=>{},
: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_tag => "git[web2.0 app]",
+ :environment=>{})
@provider.setup_remote_tracking_branches(@resource.remote, @resource.repository)
end
@@ -365,11 +372,13 @@ SHAS
@provider.should_receive(:shell_out!).with(check_remote_command,
:cwd => "/my/deploy/dir",
:log_tag => "git[web2.0 app]",
+ :environment=>{},
:returns => [0,1,2]).and_return(command_response)
unexpected_command = "git config --replace-all remote.#{@resource.remote}.url #{@resource.repository}"
@provider.should_not_receive(:shell_out!).with(unexpected_command,
:cwd => "/my/deploy/dir",
- :log_tag => "git[web2.0 app]")
+ :log_tag => "git[web2.0 app]",
+ :environment=>{})
@provider.setup_remote_tracking_branches(@resource.remote, @resource.repository)
end
@@ -380,11 +389,13 @@ SHAS
@provider.should_receive(:shell_out!).with(check_remote_command,
:cwd => "/my/deploy/dir",
:log_tag => "git[web2.0 app]",
+ :environment=>{},
: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_tag => "git[web2.0 app]",
+ :environment=>{})
@provider.setup_remote_tracking_branches(@resource.remote, @resource.repository)
end
end