-2

我的食谱:

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

在切佩克:

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 中不存在错误

4

1 回答 1

0

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

let(:chef_run) { ChefSpec::SoloRunner.new(platform: 'windows', version: '2012R2').converge(described_recipe) }
于 2016-02-17T21:50:15.043 回答