summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Vlaardingerbroek <kristian.vlaardingerbroek@gmail.com>2013-02-02 16:15:07 +0100
committerBryan McLellan <btm@opscode.com>2013-04-12 11:49:11 -0700
commitf4b6168b6370647024a059036c8310e576258246 (patch)
tree7f65ab238bfe9479ac34b7e217a33f73688c8c14
parent82f099ce46de029ee756cc497910262262c15b61 (diff)
downloadchef-f4b6168b6370647024a059036c8310e576258246.tar.gz
Add comment to regular expression and add unit tests
-rw-r--r--lib/chef/provider/mount/mount.rb1
-rw-r--r--spec/unit/provider/mount/mount_spec.rb26
2 files changed, 27 insertions, 0 deletions
diff --git a/lib/chef/provider/mount/mount.rb b/lib/chef/provider/mount/mount.rb
index 593a09ecbe..2e98b7a69c 100644
--- a/lib/chef/provider/mount/mount.rb
+++ b/lib/chef/provider/mount/mount.rb
@@ -225,6 +225,7 @@ class Chef
# ignore trailing slash
Regexp.escape(device_real)+"/?"
elsif ::File.symlink?(device_real)
+ # This regular expression tries to match device_real. If that does not match it will try to match the target of device_real.
"(?:#{Regexp.escape(device_real)}|#{Regexp.escape(::File.readlink(device_real))})"
else
Regexp.escape(device_real)
diff --git a/spec/unit/provider/mount/mount_spec.rb b/spec/unit/provider/mount/mount_spec.rb
index c497a08e40..f6c6c1b7d4 100644
--- a/spec/unit/provider/mount/mount_spec.rb
+++ b/spec/unit/provider/mount/mount_spec.rb
@@ -216,6 +216,32 @@ describe Chef::Provider::Mount::Mount do
@provider.load_current_resource
@provider.current_resource.enabled.should be_false
end
+
+ it "should not mangle the mount options if the device in fstab is a symlink" do
+ target = "/dev/mapper/target"
+ options = "rw,noexec,noauto"
+
+ ::File.stub!(:symlink?).with("#{@new_resource.device}").and_return(true)
+ ::File.stub!(:readlink).with("#{@new_resource.device}").and_return(target)
+
+ fstab = "#{@new_resource.device} #{@new_resource.mount_point} #{@new_resource.fstype} #{options} 1 2\n"
+ ::File.stub!(:foreach).with("/etc/fstab").and_yield fstab
+ @provider.load_current_resource
+ @provider.current_resource.options.should eq(options.split(','))
+ end
+
+ it "should not mangle the mount options if the symlink target is in fstab" do
+ target = "/dev/mapper/target"
+ options = "rw,noexec,noauto"
+
+ ::File.stub!(:symlink?).with("#{@new_resource.device}").and_return(true)
+ ::File.stub!(:readlink).with("#{@new_resource.device}").and_return(target)
+
+ fstab = "#{target} #{@new_resource.mount_point} #{@new_resource.fstype} #{options} 1 2\n"
+ ::File.stub!(:foreach).with("/etc/fstab").and_yield fstab
+ @provider.load_current_resource
+ @provider.current_resource.options.should eq(options.split(','))
+ end
end
context "after the mount's state has been discovered" do