summaryrefslogtreecommitdiff
path: root/spec/unit/provider
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit/provider')
-rw-r--r--spec/unit/provider/deploy/revision_spec.rb1
-rw-r--r--spec/unit/provider/deploy_spec.rb1
-rw-r--r--spec/unit/provider/env/windows_spec.rb104
-rw-r--r--spec/unit/provider/git_spec.rb24
-rw-r--r--spec/unit/provider/package/homebrew_spec.rb14
-rw-r--r--spec/unit/provider/user/dscl_spec.rb3
6 files changed, 105 insertions, 42 deletions
diff --git a/spec/unit/provider/deploy/revision_spec.rb b/spec/unit/provider/deploy/revision_spec.rb
index 8d4590378e..9fa8bdf826 100644
--- a/spec/unit/provider/deploy/revision_spec.rb
+++ b/spec/unit/provider/deploy/revision_spec.rb
@@ -21,6 +21,7 @@ require 'spec_helper'
describe Chef::Provider::Deploy::Revision do
before do
+ Chef::Platform.stub(:windows?) { false }
@temp_dir = Dir.mktmpdir
Chef::Config[:file_cache_path] = @temp_dir
@resource = Chef::Resource::Deploy.new("/my/deploy/dir")
diff --git a/spec/unit/provider/deploy_spec.rb b/spec/unit/provider/deploy_spec.rb
index c6df0d4fdf..d85ee4c7fd 100644
--- a/spec/unit/provider/deploy_spec.rb
+++ b/spec/unit/provider/deploy_spec.rb
@@ -21,6 +21,7 @@ require 'spec_helper'
describe Chef::Provider::Deploy do
before do
+ Chef::Platform.stub(:windows?) { false }
@release_time = Time.utc( 2004, 8, 15, 16, 23, 42)
Time.stub(:now).and_return(@release_time)
@expected_release_dir = "/my/deploy/dir/releases/20040815162342"
diff --git a/spec/unit/provider/env/windows_spec.rb b/spec/unit/provider/env/windows_spec.rb
index 329448ac05..2ea137c1d9 100644
--- a/spec/unit/provider/env/windows_spec.rb
+++ b/spec/unit/provider/env/windows_spec.rb
@@ -19,49 +19,85 @@
require 'spec_helper'
describe Chef::Provider::Env::Windows, :windows_only do
- before do
- @node = Chef::Node.new
- @events = Chef::EventDispatch::Dispatcher.new
- @run_context = Chef::RunContext.new(@node, {}, @events)
- @new_resource = Chef::Resource::Env.new("CHEF_WINDOWS_ENV_TEST")
- @new_resource.value("foo")
- @provider = Chef::Provider::Env::Windows.new(@new_resource, @run_context)
- @provider.stub(:env_obj).and_return(double('null object').as_null_object)
- end
+ let(:node) { Chef::Node.new }
+ let(:events) {Chef::EventDispatch::Dispatcher.new }
+ let(:run_context) { Chef::RunContext.new(node, {}, events) }
- describe "action_create" do
- before do
- ENV.delete('CHEF_WINDOWS_ENV_TEST')
- @provider.key_exists = false
- end
+ context 'when environment variable is not PATH' do
+ let(:new_resource) {
+ new_resource = Chef::Resource::Env.new("CHEF_WINDOWS_ENV_TEST")
+ new_resource.value("foo")
+ new_resource
+ }
+ let(:provider) {
+ provider = Chef::Provider::Env::Windows.new(new_resource, run_context)
+ provider.stub(:env_obj).and_return(double('null object').as_null_object)
+ provider
+ }
- it "should update the ruby ENV object when it creates the key" do
- @provider.action_create
- expect(ENV['CHEF_WINDOWS_ENV_TEST']).to eql('foo')
- end
- end
+ describe "action_create" do
+ before do
+ ENV.delete('CHEF_WINDOWS_ENV_TEST')
+ provider.key_exists = false
+ end
- describe "action_modify" do
- before do
- ENV['CHEF_WINDOWS_ENV_TEST'] = 'foo'
+ it "should update the ruby ENV object when it creates the key" do
+ provider.action_create
+ expect(ENV['CHEF_WINDOWS_ENV_TEST']).to eql('foo')
+ end
end
- it "should update the ruby ENV object when it updates the value" do
- @provider.should_receive(:compare_value).and_return(true)
- @new_resource.value("foobar")
- @provider.action_modify
- expect(ENV['CHEF_WINDOWS_ENV_TEST']).to eql('foobar')
+ describe "action_modify" do
+ before do
+ ENV['CHEF_WINDOWS_ENV_TEST'] = 'foo'
+ end
+
+ it "should update the ruby ENV object when it updates the value" do
+ provider.should_receive(:compare_value).and_return(true)
+ new_resource.value("foobar")
+ provider.action_modify
+ expect(ENV['CHEF_WINDOWS_ENV_TEST']).to eql('foobar')
+ end
+
+ describe "action_delete" do
+ before do
+ ENV['CHEF_WINDOWS_ENV_TEST'] = 'foo'
+ end
+
+ it "should update the ruby ENV object when it deletes the key" do
+ provider.action_delete
+ expect(ENV['CHEF_WINDOWS_ENV_TEST']).to eql(nil)
+ end
+ end
end
end
- describe "action_delete" do
- before do
- ENV['CHEF_WINDOWS_ENV_TEST'] = 'foo'
- end
+ context 'when environment is PATH' do
+ describe "for PATH" do
+ let(:system_root) {'%SystemRoot%'}
+ let(:system_root_value) { 'D:\Windows' }
+ let(:new_resource) {
+ new_resource = Chef::Resource::Env.new('PATH')
+ new_resource.value(system_root)
+ new_resource
+ }
+ let(:provider) {
+ provider = Chef::Provider::Env::Windows.new(new_resource, run_context)
+ provider.stub(:env_obj).and_return(double('null object').as_null_object)
+ provider
+ }
- it "should update the ruby ENV object when it deletes the key" do
- @provider.action_delete
- expect(ENV['CHEF_WINDOWS_ENV_TEST']).to eql(nil)
+ before do
+ stub_const('ENV', {'PATH' => ''})
+ end
+
+ it "replaces Windows system variables" do
+ provider.should_receive(:compare_value).and_return(true)
+ provider.should_receive(:expand_path).with(system_root).and_return(system_root_value)
+ provider.action_modify
+ expect(ENV['PATH']).to eql(system_root_value)
+ end
end
+
end
end
diff --git a/spec/unit/provider/git_spec.rb b/spec/unit/provider/git_spec.rb
index 143c22da6e..ff1c0b0398 100644
--- a/spec/unit/provider/git_spec.rb
+++ b/spec/unit/provider/git_spec.rb
@@ -233,6 +233,21 @@ 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\""
+ version_response = double('shell_out')
+ version_response.stub(:stdout) { 'git version 1.7.9' }
+ @provider.should_receive(:shell_out!).with("git --version",
+ :log_tag => "git[web2.0 app]").and_return(version_response)
+ @provider.should_receive(:shell_out!).with(expected_cmd, :log_tag => "git[web2.0 app]")
+ @provider.clone
+ end
+
+ it "compiles a clone command using --no-single-branch for shallow cloning when git >= 1.7.10" do
+ @resource.depth 5
+ expected_cmd = "git clone --depth 5 --no-single-branch \"git://github.com/opscode/chef.git\" \"/my/deploy/dir\""
+ version_response = double('shell_out')
+ version_response.stub(:stdout) { 'git version 1.7.10' }
+ @provider.should_receive(:shell_out!).with("git --version",
+ :log_tag => "git[web2.0 app]").and_return(version_response)
@provider.should_receive(:shell_out!).with(expected_cmd, :log_tag => "git[web2.0 app]")
@provider.clone
end
@@ -244,10 +259,11 @@ SHAS
@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]")
+ it "runs a checkout command with default options" do
+ @provider.should_receive(:shell_out!).with('git branch -f deploy d35af14d41ae22b19da05d7d03a0bafc321b244c', :cwd => "/my/deploy/dir",
+ :log_tag => "git[web2.0 app]").ordered
+ @provider.should_receive(:shell_out!).with('git checkout deploy', :cwd => "/my/deploy/dir",
+ :log_tag => "git[web2.0 app]").ordered
@provider.checkout
end
diff --git a/spec/unit/provider/package/homebrew_spec.rb b/spec/unit/provider/package/homebrew_spec.rb
index 9f105c13b8..d38458546d 100644
--- a/spec/unit/provider/package/homebrew_spec.rb
+++ b/spec/unit/provider/package/homebrew_spec.rb
@@ -28,6 +28,8 @@ describe Chef::Provider::Package::Homebrew do
Chef::Provider::Package::Homebrew.new(new_resource, run_context)
end
+ let(:homebrew_uid) { 1001 }
+
let(:uninstalled_brew_info) do
{
'name' => 'emacs',
@@ -92,8 +94,7 @@ describe Chef::Provider::Package::Homebrew do
end
before(:each) do
- node.default['homebrew']['owner'] = 'sid_vicious'
- allow(Etc).to receive(:getpwnam).with('sid_vicious').and_return('/Users/sid_vicious')
+
end
describe 'load_current_resource' do
@@ -143,13 +144,18 @@ describe Chef::Provider::Package::Homebrew do
end
describe 'brew' do
+ before do
+ expect(provider).to receive(:find_homebrew_uid).and_return(homebrew_uid)
+ expect(Etc).to receive(:getpwuid).with(homebrew_uid).and_return(OpenStruct.new(:name => "name", :dir => "/"))
+ end
+
it 'passes a single to the brew command and return stdout' do
- allow(provider).to receive(:get_response_from_command).and_return('zombo')
+ allow(provider).to receive(:shell_out!).and_return(OpenStruct.new(:stdout => 'zombo'))
expect(provider.brew).to eql('zombo')
end
it 'takes multiple arguments as an array' do
- allow(provider).to receive(:get_response_from_command).and_return('homestarrunner')
+ allow(provider).to receive(:shell_out!).and_return(OpenStruct.new(:stdout => 'homestarrunner'))
expect(provider.brew('info', 'opts', 'bananas')).to eql('homestarrunner')
end
end
diff --git a/spec/unit/provider/user/dscl_spec.rb b/spec/unit/provider/user/dscl_spec.rb
index b272eceada..c17aefb00d 100644
--- a/spec/unit/provider/user/dscl_spec.rb
+++ b/spec/unit/provider/user/dscl_spec.rb
@@ -23,6 +23,9 @@ require 'ostruct'
require 'mixlib/shellout'
describe Chef::Provider::User::Dscl do
+ before do
+ Chef::Platform.stub(:windows?) { false }
+ end
let(:node) {
node = Chef::Node.new
node.stub(:[]).with(:platform_version).and_return(mac_version)