diff options
author | Tim Smith <tsmith@chef.io> | 2021-09-16 18:38:49 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-16 18:38:49 -0700 |
commit | ef0584b4c8fdc418438b40f93fbdea1de05a66d4 (patch) | |
tree | c796c6eee08a09205449849dbe729eefbb7c797b | |
parent | fcac6598c1c8c3689c623ebdfe0294b992168e2f (diff) | |
parent | 9676ebe1f27e127808692d24dc6c476d80d4d0d3 (diff) | |
download | chef-ef0584b4c8fdc418438b40f93fbdea1de05a66d4.tar.gz |
Merge pull request #12049 from chef/mount_16
Coerce mount_point only when it is not root directory
-rw-r--r-- | lib/chef/resource/mount.rb | 2 | ||||
-rw-r--r-- | spec/unit/resource/mount_spec.rb | 10 |
2 files changed, 11 insertions, 1 deletions
diff --git a/lib/chef/resource/mount.rb b/lib/chef/resource/mount.rb index c23ba9bbee..c28c0357a3 100644 --- a/lib/chef/resource/mount.rb +++ b/lib/chef/resource/mount.rb @@ -41,7 +41,7 @@ class Chef sensitive: true property :mount_point, String, name_property: true, - coerce: proc { |arg| arg.chomp("/") }, # Removed "/" from the end of str, because it was causing idempotency issue. + coerce: proc { |arg| (arg == "/" || arg.match?(":/$")) ? arg : arg.chomp("/") }, # Removed "/" from the end of str, because it was causing idempotency issue. description: "The directory (or path) in which the device is to be mounted. Defaults to the name of the resource block if not provided." property :device, String, identity: true, diff --git a/spec/unit/resource/mount_spec.rb b/spec/unit/resource/mount_spec.rb index c9800f1381..1e1c36a5dd 100644 --- a/spec/unit/resource/mount_spec.rb +++ b/spec/unit/resource/mount_spec.rb @@ -59,6 +59,16 @@ describe Chef::Resource::Mount do expect(resource.mount_point).to eql("//192.168.11.102/Share/backup") end + it "does not strip slash when mount_point is root directory" do + resource.mount_point "/" + expect(resource.mount_point).to eql("/") + end + + it "does not strip slash when mount_point is root of network mount" do + resource.mount_point "127.0.0.1:/" + expect(resource.mount_point).to eql("127.0.0.1:/") + end + it "raises error when mount_point property is not set" do expect { resource.mount_point nil }.to raise_error(Chef::Exceptions::ValidationFailed, "Property mount_point must be one of: String! You passed nil.") end |