Ask Your Question

Any one have idea how to check entire file in serverspec for puppet testing

asked 2015-12-17 23:07:17 -0600

Chutki gravatar image


I know if we need to check the content of a file we use the below should match /^ test $/ in serverspec. But how can we check the entire file content is copied to the destination file.


source => 'puppet:///modules/test/test.conf'

Below is the config file content

  size 30k
   create 755 root root

The file contains 5 lines, there are files which has more than 50 lines. In that case, how can we do end to end testing in serverspec.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2015-12-17 23:49:42 -0600

You could do something like:

expected_content ='files/test.conf')

describe file('/path/to/test.conf') do
  its(:content) { should eq expected_content }
edit flag offensive delete link more


Thanks for your response. If its template, then how can we test the content, because sometimes we use "CN=<%= @fqdn %>" facts for puppet in test.erb file. Then how it's possible to test the entire content in serverspec.

Chutki gravatar imageChutki ( 2015-12-18 02:54:20 -0600 )edit

What I should refer to hone my skills in serverspec. Do I need to have good knowledge in ruby. Pls help me.

Chutki gravatar imageChutki ( 2015-12-18 02:59:03 -0600 )edit

This isn't really the right forum for engaging in extended discussion about all this unfortunately. The purpose of testing isn't usually to check every byte in a file. I recommend learning by trying to understand the tests in the Puppet Labs supported modules. But beware, they use Beaker! :)

Alex Harvey gravatar imageAlex Harvey ( 2015-12-18 03:42:46 -0600 )edit

To answer your first question, you could write something in Ruby to deduce expected content based on facts + and ERB template. But if you really need to do that, it's really time to look at Beaker I think, rather than trying to do all this in pure Serverspec.

Alex Harvey gravatar imageAlex Harvey ( 2015-12-18 03:44:27 -0600 )edit

answered 2015-12-18 12:51:51 -0600

lavaman gravatar image

First, there's no good reason to test whether puppet is serving static files correctly or not. You'll find out really quick if that's an issue :)

Second, for templates, you don't need to check the entire contents of the file, just the part that is templated to ensure interpolation/iteration is correct.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2015-12-17 23:07:17 -0600

Seen: 1,003 times

Last updated: Dec 18 '15