summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn McCrae <john.mccrae@progress.com>2022-06-15 17:30:29 -0700
committerJohn McCrae <john.mccrae@progress.com>2022-06-24 11:23:33 -0700
commit326af7f58592cef4c6e997296ec50c4eccb39826 (patch)
treec26ca0042ee69b24bcc4bba804f2658b2a6e2c35
parent786715a03bfa2466800941d8edbbd5a558df8820 (diff)
downloadchef-326af7f58592cef4c6e997296ec50c4eccb39826.tar.gz
Refactored code to be more readable and changed a test to correct for starting out with Auto-Managed being false by default
Signed-off-by: John McCrae <john.mccrae@progress.com>
-rw-r--r--lib/chef/resource/windows_pagefile.rb10
-rw-r--r--spec/functional/resource/windows_pagefile_spec.rb4
2 files changed, 8 insertions, 6 deletions
diff --git a/lib/chef/resource/windows_pagefile.rb b/lib/chef/resource/windows_pagefile.rb
index 03649e28aa..ca80d5b2ab 100644
--- a/lib/chef/resource/windows_pagefile.rb
+++ b/lib/chef/resource/windows_pagefile.rb
@@ -148,10 +148,12 @@ class Chef
def exists?(pagefile)
@exists ||= begin
logger.trace("Checking if #{pagefile} exists by running: Get-CimInstance Win32_PagefileSetting | Where-Object { $_.name -eq $($pagefile)} ")
- cmd = "$page_file_name = '#{pagefile}';"
- cmd << "$pagefile = Get-CimInstance Win32_PagefileSetting | Where-Object { $_.name -eq $($page_file_name)};"
- cmd << "if ([string]::IsNullOrEmpty($pagefile)) { return $false } else { return $true }"
- powershell_exec!(cmd).result
+ powershell_code = <<~CODE
+ $page_file_name = '#{pagefile}';
+ $pagefile = Get-CimInstance Win32_PagefileSetting | Where-Object { $_.name -eq $($page_file_name)}
+ if ([string]::IsNullOrEmpty($pagefile)) { return $false } else { return $true }
+ CODE
+ powershell_exec!(powershell_code).result
end
end
diff --git a/spec/functional/resource/windows_pagefile_spec.rb b/spec/functional/resource/windows_pagefile_spec.rb
index fd44c01973..bb30c0e054 100644
--- a/spec/functional/resource/windows_pagefile_spec.rb
+++ b/spec/functional/resource/windows_pagefile_spec.rb
@@ -42,11 +42,11 @@ describe Chef::Resource::WindowsPagefile, :windows_only do
describe "Setting Up Pagefile Management" do
context "Disable Automatic Management" do
- it "Disables Automatic Management" do
+ it "Verifies Automatic Management is Disabled" do
subject.path c_path
subject.automatic_managed false
subject.run_action(:set)
- expect(subject).to be_updated_by_last_action
+ expect(subject).not_to be_updated_by_last_action
end
it "Enable Automatic Management " do