0

My recipe installs the dynatrace module and enables it:

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

My spec file contains the following:

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

When I run Rspec it fails with the following error:

$ 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

Need some help in identifying the issue causing my spec failure.

Carlos Villalba
  • 799
  • 5
  • 7
LenG
  • 61
  • 1
  • 4

1 Answers1

0

From your description, the issue isn't it failing due to untouched resources.

Your chefspec run has failed as no resource in the chef run creates the file /opt/dynatrace/agent/lib64/libdtagent.so

From the looks of https://github.com/Dynatrace/Dynatrace-Chef/blob/master/recipes/wsagent_package.rb , the recipe being included might create that file via the extraction of an archive/tar. As this is a side effect, it can't be directly tested using unit tests.

It seems you are writing a wrapper cookbook to glue two pieces of functionality together.

A tool such as test kitchen with serverspec might be better suited to the integration test you are writing.

jedifans
  • 2,287
  • 1
  • 13
  • 9