Skip to content

Instantly share code, notes, and snippets.

@vinyar
Created August 8, 2014 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vinyar/c6a4a1b3fc631634a179 to your computer and use it in GitHub Desktop.
Save vinyar/c6a4a1b3fc631634a179 to your computer and use it in GitHub Desktop.
serverspec failing on reg_key numbers
Windows registry key "HKLM\Software\Policies\Microsoft\Power\PowerSettings\3C0BC021-C8A8-4E07-A973-6B14CBCB2B7E" should have property value "ACSettingIndex", :type_dword, "1200"
Failure/Error: it { should have_property_value('ACSettingIndex', :type_dword, '1200')}
$exitCode = 1
$ProgressPreference = "SilentlyContinue"
try {
$success = ((Compare-Object (Get-Item 'Registry::HKLM\Software\Policies\Microsoft\Power\PowerSettings\3C0BC021-C8A8-4E07-A973-6B14CBCB2B7E').GetValue('ACSettingIndex') 4608) -eq $null)
if ($success -is [Boolean] -and $success) { $exitCode = 0 }
} catch {
Write-Output $_.Exception.Message
}
Write-Output "Exiting with code: $exitCode"
exit $exitCode
Exiting with code: 1
expected #has_property_value?("ACSettingIndex", :type_dword, "1200") to return true, got false
# ./test/integration/windows/spec/localhost/2012_spec.rb:144:in `block (2 levels) in <top (required)>'
@vinyar
Copy link
Author

vinyar commented Aug 8, 2014

actual test:

describe windows_registry_key('HKLM\Software\Policies\Microsoft\Power\PowerSettings\3C0BC021-C8A8-4E07-A973-6B14CBCB2B7E') do
it { should have_property_value('DCSettingIndex', :type_dword, '1200')}
it { should have_property_value('ACSettingIndex', :type_dword, '1200')}
end

Notice in the output above, that the test compares 1200 to 4608 --> .GetValue('ACSettingIndex') 4608)
Some messing around later in ruby land - "1200".to_i(16) = 4608

@vinyar
Copy link
Author

vinyar commented Aug 8, 2014

Seems I cant really hack around it either:

Hack:
describe windows_registry_key('HKLM\Software\Policies\Microsoft\Power\PowerSettings\3C0BC021-C8A8-4E07-A973-6B14CBCB2B7E') do
it { should exist }
it { should have_property_value('DCSettingIndex', :type_dword, "#{"1200".to_i(16)}")}
it { should have_property_value('ACSettingIndex', :type_dword, '1200'.to_i(16))}
end

Error:

  1. Windows registry key "HKLM\Software\Policies\Microsoft\Power\PowerSettings\3C0BC021-C8A8-4E07-A973-6B14CBCB2B7E" should have property value "DCSettingIndex", :type_dword, "4608"
    Failure/Error: it { should have_property_value('DCSettingIndex', :type_dword, "#{"1200".to_i(16)}")}
    $exitCode = 1
    $ProgressPreference = "SilentlyContinue"
    try {

$success = ((Compare-Object (Get-Item 'Registry::HKLM\Software\Policies\Microsoft\Power\PowerSettings\3C0BC021-C8A8-4E07-A973-6B14CBCB2B7E').GetValue('DCSettingIndex') 17928) -eq $null)
if ($success -is [Boolean] -and $success) { $exitCode = 0 }
} catch {
Write-Output $_.Exception.Message
}
Write-Output "Exiting with code: $exitCode"
exit $exitCode

   Exiting with code: 1

   expected #has_property_value?("DCSettingIndex", :type_dword, "4608") to return true, got false
 # ./test/integration/windows/spec/localhost/2012_spec.rb:143:in `block (2 levels) in <top (required)>'
  1. Windows registry key "HKLM\Software\Policies\Microsoft\Power\PowerSettings\3C0BC021-C8A8-4E07-A973-6B14CBCB2B7E" should have property value "ACSettingIndex", :type_dword, 4608
    Failure/Error: it { should have_property_value('ACSettingIndex', :type_dword, '1200'.to_i(16))}
    NoMethodError: undefined method `rjust' for 4608:Fixnum
   undefined method `rjust' for 4608:Fixnum
 # ./test/integration/windows/spec/localhost/2012_spec.rb:144:in `block (2 levels) in <top (required)>'

Finished in 1.09 seconds
3 examples, 2 failures

Failed examples:

rspec ./test/integration/windows/spec/localhost/2012_spec.rb:143 # Windows registry key "HKLM\Software\Policies\Microsoft\Power\PowerSettings\3C0BC021-C8A8-4E07-A973-6B14CBCB2B7E" should have property value "DCSettingIndex", :type_dword, "4608"
rspec ./test/integration/windows/spec/localhost/2012_spec.rb:144 # Windows registry key "HKLM\Software\Policies\Microsoft\Power\PowerSettings\3C0BC021-C8A8-4E07-A973-6B14CBCB2B7E" should have property value "ACSettingIndex", :type_dword, 4608

@vinyar
Copy link
Author

vinyar commented Aug 8, 2014

I didnt find any elegant way of hacking it, so until serverspec is fixed, I converted all of the actual values to what serverspec expects them to be with " .to_s(16) "

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment