(#12864) Close registry key
Previously, we were not closing the registry key (until the process
exits). It would be simplier to just use the block form of `open` that
automatically closes the key, but it makes it harder to test so this
commit explicitly closes the key.
Josh Cooper
11 years ago
2 | 2 |
def hklm_read(key, value)
|
3 | 3 |
require 'win32/registry'
|
4 | 4 |
reg = Win32::Registry::HKEY_LOCAL_MACHINE.open(key)
|
5 | |
reg[value]
|
|
5 |
rval = reg[value]
|
|
6 |
reg.close
|
|
7 |
rval
|
6 | 8 |
end
|
7 | 9 |
end
|
8 | 10 |
end
|
26 | 26 |
end
|
27 | 27 |
it "should return #{scenario[:expected]} value" do
|
28 | 28 |
Win32::Registry::HKEY_LOCAL_MACHINE.stubs(:open).with(scenario[:key]).returns(fake_registry_key)
|
|
29 |
fake_registry_key.stubs(:close)
|
29 | 30 |
|
30 | 31 |
Facter::Util::Registry.hklm_read(scenario[:key], scenario[:value]).should == scenario[:expected]
|
31 | 32 |
end
|
32 | 33 |
end
|
33 | 34 |
end
|
34 | 35 |
end
|
35 | |
|
|
36 |
|
36 | 37 |
describe "invalid params" do
|
37 | 38 |
[ {:key => "valid_key", :value => "invalid_value"},
|
38 | 39 |
{:key => "valid_key", :value => ""},
|
|
44 | 45 |
end
|
45 | 46 |
it "should raise an error" do
|
46 | 47 |
Win32::Registry::HKEY_LOCAL_MACHINE.stubs(:open).with(scenario[:key]).returns(fake_registry_key)
|
|
48 |
fake_registry_key.stubs(:close)
|
47 | 49 |
|
48 | 50 |
Facter::Util::Registry.hklm_read(scenario[:key], scenario[:value]).should raise_error
|
49 | 51 |
end
|