- Mastering Puppet 5
- Ryan Russell Yates Jason Southgate
- 309字
- 2021-07-16 17:46:08
Unit testing your module
The number one most important thing you can do to bring quality to your modules is to test them! Testing really is one of the most important aspects of software quality assurance in any field of software development. In the agile development community, we've been banging on the table about automated testing for more than 10 years!
Puppet RSpec (http://rspec-puppet.com/tutorial) has been allowing the Puppet community to unit test their modules for quite some time, but it's even easier now with the new PDK 1.0, as everything is set up ready, and you can just add your testing code and run the tests.
From a Puppet perspective, unit testing means checking the output from the compiler. Are the resources contained in the compiled relationship resource catalog, and is their order as expected, given the parameters passed and/or facts present?
When you begin to write tests in Puppet-RSpec, it seems at first like all you are doing is rewriting the Puppet manifests in another Ruby-like language. There is, however, really more to it than that. If there is some reasonable complexity to the module's functionality, for example, testing the dynamic content produced by Puppet templates, support for multiple operating systems, and different actions according to the passed parameters, then these tests actually form a safety net when editing or adding new functionality to your modules, protecting against regressions when refactoring, or upgrading to a new Puppet release.
Let's carry on from the previous two sections and use the development kit to unit test our module. Whenever you generate a class using the pdk new class command, PDK creates a corresponding unit test file. This file, located in your module's /spec/classes folder, already includes a template for writing your unit tests (see http://rspec-puppet.com/tutorial). You can then run the tests using the following command:
$ pdk test unit
- 通信工程辦公實務(wù)
- 分布式系統(tǒng)常用技術(shù)及案例分析(第2版)
- 西門子SINAMICS G120/S120變頻器技術(shù)與應(yīng)用
- 元器件易學通:常用元件分冊
- BBC監(jiān)聽音箱完全指南
- 路由與交換技術(shù)
- 教你檢修液晶顯示器
- Altium Designer 21常見問題解答500例
- Rust Standard Library Cookbook
- TFT-LCD原理與設(shè)計
- 天線測量實用手冊(第2版)
- 電子技能與實訓(xùn)項目教程
- 5G無線增強設(shè)計與國際標準
- 電子產(chǎn)品調(diào)試技能演練
- Android應(yīng)用開發(fā)從入門到精通