Codebase list facter / 964d1f0
(#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 changed file(s) with 6 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
22 def hklm_read(key, value)
33 require 'win32/registry'
44 reg = Win32::Registry::HKEY_LOCAL_MACHINE.open(key)
5 reg[value]
5 rval = reg[value]
6 reg.close
7 rval
68 end
79 end
810 end
2626 end
2727 it "should return #{scenario[:expected]} value" do
2828 Win32::Registry::HKEY_LOCAL_MACHINE.stubs(:open).with(scenario[:key]).returns(fake_registry_key)
29 fake_registry_key.stubs(:close)
2930
3031 Facter::Util::Registry.hklm_read(scenario[:key], scenario[:value]).should == scenario[:expected]
3132 end
3233 end
3334 end
3435 end
35
36
3637 describe "invalid params" do
3738 [ {:key => "valid_key", :value => "invalid_value"},
3839 {:key => "valid_key", :value => ""},
4445 end
4546 it "should raise an error" do
4647 Win32::Registry::HKEY_LOCAL_MACHINE.stubs(:open).with(scenario[:key]).returns(fake_registry_key)
48 fake_registry_key.stubs(:close)
4749
4850 Facter::Util::Registry.hklm_read(scenario[:key], scenario[:value]).should raise_error
4951 end