TDD - TEST KITCHEN

CHAPTER 5

TESt APP Vs TEST cookbook

Test in COOKBOOK

Test in APP

.
`-- myapp
    |-- README.md
    |-- cookbooks
    |   `-- myapp
    |       |-- Berksfile
    |       |-- chefignore
    |       |-- metadata.rb
    |       |-- recipes
    |       |   `-- default.rb
    |       `-- spec
    |           |-- spec_helper.rb
    |           `-- unit
    |               `-- recipes
    |                   `-- default_spec.rb
    `-- test
        `-- recipes
            `-- default_test.rb
.
`-- mycookbook
    |-- Berksfile
    |-- README.md
    |-- chefignore
    |-- metadata.rb
    |-- recipes
    |   `-- default.rb
    |-- spec
    |   |-- spec_helper.rb
    |   `-- unit
    |       `-- recipes
    |           `-- default_spec.rb
    `-- test
        `-- recipes
            `-- default_test.rb

inspec Vs serverspec

test user

Group exercise

unless os.windows?
  describe user('tomcat') do
    it { should exist }
  end
end

file: /workspace/myapp/test/recipes/default_test.rb

  • Add inspec user resource to check for tomcat user

test port

Group exercise

describe port(8080) do
  it { should be_listening }
  its('protocols') { should include 'tcp6' }
end

file: /workspace/myapp/test/recipes/default_test.rb

  • Add inspec port resource to verify listening of port 8080
  • Include protocols for tcp6

test service

Group exercise

describe service('tomcat') do
  it { should be_installed }
  it { should be_enabled }
  it { should be_running }
end

file: /workspace/myapp/test/recipes/default_test.rb

  • Add inspec service resource to verify tomcat service
  • Include installed, enabled and running conditions

kitchen verify

Group exercise

root@ws:/workspace/myapp# kitchen verify
-----> Starting Kitchen (v1.13.2)
-----> Setting up <default-centos-68>...
       Finished setting up <default-centos-68> (0m0.00s).
-----> Verifying <default-centos-68>...
       Using `/workspace/myapp/test/recipes/default` for testing

Target:  ssh://kitchen@localhost:32772


  User tomcat
     ✔  should exist
  Port 8080
     ✔  should be listening
     ✔  protocols should include "tcp6"
  Service tomcat
     ✔  should be installed
     ✔  should be enabled
     ✔  should be running

Test Summary: 6 successful, 0 failures, 0 skipped
       Finished verifying <default-centos-68> (0m0.53s).
-----> Kitchen is finished. (0m1.29s)
  • Use kitchen verify to change instance state to verify.
  • It runs automated tests on one or more instances

TDD Test Kitchen

By School of Devops

TDD Test Kitchen

CCI 05 - TDD with Test Kichen

  • 1,033