ruby - 使用 rspec 进行 Puppet 代码覆盖率测试

标签 ruby code-coverage rspec-puppet

我的模块结构是这样的。

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文件代码。

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 文件代码

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! }

这就是我想要做的。

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:

问题是为什么它无法找到任何资源,尽管 1 个示例已成功测试。

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

任何帮助将不胜感激。谢谢。

最佳答案

请使用Puppet Development Kit生成你的模块和类。 PDK 将为这些生成工作单元测试。

使用 rspec-puppet 编写单元测试,请引用 docsite ,在这种情况下,特别是 testing classes , 和 resources .

关于ruby - 使用 rspec 进行 Puppet 代码覆盖率测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37465107/

相关文章:

arrays - 将数组中的每个单词大写

Ruby:文件中的数据仅在程序终止后写入/保存/可见

c# - 为什么这个字符串属性在不应该被覆盖的情况下显示为被完全覆盖?

go - -coverprofile 从覆盖百分比中排除未测试的文件

rspec - 你能覆盖 rspec-puppet 中的参数化类变量吗?

mysql - 在 Ruby 和 Rails 中使用计算

ruby - 我如何从控制台要求 Rails 目录中的库?

java - 确定哪些测试用例覆盖了一个方法

windows - 编写 puppet 配置以克隆 github repo

testing - Puppet:rake spec 找不到 class::splunk