简体   繁体   English

使用rspec进行Puppet Code覆盖测试

[英]Puppet Code coverage testing using rspec

My Module structure is this. 我的模块结构是这样的。

install_logging
├── files
│   └── install_logging.sh
├── Gemfile
├── Gemfile.lock
├── manifests
│   ├── \
│   ├── empty.rb
│   └── init.pp
├── Modulefile
├── Rakefile
├── README
├── spec
│   ├── chkcls_sec.rb
│   ├── classes
│   │   ├── init1_spec.rb
│   │   ├── init_spec.rb
│   │   └── spec_helper.rb
│   ├── coverage_spec.rb
│   ├── defines
│   ├── fixtures
│   │   ├── manifests
│   │   │   └── site.pp
│   │   └── modules
│   │       └── install_logging
│   │           ├── files -> ../../../../files
│   │           ├── manifests -> ../../../../manifests
│   │           └── templates -> ../../../../templates
│   ├── functions
│   ├── hosts
│   └── spec_helper.rb
├── templates
│   └── agent.sh.erb
└── tests
    └── init.pp

manifests/init.pp file code. manifest / init.pp文件代码。

class install_logging {
  file { '/tmp/install_logging.sh':
    ensure => 'present',
    mode   => '0644',
    source => 'puppet:///modules/install_logging/install_logging.sh'
  }-> exec { 'Install Logging Agent':
    provider  => shell,
    command   => 'bash /tmp/install_logging.sh',
    logoutput => on_failure,
  }
}

$ua_module_name = 'VivekMishra01/Google_Cloud_Logging1'  
$ua_module_version = "${ua_module_name}/1.1.0" 

file { '/tmp/agent.sh':
  ensure  => file,
  mode    => '0755',
  content => template('gcloudsdk/agent.sh.erb'),
  require => Exec['Remove Components'],
}-> exec { 'Agent':
  provider  => shell,
  command   => 'sh /tmp/agent.sh',
  logoutput => on_failure,
}

spec/classes/init_spec.rb file code spec / classes / init_spec.rb文件代码

require 'spec_helper'
describe 'contains install_logging' do
  it { File.exist?('File.join(File.dirname(__FILE__),init.pp)') }
end
at_exit { RSpec::Puppet::Coverage.report! }

This is what I am trying to do. 这就是我想要做的。

root@ubuntu-14-04:/home/vivekkumarmishra17/Mymodule/install_logging# rspec spec/classes/init_spec.rb 
.
Finished in 0.00164 seconds (files took 0.59198 seconds to load)

    1 example, 0 failures
    Total resources:   0
    Touched resources: 0
    Resource coverage:   NaN%
    Untouched resources:

Problem is that why it's not able to find any resource although 1 example is tested successfully. 问题是,虽然成功测试了一个示例,但为什么它无法找到任何资源。

    Total resources:   0
    Touched resources: 0
    Resource coverage:   NaN%
    Untouched resources:

Any help will be highly appreciated. 任何帮助将受到高度赞赏。 Thanks. 谢谢。

Please use the Puppet Development Kit to generate your modules and classes. 请使用Puppet Development Kit生成您的模块和类。 The PDK will generate working unit tests for those. PDK将为这些人生成工作单元测试。

For writing unit tests using rspec-puppet, please refer to the docsite , in this case, specifically to testing classes , and resources . 对于使用rspec-puppet编写单元测试,请参考docsite ,在本例中,特别是测试类资源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM