Now that we can write a test, we'll write one simple test that simply mirrors our manifest. This test will help us prevent regression, as changing an existing value or removing an existing resource will cause the test to fail. If this change is intended, the test must also be changed. Although this intuitively feels like it would slow down development, it saves even more time in integration when you can ensure that no new errors have been introduced.
Here is our RSpec test containing the mirror of our original profile:
require 'spec_helper' describe 'profile::jenkins' do on_supported_os.each do |os, os_facts| context "on #{os}" do systemd_fact = case os_facts[:operatingsystemmajrelease] when '6' { systemd: false } else { systemd: true } end let :facts do os_facts.merge(systemd_fact) end #### NEW CODE #### context 'With Defaults' do it do # Jenkins must be the LTS is_expected.to contain_class('jenkins').with('lts' => 'true') # We're unsure if we want latest git, but we want to make sure it's installed is_expected.to contain_package('git') # Download this particular version of the PDK is_expected.to contain_file('/tmp/pdk.rpm').with('ensure' => 'file', 'source' => 'https://puppet-pdk.s3.amazonaws.com/pdk/1.7.0.0/repos/el/7/puppet5/x86_64/pdk-1.7.0.0-1.el7.x86_64.rpm') # Install PDK from Disk. We'll change this test if we place this in a proper yumrepo one day # Also not that that_requires, and the lack of quotes within the File array is_expected.to contain_package('pdk').with('ensure' => 'installed', 'source' => '/tmp/pdk.rpm').that_requires('File[/tmp/pdk.rpm]') end end ### END NEW CODE ### it { is_expected.to compile } end end end
When we create a commit with this new test, and send it back up to Jenkins, we'll see our build actually perform this test. Up to this point, we've never intentionally broken a test. Let's go ahead and prove our test now. Comment out one resource in your original manifest, or change some configuration before sending this repository back to the remote server. After pushing this, you should be able to see a failed test in Jenkins! Simply uncomment out your resources and push a new commit up to your remote, and you'll see Jenkins pass this build. Once your build is passing, go ahead and merge into master so that we can continue onto our next section of integration testing.