summaryrefslogtreecommitdiff
path: root/spec/unit/provider/git_spec.rb
diff options
context:
space:
mode:
authorKapil Chouhan <kapil.chouhan@msystechnologies.com>2020-04-15 18:08:00 +0530
committerKapil Chouhan <kapil.chouhan@msystechnologies.com>2020-04-17 17:07:34 +0530
commitadcc1c6d0fe1b4cb34dc981b1819177545b30463 (patch)
tree40801fc5df64692c13d7ba73af24bc340f1e6ecc /spec/unit/provider/git_spec.rb
parentcb4383bb80656be29db6194308d6a913894ad218 (diff)
downloadchef-adcc1c6d0fe1b4cb34dc981b1819177545b30463.tar.gz
Fix for exception raised in define resource requirementsKapil/GitHub-2860_exception_raised_in_define_resource_requirements
Signed-off-by: Kapil Chouhan <kapil.chouhan@msystechnologies.com>
Diffstat (limited to 'spec/unit/provider/git_spec.rb')
-rw-r--r--spec/unit/provider/git_spec.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/spec/unit/provider/git_spec.rb b/spec/unit/provider/git_spec.rb
index 9a6ae31397..953c3c1e98 100644
--- a/spec/unit/provider/git_spec.rb
+++ b/spec/unit/provider/git_spec.rb
@@ -590,6 +590,43 @@ describe Chef::Provider::Git do
end
end
+ context "with why-run mode" do
+ before do
+ Chef::Config[:why_run] = true
+ @resource.user "test"
+ end
+
+ after do
+ Chef::Config[:why_run] = false
+ end
+
+ it "does not raise an error if user does not exist" do
+ allow(@provider).to receive(:get_homedir).with(@resource.user).and_return(nil)
+ expect { @provider.run_action(:sync) }.not_to raise_error
+ end
+
+ it "does not raise an error if user exists" do
+ allow(@provider).to receive(:get_homedir).with(@resource.user).and_return("/home/test")
+ expect { @provider.run_action(:sync) }.not_to raise_error(ArgumentError)
+ end
+ end
+
+ context "without why-run mode" do
+ before do
+ @resource.user "test"
+ end
+
+ it "raises an error if user does not exist" do
+ allow(@provider).to receive(:get_homedir).with(@resource.user).and_return(nil)
+ expect { @provider.run_action(:sync) }.to raise_error(Chef::Exceptions::User)
+ end
+
+ it "does not raise an error if user exists" do
+ allow(@provider).to receive(:get_homedir).with(@resource.user).and_return("/home/test")
+ expect { @provider.run_action(:sync) }.not_to raise_error(Chef::Exceptions::User)
+ end
+ end
+
it "raises an error if the git clone command would fail because the enclosing directory doesn't exist" do
allow(@provider).to receive(:shell_out!)
expect { @provider.run_action(:sync) }.to raise_error(Chef::Exceptions::MissingParentDirectory)