3
我的模塊結構是這樣的。使用rspec的木偶代碼覆蓋測試
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
manifeststs/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,
}
規格/班/ 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! }
這就是我要做的。
[email protected]:/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:
任何幫助將不勝感激。謝謝。
歡迎來到SO。請檢查您的問題並修改格式,以便更易讀。您的代碼中有註釋,並且沒有格式化的命令行輸出;您爲使問題可讀而付出的努力是值得的。而且,給我們必要的信息可以幫助我們幫助你。閱讀「[問]」,包括鏈接和「[mcve]」。 –