0

我的食谱安装了 dynatrace 模块并启用它:

include_recipe 'dynatrace::wsagent_package'

apache2_module 'dtagent_module' do
  module_name 'dtagent_module'
  filepath node['dynatrace']['apache_wsagent']['linux']['agent_path']
  action [:enable]
end

我的规范文件包含以下内容:

  it 'creates /opt/dynatrace/agent/lib64/libdtagent.so file' do
    expect(chef_run).to render_file('/opt/dynatrace/agent/lib64/libdtagent.so')
  end

当我运行 Rspec 它失败并出现以下错误:

$ rspec -f d ./spec/unit/recipes/apache_spec.rb[1:4]

Run options: `include {:ids=>{"./spec/unit/recipes/apache_spec.rb"=>["1:4"]}}`

dynatrace::apache
  creates /opt/dynatrace/agent/lib64/libdtagent.so file (FAILED - 1)

Failures:

  1) dynatrace::apache creates /opt/dynatrace/agent/lib64/libdtagent.so file
     Failure/Error: expect(chef_run).to render_file('/opt/dynatrace/agent/lib64/libdtagent.so')
       expected Chef run to render "/opt/dynatrace/agent/lib64/libdtagent.so"
     # ./spec/unit/recipes/apache_spec.rb:35:in `block (2 levels) in <top (required)>'

Finished in 1.13 seconds (files took 8.93 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/unit/recipes/apache_spec.rb:34 # dynatrace::apache creates /opt/dynatrace/agent/lib64/libdtagent.so file


ChefSpec Coverage report generated...

  Total Resources:   1
  Touched Resources: 0
  Touch Coverage:    0.0%

Untouched Resources:

  apache2_module[dtagent_module]     dynatrace/recipes/apache.rb:12


ChefSpec Coverage report generated...

  Total Resources:   1
  Touched Resources: 0
  Touch Coverage:    0.0%

Untouched Resources:

  apache2_module[dtagent_module]     dynatrace/recipes/apache.rb:12

需要一些帮助来确定导致我的规范失败的问题。

4

1 回答 1

0

根据您的描述,问题不是由于未触及资源而导致失败。

您的 chefspec 运行失败,因为 chef 运行中没有资源创建文件/opt/dynatrace/agent/lib64/libdtagent.so

https://github.com/Dynatrace/Dynatrace-Chef/blob/master/recipes/wsagent_package.rb的外观来看,包含的配方可能会通过提取档案/tar 来创建该文件。由于这是副作用,因此无法使用单元测试直接对其进行测试。

看来您正在编写一个包装食谱以将两个功能粘合在一起。

诸如带有 serverspec 的测试厨房之类的工具可能更适合您正在编写的集成测试。

于 2016-08-12T19:07:02.733 回答