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 リソースをサポートしませんか?

「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 に答える