Ask Your Question
0

name attribute doesn't in rspec-puppet

asked 2017-01-03 06:39:17 -0500

Chutki gravatar image

updated 2017-01-04 03:11:59 -0500

Hi,

I have below manifests,

file {'module_name' :
    ensure => present,
    name   => '/etc/init.d/module_name',
    owner  => 'root',
    group  => 'root',
    mode   => '0755',
    source => 'puppet:///modules/test/module_name',
}

Below is the rspec-puppet test case, when I run the test case getting error

    it { should contain_file('module_name').with(
             'ensure' => 'present',
             'name'   => '/etc/init.d/module_name',
             'owner'  => 'root',
             'group'  => 'root',
             'mode'   => '0755',
             'source' => 'puppet:///modules/test/module_name',
)}

Error Message:

expected that the catalogue would contain File[module_name] with name set to "/etc/init.d/module_name" but it is set to nil

when I make 'name' => nilchange then my test case did pass.

============================================================== Second update, test.json

{
      "type": "File",
      "title": "module_name",
      "tags": ["file","module_name","class","module_name","module_name"],
      "file": "/root/modules_test/test/spec/fixtures/modules/test/manifests/test.pp",
      "line": 6,
      "exported": false,
      "parameters": {
        "path": "/etc/init.d/module_name",
        "ensure": "present",
        "owner": "root",
        "group": "root",
        "mode": "0755",
        "source": "puppet:///modules/oracle/module_name"
      }
edit retag flag offensive close merge delete

Comments

I think that methods like 'contain_file' reference the title, not the name.

DarylW gravatar imageDarylW ( 2017-01-03 08:53:04 -0500 )edit

You also can put some debug in your rspec tests that print out the (pson) catalog for you to inspect what is actually present. (https://ask.puppet.com/question/24628/verify_contents-catalog-error-in-rspec-puppet/) note that you have to reference the `catalogue` object in your test

DarylW gravatar imageDarylW ( 2017-01-03 09:07:10 -0500 )edit

require 'spec_helper' describe 'module_name' do it { File.write( 'module_name.json', PSON.pretty_generate(catalogue) )}end # via https://ask.puppet.com/question/25590/is-it-possible-to-clear-catalog-cache-in-rspec-puppet/

DarylW gravatar imageDarylW ( 2017-01-03 09:15:10 -0500 )edit

http://razorconsulting.com.au/dumping-the-catalog-in-rspec-puppet.html

DarylW gravatar imageDarylW ( 2017-01-03 09:46:06 -0500 )edit

Hi, you can find the second update of json file in question box, I separated by "========". As you mentioned, I don't find attribute for "name" there. If 'content_file' refer the title as file name, then why we use "name" attribute in 'file' resource.

Chutki gravatar imageChutki ( 2017-01-04 03:18:07 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-10-02 05:01:14 -0500

David Schmitt gravatar image

The attribute is called path, not name: https://docs.puppet.com/puppet/latest... .

Do you have a it { is_expected.to compile.with_all_deps } test in your spec file? It should catch errors like this.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-01-03 06:39:17 -0500

Seen: 186 times

Last updated: Oct 02