btm / minitest-handler-cookbook

Apache License 2.0
59 stars 36 forks source link

minitest-handler cookbook

Build Status

License: Apache 2.0
Copyright: 2012 Opscode, Inc.
Author: Bryan McLellan btm@loftninjas.org
Author: Bryan W. Berry bryan.berry@gmail.com

Description

This cookbook utilizes the minitest-chef-handler project to facilitate cookbook testing. By default, minitest-handler will collect all the tests in your cookbook_path and run them.

minitest-chef-handler project: https://github.com/calavera/minitest-chef-handler
stable minitest-handler cookbook: http://community.opscode.com/cookbooks/minitest-handler
minitest-handler cookbook development: https://github.com/btm/minitest-handler-cookbook

Note: Version 0.1.8 deprecated use of files/default/tests/minitest/*_test.rb and the location of support files. Test files should now be located in files/default/test/*_test.rb

Note: Version 0.1.0 added a change that breaks backward compatibility. The minitest-handler now only loads
test files named "_test.rb" rather than all test files in the path files/default/test/*_test.rb

If you have any helper libraries, they should match files/default/test/*helper*.rb

Attributes

Usage

Minitest

Examples

Traditional minitest

class TestApache2 < MiniTest::Chef::TestCase
  def test_that_the_package_installed
    case node[:platform]
    when "ubuntu","debian"
      assert system('apt-cache policy apache2 | grep Installed | grep -v none')
    end
  end

  def test_that_the_service_is_running
    assert system('/etc/init.d/apache2 status')
  end

  def test_that_the_service_is_enabled
    assert File.exists?(Dir.glob("/etc/rc5.d/S*apache2").first)
  end
end

Using minitest/spec

require 'minitest/spec'

describe_recipe 'ark::test' do

  it "installed the unzip package" do
    package("unzip").must_be_installed
  end

  it "dumps the correct files into place with correct owner and group" do
    file("/usr/local/foo_dump/foo1.txt").must_have(:owner, "foobarbaz").and(:group, "foobarbaz")
  end

 end

For more detailed examples, see here

Testing this cookbook

This cookbook currently uses test-kitchen along with the kitchen-vagrant.

All test are currently written using BATS, which is essentially bash. Using BATS was done so that minitest-handler nor minitest-chef-handler were used to test itself. For more examples of bats than are in this cookbook, see the chef-rvm, chef-ruby_build, and chef-rbenv cookbooks.

NOTE A known limitation of using BATS is that the cookbook is not currently tested on Windows machines. See https://github.com/btm/minitest-handler-cookbook/issues/45 for more of the background on this.

Releasing

This cookbook uses an 'even number' release strategy. The version number in master will always be an odd number indicating development, and an even number will be used when an official build is released.

Come release time here is the checklist:

Contributors