summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Magnus Rakvåg <tor.magnus@outlook.com>2019-10-08 12:24:35 +0200
committerTor Magnus Rakvåg <tor.magnus@outlook.com>2019-10-08 12:24:35 +0200
commitfaf716e65b2b20ada260e0ce4cda030a2c2bb894 (patch)
tree455b7bff68cab8270370ff3cd581c107b5d850e0
parent1e298cbc10f7814a3610eb7d7f8ba3a52456bda2 (diff)
downloadchef-faf716e65b2b20ada260e0ce4cda030a2c2bb894.tar.gz
make path idempotent by coercing to backwhacks
Signed-off-by: Tor Magnus Rakvåg <tor.magnus@outlook.com>
-rw-r--r--lib/chef/resource/windows_share.rb3
-rw-r--r--spec/unit/resource/windows_share_spec.rb7
2 files changed, 9 insertions, 1 deletions
diff --git a/lib/chef/resource/windows_share.rb b/lib/chef/resource/windows_share.rb
index a5924d2996..b4f344eb96 100644
--- a/lib/chef/resource/windows_share.rb
+++ b/lib/chef/resource/windows_share.rb
@@ -38,7 +38,8 @@ class Chef
# Specifies the path of the location of the folder to share. The path must be fully qualified. Relative paths or paths that contain wildcard characters are not permitted.
property :path, String,
- description: "The path of the folder to share. Required when creating. If the share already exists on a different path then it is deleted and re-created."
+ description: "The path of the folder to share. Required when creating. If the share already exists on a different path then it is deleted and re-created.",
+ coerce: proc { |p| p.gsub!(%r{/}, "\\") || p }
# Specifies an optional description of the SMB share. A description of the share is displayed by running the Get-SmbShare cmdlet. The description may not contain more than 256 characters.
property :description, String,
diff --git a/spec/unit/resource/windows_share_spec.rb b/spec/unit/resource/windows_share_spec.rb
index ee1c24529f..365d2c7b11 100644
--- a/spec/unit/resource/windows_share_spec.rb
+++ b/spec/unit/resource/windows_share_spec.rb
@@ -36,4 +36,11 @@ describe Chef::Resource::WindowsShare do
expect { resource.action :create }.not_to raise_error
expect { resource.action :delete }.not_to raise_error
end
+
+ it "coerces path to a single path separator format" do
+ resource.path("C:/chef")
+ expect(resource.path).to eql("C:\\chef")
+ resource.path("C:\\chef")
+ expect(resource.path).to eql("C:\\chef")
+ end
end