Obstacle Driven Development: Extending Test Driven Development
Test Driven Development with Puppet
-
Upload
puppet-labs -
Category
Technology
-
view
1.337 -
download
0
description
Transcript of Test Driven Development with Puppet
![Page 1: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/1.jpg)
Test Driven Development!for Puppet!Puppet needs software developmentGareth Rushgrove
![Page 2: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/2.jpg)
Who (Who is this person?)
![Page 3: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/3.jpg)
@garethr
![Page 4: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/4.jpg)
UK Government Digital Service
![Page 5: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/5.jpg)
![Page 6: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/6.jpg)
![Page 7: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/7.jpg)
![Page 8: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/8.jpg)
The problem (This isn’t a rant, but…)
![Page 9: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/9.jpg)
Who here is a software developer?
Gareth Rushgrove
![Page 10: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/10.jpg)
If you’re writing Puppet code you’re a software developer
Gareth Rushgrove
![Page 11: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/11.jpg)
As a software developer it’s your job to learn software engineering practices
Gareth Rushgrove
![Page 12: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/12.jpg)
What is Test Driven Development
(And why should you care)
![Page 13: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/13.jpg)
A common practice in software engineering
Gareth Rushgrove
![Page 14: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/14.jpg)
Not just testing
Gareth Rushgrove
![Page 15: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/15.jpg)
Encourages simple designs and inspires confidence
Gareth Rushgrove
![Page 16: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/16.jpg)
First write an (initially failing) automated test case
Gareth Rushgrove
![Page 17: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/17.jpg)
Then produce the minimum amount of code to pass that test
Gareth Rushgrove
![Page 18: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/18.jpg)
And finally refactor the new code to acceptable standards
Gareth Rushgrove
![Page 19: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/19.jpg)
Test Driven Design
Gareth Rushgrove
![Page 20: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/20.jpg)
Gareth Rushgrove
![Page 21: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/21.jpg)
Unit testing with RSpec and Guard (Not puppet specific)
![Page 22: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/22.jpg)
A unit is the smallest testable part of an application
Gareth Rushgrove
![Page 23: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/23.jpg)
Testing puppet requires a little Ruby knowledge so we’ll use Ruby examples
Gareth Rushgrove
![Page 24: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/24.jpg)
class Person def say(word) end end
Gareth Rushgrove
![Page 25: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/25.jpg)
First lets write a test. For this we use the RSpec testing framework
Gareth Rushgrove
![Page 26: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/26.jpg)
require 'person' !describe Person, "#say" do it "should say something" do ! end end
Gareth Rushgrove
![Page 27: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/27.jpg)
require 'person' !describe Person, "#say" do it "should say something" do bob = Person.new bob.say("hello").should \ eq("hello everyone") end end
Gareth Rushgrove
![Page 28: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/28.jpg)
Now lets run our test. It should fail
Gareth Rushgrove
![Page 29: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/29.jpg)
rspec
Gareth Rushgrove
![Page 30: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/30.jpg)
Failures: 1) Person#say should say something Failure/Error: bob.say("hello").should eq("hello everyone") expected: "hello everyone" got: nil Finished in 0.00171 seconds 1 example, 1 failure
Gareth Rushgrove
![Page 31: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/31.jpg)
Now lets write the implementation
Gareth Rushgrove
![Page 32: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/32.jpg)
class Person def say(word) word + " everyone" end end
Gareth Rushgrove
![Page 33: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/33.jpg)
And run our test again
Gareth Rushgrove
![Page 34: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/34.jpg)
Person#say should say something !Finished in 0.00199 seconds 1 example, 0 failures
Gareth Rushgrove
![Page 35: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/35.jpg)
Why not have tests automatically run whenever you change the code?
Gareth Rushgrove
![Page 36: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/36.jpg)
That’s what Guard does
Gareth Rushgrove
![Page 37: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/37.jpg)
guard :rspec, cmd: 'bundle exec rspec' do watch(%r{^spec/.+_spec\.rb$}) watch(%r{^lib/.+\.rb$}) { 'spec' } end
Gareth Rushgrove
![Page 38: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/38.jpg)
guard
Gareth Rushgrove
![Page 39: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/39.jpg)
Lets see a quick demo
Gareth Rushgrove
![Page 40: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/40.jpg)
Why test puppet code at all
(Testing declarative languages)
![Page 41: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/41.jpg)
Modules increasingly contain logic
Gareth Rushgrove
![Page 42: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/42.jpg)
Modules increasingly take arguments
Gareth Rushgrove
![Page 43: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/43.jpg)
Modules increasingly have interfaces with other modules
Gareth Rushgrove
![Page 44: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/44.jpg)
Modules increasingly used in many operating system and version combinations
Gareth Rushgrove
![Page 45: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/45.jpg)
Modules increasingly used in many Ruby and Puppet version combinations
Gareth Rushgrove
![Page 46: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/46.jpg)
Unit testing puppet with
rspec-puppet (Finally some puppet code)
![Page 47: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/47.jpg)
Unit testing for Puppet
![Page 48: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/48.jpg)
A very simple puppet class
Gareth Rushgrove
![Page 49: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/49.jpg)
class sample { }
Gareth Rushgrove
![Page 50: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/50.jpg)
First write the test
Gareth Rushgrove
![Page 51: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/51.jpg)
require 'spec_helper' !describe "sample" do it { should create_file('/tmp/sample')} end
Gareth Rushgrove
![Page 52: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/52.jpg)
Then run the test
Gareth Rushgrove
![Page 53: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/53.jpg)
sample should contain File[/tmp/sample] (FAILED - 1) !Finished in 0.4584 seconds 1 example, 1 failure
Gareth Rushgrove
![Page 54: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/54.jpg)
And then write the (puppet) code to make the test pass
Gareth Rushgrove
![Page 55: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/55.jpg)
class sample { file { "/tmp/sample": ensure => present, } }
Gareth Rushgrove
![Page 56: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/56.jpg)
sample should contain File[/tmp/sample] !Finished in 0.3881 seconds 1 example, 0 failures
Gareth Rushgrove
![Page 57: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/57.jpg)
Lets run the tests automatically whenever you change anything
Gareth Rushgrove
![Page 58: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/58.jpg)
guard :rspec, cmd: 'bundle exec rspec' do watch(%r{^spec/.+_spec\.rb$}) watch(%r{^manifests/.+\.pp$}) { 'spec' } end
Gareth Rushgrove
![Page 59: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/59.jpg)
Lets see a quick demo of that too
Gareth Rushgrove
![Page 60: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/60.jpg)
You can also test hosts, defines, facts, functions, hieradata
Gareth Rushgrove
![Page 61: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/61.jpg)
Syntax checking, linting, oh my (Creating a build process)
![Page 62: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/62.jpg)
puppet-lint
Gareth Rushgrove
![Page 63: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/63.jpg)
Puppet!style guide
![Page 64: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/64.jpg)
Available!as a gem
![Page 65: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/65.jpg)
puppet-lint --with-filename /etc/puppet/modules foo/manifests/bar.pp: trailing whitespace found on line 1 apache/manifests/server.pp: variable not enclosed in {} on line 56
Gareth Rushgrove
![Page 66: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/66.jpg)
puppet-syntax
Gareth Rushgrove
![Page 67: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/67.jpg)
Validate Puppet and ERB syntax
![Page 68: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/68.jpg)
require 'puppet-syntax/tasks/puppet-syntax'
Gareth Rushgrove
![Page 69: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/69.jpg)
rake syntax ---> syntax:manifests ---> syntax:templates ---> syntax:hiera:yaml
Gareth Rushgrove
![Page 70: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/70.jpg)
What is Rake and why do we use it
(Still no puppet)
![Page 71: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/71.jpg)
Rake is a Ruby!build tool
Gareth Rushgrove
![Page 72: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/72.jpg)
It’s like Make but in Ruby
Gareth Rushgrove
![Page 73: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/73.jpg)
It’s very easy to distribute Rake tasks as Ruby gems
Gareth Rushgrove
![Page 74: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/74.jpg)
rake
Gareth Rushgrove
![Page 75: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/75.jpg)
rake <command>
Gareth Rushgrove
![Page 76: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/76.jpg)
rake -T
Gareth Rushgrove
![Page 77: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/77.jpg)
Lets make a command to run lint, syntax and spec
Gareth Rushgrove
![Page 78: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/78.jpg)
task :test => [ :syntax, :lint, :spec, ]
Gareth Rushgrove
![Page 79: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/79.jpg)
rake test
Gareth Rushgrove
![Page 80: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/80.jpg)
Acceptance testing with
beaker (Living on the edge)
![Page 81: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/81.jpg)
Acceptance test against real systems
Gareth Rushgrove
![Page 82: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/82.jpg)
Test what actually happens, not what is meant to happen
Gareth Rushgrove
![Page 83: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/83.jpg)
Build by
Gareth Rushgrove
![Page 84: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/84.jpg)
Very new
Gareth Rushgrove
![Page 85: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/85.jpg)
Test against different operating systems
Gareth Rushgrove
![Page 86: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/86.jpg)
HOSTS: ubuntu-server-12042-x64: roles: - master platform: ubuntu-server-12.04-amd64 box: ubuntu-server-12042-x64-vbox4210-nocm box_url: http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042-x64-vbox4210-nocm.box hypervisor: vagrant !CONFIG: log_level: verbose type: foss
Gareth Rushgrove
![Page 87: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/87.jpg)
HOSTS: centos-64-x64: roles: - master platform: el-6-x86_64 box : centos-64-x64-vbox4210-nocm box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box hypervisor : vagrant !CONFIG: log_level: verbose type: foss
Gareth Rushgrove
![Page 88: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/88.jpg)
Supports multiple hypervisors
Gareth Rushgrove
![Page 89: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/89.jpg)
Vagrant hypervisor
![Page 90: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/90.jpg)
VSphere hypervisor
![Page 91: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/91.jpg)
Helpers to install puppet and modules
Gareth Rushgrove
![Page 92: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/92.jpg)
install_puppet
Gareth Rushgrove
![Page 93: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/93.jpg)
puppet('module', 'install', 'puppetlabs-stdlib')
Gareth Rushgrove
![Page 94: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/94.jpg)
Test that Puppet runs without errors
Gareth Rushgrove
![Page 95: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/95.jpg)
context 'default parameters' do it 'should work with no errors' do pp = “class { 'sample': }” ! expect(apply_manifest(pp).exit_code).to_not eq(1) end end
Gareth Rushgrove
![Page 96: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/96.jpg)
Test runs are idempotent
Gareth Rushgrove
![Page 97: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/97.jpg)
context 'default parameters' do it 'should work with no errors' do pp = “class { 'sample': }” ! expect(apply_manifest(pp).exit_code).to_not eq(1) expect(apply_manifest(pp).exit_code).to eq(0) end end
Gareth Rushgrove
![Page 98: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/98.jpg)
Test that the module installs packages, run services, etc.
Gareth Rushgrove
![Page 99: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/99.jpg)
Gareth Rushgrove
![Page 100: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/100.jpg)
describe package('nginx') do it { should be_installed } end !describe service('nginx') do it { should be_enabled } it { should be_running } end !describe port(80) do it { should be_listening} end
Gareth Rushgrove
![Page 101: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/101.jpg)
Other useful tools (and what we’re still missing)
![Page 102: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/102.jpg)
Fixtures, matchers
![Page 103: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/103.jpg)
Gareth Rushgrove
![Page 104: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/104.jpg)
Nice continuous integration
![Page 105: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/105.jpg)
![Page 106: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/106.jpg)
Test pull request branches too
![Page 107: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/107.jpg)
--- language: ruby bundler_args: --without development before_install: rm Gemfile.lock || true rvm: - 1.8.7 - 1.9.3 - 2.0.0 script: bundle exec rake test env: - PUPPET_VERSION="~> 2.7.0" - PUPPET_VERSION="~> 3.1.0" - PUPPET_VERSION="~> 3.2.0" - PUPPET_VERSION="~> 3.3.0" - PUPPET_VERSION="~> 3.4.0"
Gareth Rushgrove
![Page 108: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/108.jpg)
Official!ruby support
![Page 109: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/109.jpg)
matrix: exclude: - rvm: 2.0.0 env: PUPPET_VERSION="~> 2.7.0" - rvm: 2.0.0 env: PUPPET_VERSION="~> 3.1.0" - rvm: 1.9.3 env: PUPPET_VERSION="~> 2.7.0"
Gareth Rushgrove
![Page 110: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/110.jpg)
Experimental code coverage support in rspec-puppet master
Gareth Rushgrove
![Page 111: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/111.jpg)
at_exit { RSpec::Puppet::Coverage.report! }
Gareth Rushgrove
![Page 112: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/112.jpg)
Total resources: 24 Touched resources: 8 Resource coverage: 33.33% !Untouched resources: Class[Nginx] File[preferences.d] Anchor[apt::update] Class[Apt::Params] File[sources.list] Exec[Required packages: 'debian-keyring debian-archive-keyring' for nginx] Anchor[apt::source::nginx] Class[Apt::Update] File[configure-apt-proxy] Apt::Key[Add key: 7BD9BF62 from Apt::Source nginx] Anchor[apt::key/Add key: 7BD9BF62 from Apt::Source nginx] Anchor[apt::key 7BD9BF62 present] File[nginx.list] Exec[apt_update]
Gareth Rushgrove
![Page 113: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/113.jpg)
A puppet module skeleton with everything working out of the box
Gareth Rushgrove
![Page 114: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/114.jpg)
puppet module skeleton
![Page 115: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/115.jpg)
puppet module generate sample
Gareth Rushgrove
![Page 116: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/116.jpg)
A pretty complete example
(The Docker module)
![Page 117: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/117.jpg)
Gareth Rushgrove
![Page 118: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/118.jpg)
Gareth Rushgrove
Featured on the Forge
![Page 119: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/119.jpg)
Gareth Rushgrove
50 pull request and counting
![Page 120: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/120.jpg)
Gareth Rushgrove
Contributing guidelines
![Page 121: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/121.jpg)
Gareth Rushgrove
![Page 122: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/122.jpg)
Gareth Rushgrove
Currently has 121 tests
![Page 123: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/123.jpg)
6 classes, 2 defines, 413 lines of puppet code, 387 lines of test code
Gareth Rushgrove
![Page 124: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/124.jpg)
Take away (If all you remember is…)
![Page 125: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/125.jpg)
Infrastructure as code
Gareth Rushgrove
![Page 126: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/126.jpg)
The first test is the hardest
Gareth Rushgrove
![Page 127: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/127.jpg)
Politely demand tests for contributions
Gareth Rushgrove
![Page 128: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/128.jpg)
Test the interface not the implementation
Gareth Rushgrove
![Page 129: Test Driven Development with Puppet](https://reader031.fdocuments.in/reader031/viewer/2022020306/554f5f4eb4c9058a148b4668/html5/thumbnails/129.jpg)
Questions? (And thanks for listening)