Puppet-rspec 一直在尝试从字符串转换为整数时出错

Puppet-rspec keeps failing on error trying to convert from string to integer

我在 Puppet 中不断收到此错误:

 1) hazelcast with defaults for all parameters should contain Class[hazelcast]
     Failure/Error: it { is_expected.to contain_class('hazelcast') }
     Puppet::PreformattedError:
       Evaluation Error: Error while evaluating a Function Call, Failed to parse template hazelcast/hazelcast.startup.sh.erb:
         Filepath: modules/hazelcast/spec/fixtures/modules/hazelcast/templates/hazelcast.startup.sh.erb
         Line: 6
         Detail: no implicit conversion of String into Integer

模板第 6 行:

EXTRA_CLASSPATH=<% scope['hazelcast::extra_libraries'].each do |extra_library| %>:$LIBS_DIR/<%= extra_library['file'] %><% end %>

规格测试:

require 'spec_helper'
describe 'hazelcast' do

  # Some general facts to assume we're running on Linux
  let :facts do {
    id:                     'root',
    kernel:                 'Linux',
    osfamily:               'RedHat',
    operatingsystem:        'RedHat',
    operatingsystemrelease: '7' }
  end

  context 'with defaults for all parameters' do
    it { expect { is_expected.to contain_class('hazelcast') }.to raise_error(Puppet::Error) }
  end

  required_params = {
    extra_libraries: {'url' => 'bla', 'file' => 'bla'},
    servers: ['1','2'],
  }

  context 'with defaults for all parameters' do
    let(:params) { required_params }
    it { is_expected.to contain_class('hazelcast') }
  end

end       

你的迭代器并没有按照你的想法去做。

你可以

scope['hazelcast::extra_libraries'].each_key do |extra_library|

或者(我假设这是你的问题)你实际上需要传递一个哈希数组。

extra_libraries: [ {'url' => 'bla', 'file' => 'bla'} ],