在chefspec中注册表项HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Microsoft SQL Server \ Instance Names \ SQL不存在错误

时间:2016-02-17 12:55:20

标签: chef sql-server-ce chefspec

我的食谱:

instance_names.each do |instance_name|
    instance_name_service=instance_name.split('.')[1]
    instance_name_service = instance_name_service == 'MSSQLSERVER'? 'MSSQLSERVER' : "MSSQL$#{instance_name_service}"
    path="HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SQL Server\\#{instance_name}\\MSSQLServer"
    registry_key path do
        architecture :"#{var_architecture}"
        values [{
            :name => 'AuditLevel',
            :type => :dword,
            :data => 3
        }]
        action :create
        not_if ( false )
    end
end

在chefpec:

require_relative '../../spec_helper'
require 'chefspec'
describe 'regcheck::default' do
    let(:chef_run) { ChefSpec::SoloRunner.new.converge(described_recipe) }
    it 'recipe loads all the dependency files and converges successfully' do
        chef_run
    end 
    context 'regcheck' do
        it 'creates or updates audit level settings for sql instances' do
            expect(chef_run).to create_registry_key('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL12.SQLINSTANCE1\MSSQLServer')
        end
    end
end

我收到了这个错误:

  

注册表项HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Microsoft SQL Server \ Instance Names \ SQL在chefspec中不存在错误

1 个答案:

答案 0 :(得分:0)

您需要将ChefSpec设置为模拟Windows平台,以使registry_key资源正常工作。

let(:chef_run) { ChefSpec::SoloRunner.new(platform: 'windows', version: '2012R2').converge(described_recipe) }