minitest-chef-handler 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in minitest-chef-handler.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ == minitest-chef-handler
2
+
3
+ Copyright (c) 2012 David Calavera
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # Minitest Chef Handler
2
+
3
+ Run minitest suites after your Chef recipes to check the status of your system.
4
+
5
+ ## Motivation
6
+
7
+ Working at Engine Yard I have to maintain a quite complicated set of Chef recipes that we use to set up our customers' instances. I need to be sure that everytime someone modify those recipes, mostly myself, the provisioned services continue working as expected.
8
+
9
+ There are other solutions that evaluate the configured node after the recipes
10
+ are loaded without arriving to the converge phase, like [ChefSpec](https://github.com/acrmp/chefspec) or [rspec-chef](https://github.com/calavera/rspec-chef), but I needed something to write integration tests easily. I checked [chef-minitest](https://github.com/fujin/chef-minitest) but I'm still amazed by the ugly code that I have to write into the recipes to make it work.
11
+
12
+ ## Installation
13
+
14
+ ```
15
+ $ gem install minitest-chef-handler
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ 1. Add the report handler to your client.rb or solo.rb file:
21
+
22
+ ```ruby
23
+ require 'minitest-chef-handler'
24
+
25
+ report_handlers << MiniTest::Chef::Handler.new
26
+ ```
27
+
28
+ 2. Write your tests as normal MiniTest cases extending from MiniTest::Chef::TestCase:
29
+
30
+ ```ruby
31
+ class TestNginx < MiniTest::Chef::TestUnit
32
+ def test_config_file_exist
33
+ assert File.exist?('/etc/nginx.conf')
34
+ end
35
+ end
36
+ ```
37
+
38
+ You still have access to Chef's `run_status`, `node` and `run_context` from your tests:
39
+
40
+ ```ruby
41
+ class TestNginx < MiniTest::Chef::TestUnit
42
+ def test_config_file_exist
43
+ assert run_status.success?
44
+ end
45
+ end
46
+ ```
47
+
48
+ ## Further configuration
49
+
50
+ These are the options the handler accepts:
51
+
52
+ * :path => where your test files are, './test/test_*.rb' by default
53
+ * :filter => filter test names on pattern
54
+ * :seed => set random seed
55
+ * :verbose => show progress processing files.
56
+
57
+ Example:
58
+
59
+ ```ruby
60
+ handler = MiniTest::Chef::Handler.new({
61
+ :path => './cookbooks/test/*_test.rb',
62
+ :filter => 'foo',
63
+ :seed => srand,
64
+ :verbose => true})
65
+
66
+ report_handlers << handler
67
+ ```
68
+
69
+ ## Copyright
70
+
71
+ Copyright (c) 2012 David Calavera. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/Vagrantfile ADDED
@@ -0,0 +1,3 @@
1
+ Vagrant::Config.run do |config|
2
+ config.vm.box = "lucid64"
3
+ end
@@ -0,0 +1 @@
1
+ file '/tmp/temporal_file'
data/examples/dna.json ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "run_list": [ "recipe[foo]" ]
3
+ }
data/examples/solo.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'minitest-chef-handler'
2
+
3
+ report_handlers << MiniTest::Chef::TestHandler.new
4
+ cookbook_path File.expand_path('cookbooks', File.dirname(__FILE__))
@@ -0,0 +1,9 @@
1
+ class FooTest < MiniTest::Chef::TestCase
2
+ def test_exist_file
3
+ assert File.exist?('/tmp/temporal_file')
4
+ end
5
+
6
+ def test_succeed
7
+ assert run_status.success?
8
+ end
9
+ end
@@ -0,0 +1,53 @@
1
+ require 'minitest/unit'
2
+
3
+ module MiniTest
4
+ module Chef
5
+ class Handler < ::Chef::Handler
6
+ def initialize(options = {})
7
+ path = options.delete(:path) || './test/test_*.rb'
8
+ Dir.glob(path).each {|test_suite| require test_suite}
9
+
10
+ @options = options
11
+ end
12
+
13
+ def report
14
+ # do not run tests if chef failed
15
+ return if failed?
16
+
17
+ runner = Runner.new(run_status)
18
+ runner._run(miniunit_options)
19
+ end
20
+
21
+ private
22
+ def miniunit_options
23
+ options = []
24
+ options << ['-n', @options[:filter]] if @options[:filter]
25
+ options << "-v" if @options[:verbose]
26
+ options << ['-s', @options[:seed]] if @options[:seed]
27
+ options.flatten
28
+ end
29
+ end
30
+
31
+ class Runner < MiniTest::Unit
32
+ attr_reader :run_status
33
+
34
+ def initialize(run_status)
35
+ @run_status = run_status
36
+ super()
37
+ end
38
+ end
39
+
40
+ class TestCase < MiniTest::Unit::TestCase
41
+ attr_reader :run_status, :node, :run_context
42
+
43
+ def run(runner)
44
+ if runner.respond_to?(:run_status)
45
+ @run_status = runner.run_status
46
+ @node = @run_status.node
47
+ @run_context = @run_status.run_context
48
+ end
49
+ super(runner)
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,15 @@
1
+ # -*- encoding: utf-8 -*-
2
+ Gem::Specification.new do |gem|
3
+ gem.authors = ["David Calavera"]
4
+ gem.email = ["david.calavera@gmail.com"]
5
+ gem.description = %q{Run Minitest suites as Chef report handlers}
6
+ gem.summary = %q{Run Minitest suites as Chef report handlers}
7
+ gem.homepage = ""
8
+
9
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
10
+ gem.files = `git ls-files`.split("\n")
11
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
12
+ gem.name = "minitest-chef-handler"
13
+ gem.require_paths = ["lib"]
14
+ gem.version = '0.2.0'
15
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: minitest-chef-handler
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - David Calavera
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-28 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Run Minitest suites as Chef report handlers
15
+ email:
16
+ - david.calavera@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE
24
+ - README.md
25
+ - Rakefile
26
+ - Vagrantfile
27
+ - examples/cookbooks/foo/recipes/default.rb
28
+ - examples/dna.json
29
+ - examples/solo.rb
30
+ - examples/test/test_foo.rb
31
+ - lib/minitest-chef-handler.rb
32
+ - minitest-chef-handler.gemspec
33
+ homepage: ''
34
+ licenses: []
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project:
53
+ rubygems_version: 1.8.10
54
+ signing_key:
55
+ specification_version: 3
56
+ summary: Run Minitest suites as Chef report handlers
57
+ test_files: []
58
+ has_rdoc: