minitest-chef-handler 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/History.txt +9 -0
- data/README.md +8 -4
- data/Vagrantfile +6 -1
- data/examples/cookbooks/chef_handler/README.md +115 -0
- data/examples/cookbooks/chef_handler/attributes/default.rb +21 -0
- data/examples/cookbooks/chef_handler/files/default/handlers/README +1 -0
- data/examples/cookbooks/chef_handler/metadata.json +29 -0
- data/examples/cookbooks/chef_handler/metadata.rb +6 -0
- data/examples/cookbooks/chef_handler/providers/default.rb +83 -0
- data/examples/cookbooks/chef_handler/recipes/default.rb +31 -0
- data/examples/cookbooks/chef_handler/recipes/json_file.rb +28 -0
- data/examples/cookbooks/chef_handler/recipes/minitest.rb +24 -0
- data/examples/cookbooks/chef_handler/resources/default.rb +34 -0
- data/examples/cookbooks/foo/test/test_foo.rb +9 -0
- data/examples/solo.rb +1 -1
- data/lib/minitest-chef-handler.rb +16 -1
- data/minitest-chef-handler.gemspec +3 -1
- metadata +32 -4
data/.gitignore
CHANGED
data/History.txt
ADDED
data/README.md
CHANGED
@@ -4,7 +4,7 @@ Run minitest suites after your Chef recipes to check the status of your system.
|
|
4
4
|
|
5
5
|
## Motivation
|
6
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
|
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 modifies those recipes, mostly myself, the provisioned services continue working as expected.
|
8
8
|
|
9
9
|
There are other solutions that evaluate the configured node after the recipes
|
10
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.
|
@@ -28,7 +28,7 @@ report_handlers << MiniTest::Chef::Handler.new
|
|
28
28
|
2. Write your tests as normal MiniTest cases extending from MiniTest::Chef::TestCase:
|
29
29
|
|
30
30
|
```ruby
|
31
|
-
class TestNginx < MiniTest::Chef::
|
31
|
+
class TestNginx < MiniTest::Chef::TestCase
|
32
32
|
def test_config_file_exist
|
33
33
|
assert File.exist?('/etc/nginx.conf')
|
34
34
|
end
|
@@ -38,8 +38,8 @@ end
|
|
38
38
|
You still have access to Chef's `run_status`, `node` and `run_context` from your tests:
|
39
39
|
|
40
40
|
```ruby
|
41
|
-
class TestNginx < MiniTest::Chef::
|
42
|
-
def
|
41
|
+
class TestNginx < MiniTest::Chef::TestCase
|
42
|
+
def test_succeed
|
43
43
|
assert run_status.success?
|
44
44
|
end
|
45
45
|
end
|
@@ -66,6 +66,10 @@ handler = MiniTest::Chef::Handler.new({
|
|
66
66
|
report_handlers << handler
|
67
67
|
```
|
68
68
|
|
69
|
+
## Chef server distribution
|
70
|
+
|
71
|
+
The instructions abow have described how to use it in a Chef solo installation. If you want to distribute the handler to your Chef server check either the chef_handler cookbooks in the examples or [minitest-handler-cookbook](https://github.com/btm/minitest-handler-cookbook).
|
72
|
+
|
69
73
|
## Copyright
|
70
74
|
|
71
75
|
Copyright (c) 2012 David Calavera. See LICENSE for details.
|
data/Vagrantfile
CHANGED
@@ -0,0 +1,115 @@
|
|
1
|
+
Description
|
2
|
+
===========
|
3
|
+
|
4
|
+
Creates a configured handler path for distributing [Chef report and exception handlers](http://wiki.opscode.com/display/chef/Exception+and+Report+Handlers). Also exposes an LWRP for enabling Chef handlers from within recipe code (as opposed to hard coding in the client.rb file). This is useful for cookbook authors who may want to ship a product specific handler (see the `cloudkick` cookbook for an example) with their cookbook.
|
5
|
+
|
6
|
+
Attributes
|
7
|
+
==========
|
8
|
+
|
9
|
+
`node["chef_handler"]["handler_path"]` - location to drop off handlers directory, default is `/var/chef/handlers`.
|
10
|
+
|
11
|
+
Resource/Provider
|
12
|
+
=================
|
13
|
+
|
14
|
+
`chef_handler`
|
15
|
+
--------------
|
16
|
+
|
17
|
+
Requires, configures and enables handlers on the node for the current Chef run. Also has the ability to pass arguments to the handlers initializer. This allows initialization data to be pulled from a node's attribute data.
|
18
|
+
|
19
|
+
It is best to declare `chef_handler` resources early on in the compile phase so they are available to fire for any exceptions during the Chef run. If you have a base role you would want any recipes that register Chef handlers to come first in the run_list.
|
20
|
+
|
21
|
+
### Actions
|
22
|
+
|
23
|
+
- :enable: Enables the Chef handler for the current Chef run on the current node
|
24
|
+
- :disable: Disables the Chef handler for the current Chef run on the current node
|
25
|
+
|
26
|
+
### Attribute Parameters
|
27
|
+
|
28
|
+
- class_name: name attribute. The name of the handler class (can be module name-spaced).
|
29
|
+
- source: full path to the handler file. can also be a gem path if the handler ships as part of a Ruby gem.
|
30
|
+
- arguments: an array of arguments to pass the handler's class initializer
|
31
|
+
- supports: type of Chef Handler to register as, ie :report, :exception or both. default is `:report => true, :exception => true`
|
32
|
+
|
33
|
+
### Example
|
34
|
+
|
35
|
+
# register the Chef::Handler::JsonFile handler
|
36
|
+
# that ships with the Chef gem
|
37
|
+
chef_handler "Chef::Handler::JsonFile" do
|
38
|
+
source "chef/handler/json_file"
|
39
|
+
arguments :path => '/var/chef/reports'
|
40
|
+
action :enable
|
41
|
+
end
|
42
|
+
|
43
|
+
# do the same but during the compile phase
|
44
|
+
chef_handler "Chef::Handler::JsonFile" do
|
45
|
+
source "chef/handler/json_file"
|
46
|
+
arguments :path => '/var/chef/reports'
|
47
|
+
action :nothing
|
48
|
+
end.run_action(:enable)
|
49
|
+
|
50
|
+
# handle exceptions only
|
51
|
+
chef_handler "Chef::Handler::JsonFile" do
|
52
|
+
source "chef/handler/json_file"
|
53
|
+
arguments :path => '/var/chef/reports'
|
54
|
+
supports exception => true
|
55
|
+
action :enable
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
# enable the CloudkickHandler which was
|
60
|
+
# dropped off in the default handler path.
|
61
|
+
# passes the oauth key/secret to the handler's
|
62
|
+
# intializer.
|
63
|
+
chef_handler "CloudkickHandler" do
|
64
|
+
source "#{node['chef_handler']['handler_path']}/cloudkick_handler.rb"
|
65
|
+
arguments [node['cloudkick']['oauth_key'], node['cloudkick']['oauth_secret']]
|
66
|
+
action :enable
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
Usage
|
71
|
+
=====
|
72
|
+
|
73
|
+
default
|
74
|
+
-------
|
75
|
+
|
76
|
+
Put the recipe `chef_handler` at the start of the node's run list to make sure that custom handlers are dropped off early on in the Chef run and available for later recipes.
|
77
|
+
|
78
|
+
For information on how to write report and exception handlers for Chef, please see the Chef wiki pages:
|
79
|
+
http://wiki.opscode.com/display/chef/Exception+and+Report+Handlers
|
80
|
+
|
81
|
+
json_file
|
82
|
+
---------
|
83
|
+
|
84
|
+
Leverages the `chef_handler` LWRP to automatically register the `Chef::Handler::JsonFile` handler that ships as part of Chef. This handler serializes the run status data to a JSON file located at `/var/chef/reports`.
|
85
|
+
|
86
|
+
Changes/Roadmap
|
87
|
+
===============
|
88
|
+
|
89
|
+
## 1.0.4
|
90
|
+
|
91
|
+
* [COOK-654] dont try and access a class before it has been loaded
|
92
|
+
* fix bad boolean check (if vs unless)
|
93
|
+
|
94
|
+
## 1.0.2:
|
95
|
+
|
96
|
+
* [COOK-620] ensure handler code is reloaded during daemonized chef runs
|
97
|
+
|
98
|
+
License and Author
|
99
|
+
==================
|
100
|
+
|
101
|
+
Author:: Seth Chisamore (<schisamo@opscode.com>)
|
102
|
+
|
103
|
+
Copyright:: 2011, Opscode, Inc
|
104
|
+
|
105
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
106
|
+
you may not use this file except in compliance with the License.
|
107
|
+
You may obtain a copy of the License at
|
108
|
+
|
109
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
110
|
+
|
111
|
+
Unless required by applicable law or agreed to in writing, software
|
112
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
113
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
114
|
+
See the License for the specific language governing permissions and
|
115
|
+
limitations under the License.
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
3
|
+
# Cookbook Name:: chef_handlers
|
4
|
+
# Attribute:: default
|
5
|
+
#
|
6
|
+
# Copyright 2011, Opscode, Inc
|
7
|
+
#
|
8
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
9
|
+
# you may not use this file except in compliance with the License.
|
10
|
+
# You may obtain a copy of the License at
|
11
|
+
#
|
12
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
13
|
+
#
|
14
|
+
# Unless required by applicable law or agreed to in writing, software
|
15
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
16
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
17
|
+
# See the License for the specific language governing permissions and
|
18
|
+
# limitations under the License.
|
19
|
+
#
|
20
|
+
|
21
|
+
default["chef_handler"]["handler_path"] = "#{File.expand_path(File.join(Chef::Config[:file_cache_path],'..'))}/handlers"
|
@@ -0,0 +1 @@
|
|
1
|
+
This directory contains Chef handlers to distribute to your nodes.
|
@@ -0,0 +1,29 @@
|
|
1
|
+
{
|
2
|
+
"name": "chef_handler",
|
3
|
+
"description": "Distribute and enable Chef Exception and Report handlers",
|
4
|
+
"long_description": "Description\n===========\n\nCreates a configured handler path for distributing [Chef report and exception handlers](http://wiki.opscode.com/display/chef/Exception+and+Report+Handlers). Also exposes an LWRP for enabling Chef handlers from within recipe code (as opposed to hard coding in the client.rb file). This is useful for cookbook authors who may want to ship a product specific handler (see the `cloudkick` cookbook for an example) with their cookbook.\n\nAttributes\n==========\n\n`node[\"chef_handler\"][\"handler_path\"]` - location to drop off handlers directory, default is `/var/chef/handlers`.\n\nResource/Provider\n=================\n\n`chef_handler`\n--------------\n\nRequires, configures and enables handlers on the node for the current Chef run. Also has the ability to pass arguments to the handlers initializer. This allows initialization data to be pulled from a node's attribute data.\n\nIt is best to declare `chef_handler` resources early on in the compile phase so they are available to fire for any exceptions during the Chef run. If you have a base role you would want any recipes that register Chef handlers to come first in the run_list.\n\n### Actions\n\n- :enable: Enables the Chef handler for the current Chef run on the current node\n- :disable: Disables the Chef handler for the current Chef run on the current node\n\n### Attribute Parameters\n\n- class_name: name attribute. The name of the handler class (can be module name-spaced).\n- source: full path to the handler file. can also be a gem path if the handler ships as part of a Ruby gem.\n- arguments: an array of arguments to pass the handler's class initializer\n- supports: type of Chef Handler to register as, ie :report, :exception or both. default is `:report => true, :exception => true`\n\n### Example\n \n # register the Chef::Handler::JsonFile handler \n # that ships with the Chef gem\n chef_handler \"Chef::Handler::JsonFile\" do\n source \"chef/handler/json_file\"\n arguments :path => '/var/chef/reports'\n action :enable\n end\n \n # do the same but during the compile phase\n chef_handler \"Chef::Handler::JsonFile\" do\n source \"chef/handler/json_file\"\n arguments :path => '/var/chef/reports'\n action :nothing\n end.run_action(:enable)\n \n # handle exceptions only\n chef_handler \"Chef::Handler::JsonFile\" do\n source \"chef/handler/json_file\"\n arguments :path => '/var/chef/reports'\n supports exception => true\n action :enable\n end\n \n \n # enable the CloudkickHandler which was \n # dropped off in the default handler path.\n # passes the oauth key/secret to the handler's \n # intializer.\n chef_handler \"CloudkickHandler\" do\n source \"#{node['chef_handler']['handler_path']}/cloudkick_handler.rb\"\n arguments [node['cloudkick']['oauth_key'], node['cloudkick']['oauth_secret']]\n action :enable\n end\n\n\nUsage\n=====\n\ndefault\n-------\n\nPut the recipe `chef_handler` at the start of the node's run list to make sure that custom handlers are dropped off early on in the Chef run and available for later recipes.\n\nFor information on how to write report and exception handlers for Chef, please see the Chef wiki pages:\nhttp://wiki.opscode.com/display/chef/Exception+and+Report+Handlers\n\njson_file\n---------\n\nLeverages the `chef_handler` LWRP to automatically register the `Chef::Handler::JsonFile` handler that ships as part of Chef. This handler serializes the run status data to a JSON file located at `/var/chef/reports`.\n\nChanges/Roadmap\n===============\n\n## 1.0.4\n\n* [COOK-654] dont try and access a class before it has been loaded\n* fix bad boolean check (if vs unless)\n\n## 1.0.2:\n\n* [COOK-620] ensure handler code is reloaded during daemonized chef runs\n\nLicense and Author\n==================\n\nAuthor:: Seth Chisamore (<schisamo@opscode.com>)\n\nCopyright:: 2011, Opscode, Inc\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n",
|
5
|
+
"maintainer": "Opscode, Inc.",
|
6
|
+
"maintainer_email": "cookbooks@opscode.com",
|
7
|
+
"license": "Apache 2.0",
|
8
|
+
"platforms": {
|
9
|
+
},
|
10
|
+
"dependencies": {
|
11
|
+
},
|
12
|
+
"recommendations": {
|
13
|
+
},
|
14
|
+
"suggestions": {
|
15
|
+
},
|
16
|
+
"conflicting": {
|
17
|
+
},
|
18
|
+
"providing": {
|
19
|
+
},
|
20
|
+
"replacing": {
|
21
|
+
},
|
22
|
+
"attributes": {
|
23
|
+
},
|
24
|
+
"groupings": {
|
25
|
+
},
|
26
|
+
"recipes": {
|
27
|
+
},
|
28
|
+
"version": "1.0.4"
|
29
|
+
}
|
@@ -0,0 +1,83 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Seth Chisamore <schisamo@opscode.com>
|
3
|
+
# Cookbook Name:: chef_handler
|
4
|
+
# Provider:: default
|
5
|
+
#
|
6
|
+
# Copyright:: 2011, Opscode, Inc <legal@opscode.com>
|
7
|
+
#
|
8
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
9
|
+
# you may not use this file except in compliance with the License.
|
10
|
+
# You may obtain a copy of the License at
|
11
|
+
#
|
12
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
13
|
+
#
|
14
|
+
# Unless required by applicable law or agreed to in writing, software
|
15
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
16
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
17
|
+
# See the License for the specific language governing permissions and
|
18
|
+
# limitations under the License.
|
19
|
+
#
|
20
|
+
|
21
|
+
action :enable do
|
22
|
+
# use load instead of require to ensure the handler file
|
23
|
+
# is reloaded into memory each chef run. fixes COOK-620
|
24
|
+
begin
|
25
|
+
Object.send(:remove_const, klass)
|
26
|
+
GC.start
|
27
|
+
rescue
|
28
|
+
Chef::Log.debug("#{@new_resource.class_name} has not been loaded.")
|
29
|
+
end
|
30
|
+
file_name = @new_resource.source
|
31
|
+
file_name << ".rb" unless file_name =~ /.*\.rb$/
|
32
|
+
load file_name
|
33
|
+
handler = klass.send(:new, *collect_args(@new_resource.arguments))
|
34
|
+
@new_resource.supports.each do |type, enable|
|
35
|
+
if enable
|
36
|
+
# we have to re-enable the handler every chef run
|
37
|
+
# to ensure daemonized Chef always has the latest
|
38
|
+
# handler code. TODO: add a :reload action
|
39
|
+
Chef::Log.info("Enabling #{@new_resource} as a #{type} handler")
|
40
|
+
Chef::Config.send("#{type.to_s}_handlers").delete_if {|v| v.class.to_s.include? @new_resource.class_name}
|
41
|
+
Chef::Config.send("#{type.to_s}_handlers") << handler
|
42
|
+
new_resource.updated_by_last_action(true)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
action :disable do
|
48
|
+
@new_resource.supports.each_key do |type|
|
49
|
+
if enabled?(type)
|
50
|
+
Chef::Log.info("Disabling #{@new_resource} as a #{type} handler")
|
51
|
+
Chef::Config.send("#{type.to_s}_handlers").delete_if {|v| v.class.to_s.include? @new_resource.class_name}
|
52
|
+
new_resource.updated_by_last_action(true)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def load_current_resource
|
58
|
+
@current_resource = Chef::Resource::ChefHandler.new(@new_resource.name)
|
59
|
+
@current_resource.class_name(@new_resource.class_name)
|
60
|
+
@current_resource.source(@new_resource.source)
|
61
|
+
@current_resource
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
def enabled?(type)
|
66
|
+
Chef::Config.send("#{type.to_s}_handlers").select do |handler|
|
67
|
+
handler.class.to_s.include? @new_resource.class_name
|
68
|
+
end.size >= 1
|
69
|
+
end
|
70
|
+
|
71
|
+
def collect_args(resource_args = [])
|
72
|
+
if resource_args.is_a? Array
|
73
|
+
resource_args
|
74
|
+
else
|
75
|
+
[resource_args]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def klass
|
80
|
+
@klass ||= begin
|
81
|
+
@new_resource.class_name.split('::').inject(Kernel) {|scope, const_name| scope.const_get(const_name)}
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
3
|
+
# Cookbook Name:: chef_handlers
|
4
|
+
# Recipe:: default
|
5
|
+
#
|
6
|
+
# Copyright 2011, Opscode, Inc.
|
7
|
+
#
|
8
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
9
|
+
# you may not use this file except in compliance with the License.
|
10
|
+
# You may obtain a copy of the License at
|
11
|
+
#
|
12
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
13
|
+
#
|
14
|
+
# Unless required by applicable law or agreed to in writing, software
|
15
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
16
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
17
|
+
# See the License for the specific language governing permissions and
|
18
|
+
# limitations under the License.
|
19
|
+
#
|
20
|
+
|
21
|
+
Chef::Log.info("Chef Handlers will be at: #{node['chef_handler']['handler_path']}")
|
22
|
+
|
23
|
+
remote_directory node['chef_handler']['handler_path'] do
|
24
|
+
source 'handlers'
|
25
|
+
owner 'root'
|
26
|
+
group 'root'
|
27
|
+
mode "0755"
|
28
|
+
recursive true
|
29
|
+
action :nothing
|
30
|
+
end.run_action(:create)
|
31
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
3
|
+
# Cookbook Name:: chef_handlers
|
4
|
+
# Recipe:: json_file
|
5
|
+
#
|
6
|
+
# Copyright 2011, Opscode, Inc.
|
7
|
+
#
|
8
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
9
|
+
# you may not use this file except in compliance with the License.
|
10
|
+
# You may obtain a copy of the License at
|
11
|
+
#
|
12
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
13
|
+
#
|
14
|
+
# Unless required by applicable law or agreed to in writing, software
|
15
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
16
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
17
|
+
# See the License for the specific language governing permissions and
|
18
|
+
# limitations under the License.
|
19
|
+
#
|
20
|
+
|
21
|
+
# force resource actions in compile phase so exception handler
|
22
|
+
# fires for compile phase exceptions
|
23
|
+
|
24
|
+
chef_handler "Chef::Handler::JsonFile" do
|
25
|
+
source "chef/handler/json_file"
|
26
|
+
arguments :path => '/var/chef/reports'
|
27
|
+
action :nothing
|
28
|
+
end.run_action(:enable)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
gem_package "minitest" do
|
2
|
+
action :nothing
|
3
|
+
end.run_action(:upgrade)
|
4
|
+
|
5
|
+
gem_package "minitest-chef-handler" do
|
6
|
+
action :nothing
|
7
|
+
end.run_action(:upgrade)
|
8
|
+
|
9
|
+
require 'rubygems'
|
10
|
+
Gem.clear_paths
|
11
|
+
require 'minitest-chef-handler'
|
12
|
+
|
13
|
+
path = File.join(Chef::Config[:cookbook_path],
|
14
|
+
"**",
|
15
|
+
"test",
|
16
|
+
"test_*.rb")
|
17
|
+
|
18
|
+
Chef::Log.info "path is #{path}, entries: #{Dir.glob(path).entries}"
|
19
|
+
|
20
|
+
chef_handler "MiniTest::Chef::Handler" do
|
21
|
+
source "minitest-chef-handler"
|
22
|
+
arguments :path => path
|
23
|
+
action :nothing
|
24
|
+
end.run_action(:enable)
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Seth Chisamore <schisamo@opscode.com>
|
3
|
+
# Cookbook Name:: chef_handler
|
4
|
+
# Resource:: default
|
5
|
+
#
|
6
|
+
# Copyright:: 2011, Opscode, Inc <legal@opscode.com>
|
7
|
+
#
|
8
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
9
|
+
# you may not use this file except in compliance with the License.
|
10
|
+
# You may obtain a copy of the License at
|
11
|
+
#
|
12
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
13
|
+
#
|
14
|
+
# Unless required by applicable law or agreed to in writing, software
|
15
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
16
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
17
|
+
# See the License for the specific language governing permissions and
|
18
|
+
# limitations under the License.
|
19
|
+
#
|
20
|
+
|
21
|
+
actions :enable, :disable
|
22
|
+
|
23
|
+
attribute :class_name, :kind_of => String, :name_attribute => true
|
24
|
+
attribute :source, :default => nil, :kind_of => String
|
25
|
+
attribute :arguments, :default => []
|
26
|
+
attribute :supports, :kind_of => Hash, :default => {:report => true, :exception => true}
|
27
|
+
|
28
|
+
# we have to set default for the supports attribute
|
29
|
+
# in initializer since it is a 'reserved' attribute name
|
30
|
+
def initialize(*args)
|
31
|
+
super
|
32
|
+
@action = :enable
|
33
|
+
@supports = {:report => true, :exception => true}
|
34
|
+
end
|
data/examples/solo.rb
CHANGED
@@ -15,10 +15,16 @@ module MiniTest
|
|
15
15
|
return if failed?
|
16
16
|
|
17
17
|
runner = Runner.new(run_status)
|
18
|
-
|
18
|
+
|
19
|
+
if custom_runner?
|
20
|
+
runner._run(miniunit_options)
|
21
|
+
else
|
22
|
+
runner.run(miniunit_options)
|
23
|
+
end
|
19
24
|
end
|
20
25
|
|
21
26
|
private
|
27
|
+
|
22
28
|
def miniunit_options
|
23
29
|
options = []
|
24
30
|
options << ['-n', @options[:filter]] if @options[:filter]
|
@@ -26,6 +32,15 @@ module MiniTest
|
|
26
32
|
options << ['-s', @options[:seed]] if @options[:seed]
|
27
33
|
options.flatten
|
28
34
|
end
|
35
|
+
|
36
|
+
# Before Minitest 2.1.0 Minitest::Unit called `run` because the custom runners support was poorly designed.
|
37
|
+
# See: https://github.com/seattlerb/minitest/commit/6023c879cf3d5169953ee929343b679de4a48bbc
|
38
|
+
#
|
39
|
+
# Using this workaround we still allow to use any other runner with the test suite for versions greater than 2.1.0.
|
40
|
+
# If the test suite doesn't use any chef injection capability it still can be ran with the default Minitest runner.
|
41
|
+
def custom_runner?
|
42
|
+
Gem::Version.new(MiniTest::Unit::VERSION) >= Gem::Version.new('2.1.0')
|
43
|
+
end
|
29
44
|
end
|
30
45
|
|
31
46
|
class Runner < MiniTest::Unit
|
@@ -11,5 +11,7 @@ Gem::Specification.new do |gem|
|
|
11
11
|
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
12
12
|
gem.name = "minitest-chef-handler"
|
13
13
|
gem.require_paths = ["lib"]
|
14
|
-
gem.version = '0.
|
14
|
+
gem.version = '0.3.0'
|
15
|
+
|
16
|
+
gem.add_development_dependency('rake')
|
15
17
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minitest-chef-handler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,19 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
13
|
-
dependencies:
|
12
|
+
date: 2012-04-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: &2164677120 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2164677120
|
14
25
|
description: Run Minitest suites as Chef report handlers
|
15
26
|
email:
|
16
27
|
- david.calavera@gmail.com
|
@@ -20,11 +31,23 @@ extra_rdoc_files: []
|
|
20
31
|
files:
|
21
32
|
- .gitignore
|
22
33
|
- Gemfile
|
34
|
+
- History.txt
|
23
35
|
- LICENSE
|
24
36
|
- README.md
|
25
37
|
- Rakefile
|
26
38
|
- Vagrantfile
|
39
|
+
- examples/cookbooks/chef_handler/README.md
|
40
|
+
- examples/cookbooks/chef_handler/attributes/default.rb
|
41
|
+
- examples/cookbooks/chef_handler/files/default/handlers/README
|
42
|
+
- examples/cookbooks/chef_handler/metadata.json
|
43
|
+
- examples/cookbooks/chef_handler/metadata.rb
|
44
|
+
- examples/cookbooks/chef_handler/providers/default.rb
|
45
|
+
- examples/cookbooks/chef_handler/recipes/default.rb
|
46
|
+
- examples/cookbooks/chef_handler/recipes/json_file.rb
|
47
|
+
- examples/cookbooks/chef_handler/recipes/minitest.rb
|
48
|
+
- examples/cookbooks/chef_handler/resources/default.rb
|
27
49
|
- examples/cookbooks/foo/recipes/default.rb
|
50
|
+
- examples/cookbooks/foo/test/test_foo.rb
|
28
51
|
- examples/dna.json
|
29
52
|
- examples/solo.rb
|
30
53
|
- examples/test/test_foo.rb
|
@@ -42,12 +65,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
42
65
|
- - ! '>='
|
43
66
|
- !ruby/object:Gem::Version
|
44
67
|
version: '0'
|
68
|
+
segments:
|
69
|
+
- 0
|
70
|
+
hash: -1728992834997706778
|
45
71
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
72
|
none: false
|
47
73
|
requirements:
|
48
74
|
- - ! '>='
|
49
75
|
- !ruby/object:Gem::Version
|
50
76
|
version: '0'
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
hash: -1728992834997706778
|
51
80
|
requirements: []
|
52
81
|
rubyforge_project:
|
53
82
|
rubygems_version: 1.8.10
|
@@ -55,4 +84,3 @@ signing_key:
|
|
55
84
|
specification_version: 3
|
56
85
|
summary: Run Minitest suites as Chef report handlers
|
57
86
|
test_files: []
|
58
|
-
has_rdoc:
|