The pdk test unit command

New manifests built with pdk new class are also provided with a default RSpec test. Unit tests are written to ensure that a manifest performs what is expected as it is running. The default unit test provided by Puppet ensures that the code compiles successfully on every operating system listed in the metadata.json, with default facts for those operating systems. This can be expanded to create more robust unit tests. In the following example, a check has been added that states that the init.pp of the module should provide a file called /etc/example that is not provided by the manifest:

$ pdk test unit
pdk (INFO): Using Ruby 2.4.4
pdk (INFO): Using Puppet 5.5.1
[] Preparing to run the unit tests.
[] Running unit tests.
Evaluated 45 tests in 2.461011 seconds: 9 failures, 0 pending.
[] Cleaning up after running unit tests.
failed: rspec: ./spec/classes/module_spec.rb:9: expected that the catalogue would contain File[test]
module on centos-7-x86_64 should contain File[test]
Failure/Error:

it { is_expected.to compile }
it { is_expected.to contain_file('/etc/example') }
end
end

The simple test provided by the default PDK only provides it { is_expected.to compile } as an RSpec test for each module. In the next chapter, we'll expand upon our initial RSpec module, as we cover unit tests and provide some basic code coverage testing to our Puppet modules.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.22.23