0

I am trying to write some tests for a chef Nginx cookbook. I have come to a block. I need to write a test for the code below. I can test for the core_lock released. I am unsure how to test for the make install as well as ./autogen.sh and ./configure --enable-standalone-module

The docs have not been too helpful since this is a bash command the docs are a bit sparse.

Code need test for

bash 'compile_modsecurity' do
  cwd modsec_compile_path
  code <<-EOH
    ./autogen.sh
    ./configure --enable-standalone-module
    make
    make install
  EOH
  action :nothing
  notifies :run, 'bash[release_core_nginx_lock]', :immediately
end

1 Answers1

1

You would write an InSpec test block that uses a command resource to try and actually run nginx. Usually you do this with something like --version and then confirm that it looks correct. You can then try starting the service and use an http_request resource to connect to it on localhost and get some content.

coderanger
  • 52,400
  • 4
  • 52
  • 75
  • Wow thanks, you solved a few issues for me without knowing. The `http_request` was something I just started looking into. –  May 08 '18 at 17:53
  • I tried to check for the nginx version how you said but I am not seeing Nginx in my system at all but a `service` check shows it is enabled and running but nothing else shows it as there. Is it possible to be getting a false positive on the enabled and running check? –  May 08 '18 at 20:37
  • Don't bother checking services, what matters is the HTTP GET. That either works or it doesn't. – coderanger May 08 '18 at 22:04
  • Okay, why would it show up as there with a service check but not with a get request request. –  May 09 '18 at 12:35
  • Because your recipe is broken? – coderanger May 09 '18 at 16:27
  • Far as I know it works in production. When I asked the coworker who wrote it they said likely because it runs as part of a runlist. –  May 09 '18 at 16:42
  • I don’t understand but this is now well outside the scope of SO comments. Jump on slack if you need more open ended help :) – coderanger May 09 '18 at 17:38