summaryrefslogtreecommitdiff
path: root/spec/unit
diff options
context:
space:
mode:
authorPete Higgins <pete@peterhiggins.org>2020-06-15 13:08:04 -0700
committerPete Higgins <pete@peterhiggins.org>2020-06-16 16:45:26 -0700
commit164e0a8e87f35b1752d2d3b4db58accdb7ac3a91 (patch)
tree6768cd195e79abb5dea95ba6d2ed364ce32a71b1 /spec/unit
parent8415abfd29efa28f106bf7e43cde00268b3222f9 (diff)
downloadchef-164e0a8e87f35b1752d2d3b4db58accdb7ac3a91.tar.gz
Add a umask property for resources.
Signed-off-by: Pete Higgins <pete@peterhiggins.org>
Diffstat (limited to 'spec/unit')
-rw-r--r--spec/unit/resource_spec.rb51
1 files changed, 51 insertions, 0 deletions
diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb
index fd32313c83..686863d367 100644
--- a/spec/unit/resource_spec.rb
+++ b/spec/unit/resource_spec.rb
@@ -1236,4 +1236,55 @@ describe Chef::Resource do
expect(resource.tagged?("foo")).to be(false)
end
end
+
+ describe "#with_umask" do
+ let(:resource) { Chef::Resource.new("testy testerson") }
+ it "does not affect the umask by default" do
+ original_value = ::File.umask
+ block_value = nil
+
+ resource.with_umask do
+ block_value = ::File.umask
+ end
+
+ expect(block_value).to eq(original_value)
+ end
+
+ it "changes the umask in the block to the set value" do
+ block_value = nil
+
+ resource.umask = "0123"
+
+ resource.with_umask do
+ block_value = ::File.umask
+ end
+
+ # Format the returned value so a potential error message is easier to understand.
+ actual_value = block_value.to_s(8).rjust(4, "0")
+
+ expect(actual_value).to eq("0123")
+ end
+
+ it "resets the umask afterwards" do
+ original_value = ::File.umask
+
+ resource.umask = "0123"
+
+ resource.with_umask do
+ "noop"
+ end
+
+ expect(::File.umask).to eq(original_value)
+ end
+
+ it "resets the umask if the block raises an error" do
+ original_value = ::File.umask
+
+ resource.umask = "0123"
+
+ expect { resource.with_umask { 1/0 } }.to raise_error(ZeroDivisionError)
+
+ expect(::File.umask).to eq(original_value)
+ end
+ end
end