bats-chef-handler 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1 +1,128 @@
1
- @TODO
1
+ Description
2
+ ===========
3
+
4
+ Chef report handler that will find and execute BATS tests, similiar to and inspired
5
+ by [minitest-chef-handler](https://github.com/calavera/minitest-chef-handler)
6
+
7
+ * http://wiki.opscode.com/display/chef/Exception+and+Report+Handlers
8
+
9
+ Requirements
10
+ ============
11
+
12
+ * Tested on Chef 10.14.x. May run on other versions (will test Chef 11 soon.)
13
+ * Only tested with chef-solo thus far. I do not run chef-server or hosted chef.
14
+ * Install [bats](https://github.com/sstephenson/bats). It should be in `$PATH` for the Chef run.
15
+
16
+
17
+ Installation
18
+ =====
19
+
20
+ There are two ways to use Chef Handlers.
21
+
22
+ ### Method 1 (recommended)
23
+
24
+ Use the
25
+ [chef_handler cookbook by Opscode](http://community.opscode.com/cookbooks/chef_handler).
26
+ Create a recipe with the following:
27
+
28
+ include_recipe "chef_handler"
29
+
30
+ # Install `bats-chef-handler` gem during the compile phase
31
+ chef_gem "bats-chef-handler"
32
+
33
+ # load the gem here so it gets added to the $LOAD_PATH, otherwise chef_handler
34
+ # will fail.
35
+ require 'chef/handler/bats_handler'
36
+
37
+ # Activate the handler immediately during compile phase
38
+ chef_handler "Chef::Handler::BatsHandler" do
39
+ source "chef/handler/bats_handler"
40
+ action :nothing
41
+ end.run_action(:enable)
42
+
43
+
44
+ ### Method 2
45
+
46
+ Install the gem ahead of time, and configure Chef to use
47
+ them:
48
+
49
+ gem install bats-chef-handler
50
+
51
+ Then add to the configuration (`/etc/chef/solo.rb` for chef-solo or
52
+ `/etc/chef/client.rb` for chef-client):
53
+
54
+ require "chef/handler/bats_handler"
55
+ report_handlers << Chef::Handler::BatsHandler.new
56
+
57
+ Usage
58
+ ====
59
+
60
+ ### Test cases
61
+
62
+ Write your BATS tests and place them together with the cookbooks they are designed to test. The handler will automatically load and execute tests based on the list of recipes that were executed during the test run.
63
+
64
+ Examples:
65
+
66
+ If the executed recipes include the recipe `foo::default`, we try to load tests from:
67
+
68
+ <cookbook_path>/foo/tests/default_test.bats
69
+ <cookbook_path>/foo/tests/default/*.bats
70
+
71
+ ### node variables
72
+
73
+ Since BATS tests are bash scripts that execute outside of the Ruby VM, you do not have access to node variables like you would with tests written in minitest. This may or may not be an issue depending on what you're testing and there are strategies to work around this. In practice we don't expect this will be an issue for the majority of testing.
74
+
75
+ Additionally, BATS seems to be catching on as the preferred integration test approach for Chef (as seen by it's prevalance in cookbooks covered by test-kitchen testing) so we decided BATS was potentially a better test framework for Chef.
76
+
77
+ It's also easier to run BATS tests outside of the Chef context, for example as a Sensu test or post-deploy smoketest.
78
+
79
+ ### Chef run failure
80
+
81
+ If any of the tests fail, the handler raises an error to abort the Chef execution.
82
+
83
+ ### Example
84
+
85
+ While developing a simple cookbook for clamav we decide to write a few integration tests. Our clamav cookbook is composed of 2 recipes
86
+
87
+ * clamav::default
88
+ * clamav::freshclam
89
+
90
+ We have created simple tests for each of them in the paths: `cookbooks/clamav/tests/default_test.bats` and `cookbooks/clamav/tests/freshclam_test.bats`:
91
+
92
+ $ chef-solo
93
+
94
+ [2013-10-01T21:38:23+00:00] INFO: *** Chef 10.14.2 ***
95
+ ...
96
+ [2013-10-01T21:38:39+00:00] INFO: Chef Run complete in 12.715307935 seconds
97
+ [2013-10-01T21:38:39+00:00] INFO: Running report handlers
98
+ [2013-10-01T21:38:39+00:00] INFO: Resources updated this run:
99
+ [2013-10-01T21:38:39+00:00] INFO: chef_handler[Chef::Handler::BatsHandler] (0s)
100
+
101
+ [2013-10-01T21:38:39+00:00] INFO: Running test: /opt/titan/chef/cookbooks/clamav/tests/base_test.bats
102
+ 1..1
103
+ ok 1 clamav package installed
104
+ [2013-10-01T21:38:40+00:00] INFO: Running test: /opt/titan/chef/cookbooks/clamav/tests/freshclam_test.bats
105
+ 1..4
106
+ ok 1 clamav-update package installed
107
+ ok 2 /etc/sysconfig/freshclam exists and is enabled
108
+ ok 3 /etc/cron.d/clamav-update cron job exists
109
+ ok 4 virus database should exist (if not, see /etc/cron.d/clamav-update)
110
+ [2013-10-01T21:38:41+00:00] INFO: Report handlers complete
111
+
112
+ Credit
113
+ ====
114
+
115
+ The idea and much of the code to make this happen was borrowed straight out of (minitest-chef-handler)[https://github.com/calavera/minitest-chef-handler] by David Calavera. We simply wanted the same thing but with BATS tests.
116
+
117
+ TODO
118
+ ====
119
+
120
+ * It would be nice to support a similar path structure to what test-kitchen's BATS busser expects so that tests were easily and automatically executed in the bats-handler context and test-kitchen context.
121
+ * Only call the bats binary once with all `.bats` files as arguments so that there is a single TAPS output. Not currently supported by BATS but would be an easy patch.
122
+
123
+ License
124
+ =======
125
+
126
+ Licensed under the MIT license. See `LICENSE` file for details.
127
+
128
+ Joe Miller <https://github.com/joemiller>, <https://twitter.com/miller_joe>
@@ -1,7 +1,7 @@
1
1
  class Chef
2
2
  class Handler
3
3
  class BatsHandler < Chef::Handler
4
- VERSION = '0.0.3'
4
+ VERSION = '0.0.4'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bats-chef-handler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-01 00:00:00.000000000 Z
12
+ date: 2013-10-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: chef
@@ -39,7 +39,8 @@ files:
39
39
  - lib/chef/handler/bats_handler_version.rb
40
40
  - lib/chef/handler/bats_handler.rb
41
41
  homepage: https://github.com/joemiller/bats-chef-handler
42
- licenses: []
42
+ licenses:
43
+ - MIT
43
44
  post_install_message:
44
45
  rdoc_options: []
45
46
  require_paths: