summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantima-gupta <agupta@msystechnologies.com>2020-08-27 14:13:25 +0530
committerantima-gupta <agupta@msystechnologies.com>2020-08-27 14:13:25 +0530
commitd0764e7849a69f5ce9b0a7bf24a7c0263a9f2c8e (patch)
treebda62ca62c17673ce9f03507b03c283e566357f3
parentc5d66d9c6a87af1b210b91a55ca1e14194b46e22 (diff)
downloadchef-d0764e7849a69f5ce9b0a7bf24a7c0263a9f2c8e.tar.gz
Update changes as per review comment.
Signed-off-by: antima-gupta <agupta@msystechnologies.com>
-rw-r--r--spec/unit/provider/mount/linux_spec.rb85
1 files changed, 46 insertions, 39 deletions
diff --git a/spec/unit/provider/mount/linux_spec.rb b/spec/unit/provider/mount/linux_spec.rb
index f31da1433a..e6d903dffc 100644
--- a/spec/unit/provider/mount/linux_spec.rb
+++ b/spec/unit/provider/mount/linux_spec.rb
@@ -2,20 +2,27 @@ require "spec_helper"
require "ostruct"
describe Chef::Provider::Mount::Linux do
- before(:each) do
- @node = Chef::Node.new
- @events = Chef::EventDispatch::Dispatcher.new
- @run_context = Chef::RunContext.new(@node, {}, @events)
- @new_resource = Chef::Resource::Mount.new("/tmp/foo")
- @new_resource.device "/dev/sdz1"
- @new_resource.device_type :device
- @new_resource.fstype "ext3"
+ let(:run_context) do
+ node = Chef::Node.new
+ events = Chef::EventDispatch::Dispatcher.new
+ run_context = Chef::RunContext.new(node, {}, events)
+ end
- @new_resource.supports remount: false
+ let(:new_resource) do
+ new_resource = Chef::Resource::Mount.new("/tmp/foo")
+ new_resource.device "/dev/sdz1"
+ new_resource.device_type :device
+ new_resource.fstype "ext3"
+ new_resource.supports remount: false
+ new_resource
+ end
- @provider = Chef::Provider::Mount::Linux.new(@new_resource, @run_context)
+ let(:provider) do
+ Chef::Provider::Mount::Linux.new(new_resource, run_context)
+ end
+ before(:each) do
allow(::File).to receive(:exists?).with("/dev/sdz1").and_return true
allow(::File).to receive(:exists?).with("/tmp/foo").and_return true
allow(::File).to receive(:realpath).with("/dev/sdz1").and_return "/dev/sdz1"
@@ -25,27 +32,27 @@ describe Chef::Provider::Mount::Linux do
context "to see if the volume is mounted" do
it "should set mounted true if the mount point is found in the mounts list" do
- allow(@provider).to receive(:shell_out!).and_return(OpenStruct.new(stdout: "/tmp/foo /dev/sdz1 type ext3 (rw)\n"))
- @provider.load_current_resource
- expect(@provider.current_resource.mounted).to be_truthy
+ allow(provider).to receive(:shell_out!).and_return(double(stdout: "/tmp/foo /dev/sdz1 type ext3 (rw)\n"))
+ provider.load_current_resource
+ expect(provider.current_resource.mounted).to be_truthy
end
it "should set mounted false if another mount point beginning with the same path is found in the mounts list" do
- allow(@provider).to receive(:shell_out!).and_return(OpenStruct.new(stdout: "/tmp/foobar /dev/sdz1 type ext3 (rw)\n"))
- @provider.load_current_resource
- expect(@provider.current_resource.mounted).to be_falsey
+ allow(provider).to receive(:shell_out!).and_return(double(stdout: "/tmp/foobar /dev/sdz1 type ext3 (rw)\n"))
+ provider.load_current_resource
+ expect(provider.current_resource.mounted).to be_falsey
end
it "should set mounted true if the symlink target of the device is found in the mounts list" do
# expand the target path to correct specs on Windows
target = ::File.expand_path("/dev/mapper/target")
- allow(::File).to receive(:symlink?).with((@new_resource.device).to_s).and_return(true)
- allow(::File).to receive(:readlink).with((@new_resource.device).to_s).and_return(target)
+ allow(::File).to receive(:symlink?).with((new_resource.device).to_s).and_return(true)
+ allow(::File).to receive(:readlink).with((new_resource.device).to_s).and_return(target)
- allow(@provider).to receive(:shell_out!).and_return(OpenStruct.new(stdout: "/tmp/foo #{target} type ext3 (rw)\n"))
- @provider.load_current_resource
- expect(@provider.current_resource.mounted).to be_truthy
+ allow(provider).to receive(:shell_out!).and_return(double(stdout: "/tmp/foo #{target} type ext3 (rw)\n"))
+ provider.load_current_resource
+ expect(provider.current_resource.mounted).to be_truthy
end
it "should set mounted true if the symlink target of the device is relative and is found in the mounts list - CHEF-4957" do
@@ -54,36 +61,36 @@ describe Chef::Provider::Mount::Linux do
# expand the target path to correct specs on Windows
absolute_target = ::File.expand_path("/dev/xsdz1")
- allow(::File).to receive(:symlink?).with((@new_resource.device).to_s).and_return(true)
- allow(::File).to receive(:readlink).with((@new_resource.device).to_s).and_return(target)
+ allow(::File).to receive(:symlink?).with((new_resource.device).to_s).and_return(true)
+ allow(::File).to receive(:readlink).with((new_resource.device).to_s).and_return(target)
- allow(@provider).to receive(:shell_out!).and_return(OpenStruct.new(stdout: "/tmp/foo #{absolute_target} type ext3 (rw)\n"))
- @provider.load_current_resource
- expect(@provider.current_resource.mounted).to be_truthy
+ allow(provider).to receive(:shell_out!).and_return(double(stdout: "/tmp/foo #{absolute_target} type ext3 (rw)\n"))
+ provider.load_current_resource
+ expect(provider.current_resource.mounted).to be_truthy
end
it "should set mounted true if the mount point is found last in the mounts list" do
- mount = "#{@new_resource.mount_point} /dev/sdy1 type ext3 (rw)\n"
- mount << "#{@new_resource.mount_point} #{@new_resource.device} type ext3 (rw)\n"
+ mount = "#{new_resource.mount_point} /dev/sdy1 type ext3 (rw)\n"
+ mount << "#{new_resource.mount_point} #{new_resource.device} type ext3 (rw)\n"
- allow(@provider).to receive(:shell_out!).and_return(OpenStruct.new(stdout: mount))
- @provider.load_current_resource
- expect(@provider.current_resource.mounted).to be_truthy
+ allow(provider).to receive(:shell_out!).and_return(double(stdout: mount))
+ provider.load_current_resource
+ expect(provider.current_resource.mounted).to be_truthy
end
it "should set mounted false if the mount point is not last in the mounts list" do
- mount = "#{@new_resource.device} on #{@new_resource.mount_point} type ext3 (rw)\n"
- mount << "/dev/sdy1 on #{@new_resource.mount_point} type ext3 (rw)\n"
+ mount = "#{new_resource.device} on #{new_resource.mount_point} type ext3 (rw)\n"
+ mount << "/dev/sdy1 on #{new_resource.mount_point} type ext3 (rw)\n"
- allow(@provider).to receive(:shell_out!).and_return(OpenStruct.new(stdout: mount))
- @provider.load_current_resource
- expect(@provider.current_resource.mounted).to be_falsey
+ allow(provider).to receive(:shell_out!).and_return(double(stdout: mount))
+ provider.load_current_resource
+ expect(provider.current_resource.mounted).to be_falsey
end
it "mounted should be false if the mount point is not found in the mounts list" do
- allow(@provider).to receive(:shell_out!).and_return(OpenStruct.new(stdout: "/dev/sdy1 on /tmp/foo type ext3 (rw)\n"))
- @provider.load_current_resource
- expect(@provider.current_resource.mounted).to be_falsey
+ allow(provider).to receive(:shell_out!).and_return(double(stdout: "/dev/sdy1 on /tmp/foo type ext3 (rw)\n"))
+ provider.load_current_resource
+ expect(provider.current_resource.mounted).to be_falsey
end
end