diff options
author | antima-gupta <agupta@msystechnologies.com> | 2020-08-20 11:18:59 +0530 |
---|---|---|
committer | antima-gupta <agupta@msystechnologies.com> | 2020-08-27 14:10:18 +0530 |
commit | c5d66d9c6a87af1b210b91a55ca1e14194b46e22 (patch) | |
tree | f54e65f0270a73bbbc45b8d88962a963dc7ca0a7 /spec/unit/provider/mount | |
parent | eea7be017e6e4fbf20d050fe0cd7358bfc1503bf (diff) | |
download | chef-c5d66d9c6a87af1b210b91a55ca1e14194b46e22.tar.gz |
Added context in the linux mount provider spec
Signed-off-by: antima-gupta <agupta@msystechnologies.com>
Diffstat (limited to 'spec/unit/provider/mount')
-rw-r--r-- | spec/unit/provider/mount/linux_spec.rb | 124 |
1 files changed, 64 insertions, 60 deletions
diff --git a/spec/unit/provider/mount/linux_spec.rb b/spec/unit/provider/mount/linux_spec.rb index feb8d97167..f31da1433a 100644 --- a/spec/unit/provider/mount/linux_spec.rb +++ b/spec/unit/provider/mount/linux_spec.rb @@ -22,66 +22,70 @@ describe Chef::Provider::Mount::Linux do allow(::File).to receive(:realpath).with("/tmp/foo").and_return "/tmp/foo" end - 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 - 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 - 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(@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 - 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 - target = "xsdz1" - - # 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(@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 - 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" - - allow(@provider).to receive(:shell_out!).and_return(OpenStruct.new(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" - - allow(@provider).to receive(:shell_out!).and_return(OpenStruct.new(stdout: mount)) - @provider.load_current_resource - expect(@provider.current_resource.mounted).to be_falsey - end + 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 + 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 + 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(@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 + 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 + target = "xsdz1" + + # 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(@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 + 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" + + allow(@provider).to receive(:shell_out!).and_return(OpenStruct.new(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" + + allow(@provider).to receive(:shell_out!).and_return(OpenStruct.new(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 + 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 end -end
\ No newline at end of file +end |