Chef registry_key 资源在 rspec 测试中给出意外结果

Chef registry_key resource give unexpected result in rspec test

我从 LWRP 中的资源的 chefspec 测试中得到了一个奇怪的结果。资源如下所示:

registry_key "disable #{connection_mode} #{protocol}" do
  key "#{protocols_key}\#{protocol}\#{connection_mode}"
  values [{ name: 'Enabled', type: :dword, data: 0 }]
  recursive true
  action :create
end

对该资源的测试给出了以下结果:

Failure/Error:
 expect(chef_run).to create_registry_key("disable #{connection_mode} #{protocol}")
   .with(key: "#{protocols_registry_key}\#{protocol}\#{connection_mode}",
         values: [{ name: 'Enabled', type: :dword, data: 0 }],
         recursive: true)

  expected "registry_key[disable Client protocol_1]" to have parameters:

   values [{:name=>"Enabled", :type=>:dword, :data=>0}], was [{:name=>"Enabled", :type=>:dword, :data=>"5feceb66ffc86f38d952786c6d696c79c2dbc239dd4e91b46729d73a27fb57e9"}]

为什么资源会生成那个奇怪的字符串而不是值 0?

那是 "0" 的 SHA256。另见 https://github.com/chef/chef/blob/master/lib/chef/resource/registry_key.rb#L135-L136

如果将测试更改为 .with(key: ..., unscrubbed_values: ..., recursive: true),您可能会看到预期的结果。