1

我有以下带有 file_line 资源的清单

class login {

  if $::operatingsystemmajrelease < 7 {

    file {'/etc/loginfile':
      ensure => present,
    }

    file_line { 'testfile':
      path   => '/etc/loginfile',
      line   => 'abc 022',
      match  => '^abc.*$',
    }
  }
}

下面是rspec文件

require 'spec_helper'

describe 'login' do

  it { should contain_class('login')}

  let(:facts) {{:operatingsystemmajrelease => 6}}

  if (6 < 7)
    it { should contain_file('/etc/loginfile').with_ensure('present')}

    it { should contain_file_line('testfile').with(
      :path   => '/etc/loginfile',
      :line   => 'abc 022',
      :match  => '^abc.*$'
    )}
  end
end

当我运行 rake-spec 命令时出现以下错误

 login
     Failure/Error: it { should contain_class('login')}
     Puppet::Error:
       Puppet::Parser::AST::Resource failed with error ArgumentError: Invalid resource type file_line at /etc/puppetlabs/modulename/login/spec/fixtures/modules/login_defs/manifests/init.pp:17 on node 
     # ./spec/classes/login_spec.rb:5

rspec 将不支持 file_line resporce?

因为如果我删除“file_line”资源并运行 rsepc 文件它的工作

4

1 回答 1

1

file_line 位于 puppetlabs-stdlib 中,因此您需要将其包含到您的测试夹具中。

最简单的方法是在 .fixtures.yml 中:

fixtures:
  repositories:
    stdlib: "git://github.com/puppetlabs/puppetlabs-stdlib"
于 2016-06-21T21:06:31.990 回答