chef-bones 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ Gemfile.lock
6
+ InstalledFiles
7
+ coverage
8
+ lib/bundler/man
9
+ pkg
10
+ rdoc
11
+ spec/reports
12
+ test/tmp
13
+ test/version_tmp
14
+ tmp
15
+
16
+ # YARD artifacts
17
+ .yardoc
18
+ _yardoc
19
+ doc/
@@ -0,0 +1,17 @@
1
+ v0.1.2 (Jul 28 2013)
2
+ --------------------
3
+
4
+ * Rename gem from chef-skel to chef-bones.
5
+
6
+ v0.1.1 (Jun 26 2013)
7
+ --------------------
8
+
9
+ * Generate knife.rb as part of `rake test:prepare` so it doesn't have to be part
10
+ of the cookbook.
11
+ * Add files README.md, TESTING.md, CHANGELOG.md, and LICENSE.
12
+ * Remove Gemfile.lock.
13
+
14
+ v0.1.0 (Jun 24 2013)
15
+ --------------------
16
+
17
+ * First tagged version.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org/'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,61 @@
1
+ chef-bones
2
+ ==========
3
+
4
+ chef-bones provides a skeleton for a testable Chef cookbook.
5
+
6
+ The goal of chef-bones is to extract all testing facilities of the [skeleton
7
+ cookbook] into a gem. See file `TESTING.md` to learn more.
8
+
9
+
10
+ Installation
11
+ ------------
12
+
13
+ You can install chef-bones via RubyGems:
14
+
15
+ $ gem install chef-bones
16
+
17
+ Alternatively, you can install the gem from source:
18
+
19
+ $ git clone git://github.com/mlafeldt/chef-bones.git
20
+ $ cd chef-bones/
21
+ $ bundle install
22
+ $ bundle exec rake install
23
+
24
+
25
+ Usage
26
+ -----
27
+
28
+ For now, take a look at the [skeleton cookbook] to learn how chef-bones is used.
29
+
30
+
31
+ License and Author
32
+ ------------------
33
+
34
+ Author:: Mathias Lafeldt (<mathias.lafeldt@gmail.com>)
35
+
36
+ Copyright:: 2012-2013, Mathias Lafeldt
37
+
38
+ Licensed under the Apache License, Version 2.0 (the "License");
39
+ you may not use this file except in compliance with the License.
40
+ You may obtain a copy of the License at
41
+
42
+ http://www.apache.org/licenses/LICENSE-2.0
43
+
44
+ Unless required by applicable law or agreed to in writing, software
45
+ distributed under the License is distributed on an "AS IS" BASIS,
46
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
47
+ See the License for the specific language governing permissions and
48
+ limitations under the License.
49
+
50
+
51
+ Contributing
52
+ ------------
53
+
54
+ 1. Fork it
55
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
56
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
57
+ 4. Push to the branch (`git push origin my-new-feature`)
58
+ 5. Create new Pull Request
59
+
60
+
61
+ [skeleton cookbook]: https://github.com/mlafeldt/skeleton-cookbook
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/clean'
3
+
4
+ task :default => :build
5
+
6
+ CLEAN.include 'pkg'
@@ -0,0 +1,159 @@
1
+ Testing
2
+ -------
3
+
4
+ chef-bones comes with everything you need to develop infrastructure code with
5
+ Chef and feel confident about it. The provided testing facilities allow you to
6
+ iterate quickly on cookbook changes.
7
+
8
+ After installing Vagrant and the required Ruby gems, most of the testing can be
9
+ done through convenient Rake tasks.
10
+
11
+ ### Bundler
12
+
13
+ Apart from Vagrant, which is described later on, all tools you need for cookbook
14
+ development and testing are installed as Ruby gems using [Bundler]. This gives
15
+ you a lot of control over the software stack ensuring that the testing
16
+ environment matches your production environment.
17
+
18
+ First, make sure you have Bundler (which is itself a gem):
19
+
20
+ $ gem install bundler
21
+
22
+ Then let Bundler install the required gems (as defined in `Gemfile`):
23
+
24
+ $ bundle install
25
+
26
+ Now you can use `bundle exec` to execute a command from the gemset, for example:
27
+
28
+ $ bundle exec rake
29
+
30
+ (You should keep `Gemfile.lock` checked in.)
31
+
32
+ ### Rake
33
+
34
+ chef-bones provides a couple of helpful [Rake] tasks (specified in `Rakefile`):
35
+
36
+ $ rake -T
37
+ rake clean # Remove any temporary products.
38
+ rake clobber # Remove any generated file.
39
+ rake env # Display information about the environment
40
+ rake test:all # Run test:syntax, test:lint, test:unit, and test:integration
41
+ rake test:integration # Run serverspec integration tests with Vagrant
42
+ rake test:integration_teardown # Tear down VM used for integration tests
43
+ rake test:lint # Run Foodcritic lint checks
44
+ rake test:syntax # Run Knife syntax checks
45
+ rake test:travis # Run test:syntax, test:lint, and test:unit
46
+ rake test:unit # Run ChefSpec examples
47
+ rake vagrant:destroy # Destroy the VM
48
+ rake vagrant:halt # Shutdown the VM
49
+ rake vagrant:provision # Provision the VM using Chef
50
+ rake vagrant:ssh # SSH into the VM
51
+
52
+ As mentioned above, use `bundle exec` to start a Rake task:
53
+
54
+ $ bundle exec rake test
55
+
56
+ The `test` task is an alias for `test:all` and also happens to be the default
57
+ when no task is given. All test-related tasks are described in more detail
58
+ below.
59
+
60
+ ### Knife
61
+
62
+ The Rake task `test:syntax` will use `knife cookbook test` to run syntax checks
63
+ on the cookbook, validating both Ruby files and templates.
64
+
65
+ ### Foodcritic
66
+
67
+ The Rake task `test:lint` will use [Foodcritic] to run lint checks on the
68
+ cookbook. Foodcritic is configured to fail if there are _any_ warnings that
69
+ might stop the cookbook from working.
70
+
71
+ ### ChefSpec
72
+
73
+ The Rake task `test:unit` will run all [ChefSpec] examples in the `spec/unit`
74
+ directory. Built on top of RSpec, ChefSpec allows you to write unit tests for
75
+ Chef cookbooks. It runs your cookbook -- without actually converging a node --
76
+ and lets you make assertions about the resources that were created. This makes
77
+ it the ideal tool to get fast feedback on cookbook changes.
78
+
79
+ ### serverspec
80
+
81
+ The Rake task `test:integration` will run [serverspec] integration tests
82
+ against a VM managed by Vagrant. The files `spec/integration/**/*_spec.rb` are
83
+ the test files that are run at the end of the provisioning process by ssh'ing
84
+ into the VM. For each VM you want to test, there must be a folder with specs in
85
+ `spec/integration/` (the default node specs are in `spec/integration/default`).
86
+
87
+ In case the VM is powered off, `rake test:integration` will boot it up first.
88
+ When you no longer need the VM for integration testing, `rake
89
+ test:integration_teardown` will shut it down. If you rather want to provision
90
+ from scratch, set `INTEGRATION_TEARDOWN` accordingly. For example:
91
+
92
+ $ export INTEGRATION_TEARDOWN='vagrant:destroy'
93
+ $ rake test:integration_teardown
94
+ $ rake test:integration
95
+
96
+ ### Berkshelf
97
+
98
+ [Berkshelf] is used to set up the cookbook and its dependencies prior to testing
99
+ with Rake and Vagrant.
100
+
101
+ The dependencies are defined in `Berksfile`, which in turn resolves the
102
+ dependencies in `metadata.rb`. It is good practice to specify the cookbook
103
+ sources in `Berksfile`, while keeping the cookbook versions in `metadata.rb`
104
+ (the authoritative source of information for Chef).
105
+
106
+ During testing, dependencies are installed to the `vendor/cookbooks` directory
107
+ inside this cookbook.
108
+
109
+ ### Vagrant
110
+
111
+ With [Vagrant], you can spin up a virtual machine and run your cookbook inside
112
+ it via Chef Solo or Chef Client. The test setup requires to install **Vagrant
113
+ 1.2.x** from the [Vagrant downloads page].
114
+
115
+ You will also need the [vagrant-berkshelf] plugin, which will make your cookbook
116
+ and its dependencies automatically available to Vagrant when creating or
117
+ provisioning a VM:
118
+
119
+ $ vagrant plugin install vagrant-berkshelf
120
+
121
+ When everything is in place, this command will boot and provision the VM as
122
+ specified in the `Vagrantfile`:
123
+
124
+ $ vagrant up
125
+
126
+ In case the VM is already up, you can run the provisioners again with:
127
+
128
+ $ vagrant provision
129
+
130
+ ### Travis CI
131
+
132
+ Simply enable [Travis CI] for your GitHub repository to get free continuous
133
+ integration. Put this into your `.travis.yml` file and Travis will run the
134
+ tests each time changes are pushed to GitHub (implementing CI with other
135
+ systems should be as simple as running the same bundle commands).
136
+
137
+ ```yaml
138
+ language: ruby
139
+
140
+ rvm:
141
+ - 1.9.3
142
+ - 2.0.0
143
+
144
+ install: bundle install
145
+
146
+ script: bundle exec rake test:travis
147
+ ```
148
+
149
+
150
+ [Berkshelf]: http://berkshelf.com
151
+ [Bundler]: http://gembundler.com
152
+ [ChefSpec]: https://github.com/acrmp/chefspec
153
+ [Foodcritic]: http://acrmp.github.com/foodcritic/
154
+ [Rake]: http://rake.rubyforge.org
155
+ [Travis CI]: https://travis-ci.org
156
+ [Vagrant downloads page]: http://downloads.vagrantup.com/
157
+ [Vagrant]: http://vagrantup.com
158
+ [serverspec]: http://serverspec.org/
159
+ [vagrant-berkshelf]: https://github.com/RiotGames/vagrant-berkshelf
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/chef_bones/version', __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.authors = ['Mathias Lafeldt']
6
+ s.email = ['mathias.lafeldt@gmail.com']
7
+ s.description = %q{Skeleton for a testable Chef cookbook}
8
+ s.summary = s.description
9
+ s.homepage = 'https://github.com/mlafeldt/chef-bones'
10
+ s.license = 'Apache 2.0'
11
+
12
+ s.files = `git ls-files`.split($\)
13
+ s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
14
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
15
+ s.name = 'chef-bones'
16
+ s.require_paths = ['lib']
17
+ s.version = ChefBones::VERSION
18
+
19
+ s.add_dependency 'berkshelf'
20
+ s.add_dependency 'chef'
21
+ s.add_dependency 'chefspec'
22
+ s.add_dependency 'foodcritic'
23
+ s.add_dependency 'rake'
24
+ s.add_dependency 'serverspec'
25
+ end
@@ -0,0 +1,45 @@
1
+ require 'serverspec'
2
+ require 'pathname'
3
+ require 'net/ssh'
4
+
5
+ include Serverspec::Helper::Ssh
6
+ include Serverspec::Helper::DetectOS
7
+
8
+ SERVERSPEC_CONFIG_ROOT = ENV.fetch('SERVERSPEC_CONFIG_ROOT', '.vagrant/machines')
9
+
10
+ # Ask Vagrant for SSH config of host
11
+ def ssh_config_for_host(host)
12
+ config_file = File.join(SERVERSPEC_CONFIG_ROOT, host, 'ssh_config')
13
+ # TODO: find a way to cache results
14
+ ssh_config = `vagrant ssh-config #{host} --host #{host}`
15
+ File.open(config_file, 'w') { |file| file.write(ssh_config) }
16
+ config_file
17
+ end
18
+
19
+ RSpec.configure do |c|
20
+ if ENV['ASK_SUDO_PASSWORD']
21
+ require 'highline/import'
22
+ c.sudo_password = ask("Enter sudo password: ") { |q| q.echo = false }
23
+ else
24
+ c.sudo_password = ENV['SUDO_PASSWORD']
25
+ end
26
+ c.before :all do
27
+ block = self.class.metadata[:example_group_block]
28
+ if RUBY_VERSION.start_with?('1.8')
29
+ file = block.to_s.match(/.*@(.*):[0-9]+>/)[1]
30
+ else
31
+ file = block.source_location.first
32
+ end
33
+ dirname = Pathname.new(file).dirname
34
+ host = File.basename(dirname)
35
+ if c.host != host
36
+ c.ssh.close if c.ssh
37
+ c.host = host
38
+ config_file = ssh_config_for_host(host)
39
+ options = Net::SSH::Config.for(c.host, files=[config_file])
40
+ user = options[:user] || Etc.getlogin
41
+ c.ssh = Net::SSH.start(c.host, user, options)
42
+ c.os = backend(Serverspec::Commands::Base).check_os
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,160 @@
1
+ #
2
+ # Rake tasks to test your cookbook
3
+ #
4
+ # Copyright (C) 2012-2013 Mathias Lafeldt <mathias.lafeldt@gmail.com>
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'rake'
20
+ require 'rake/clean'
21
+ require 'rspec/core/rake_task'
22
+ require 'chef/cookbook/metadata'
23
+
24
+ def cookbook_metadata
25
+ metadata = Chef::Cookbook::Metadata.new
26
+ metadata.from_file 'metadata.rb'
27
+ metadata
28
+ end
29
+
30
+ def cookbook_name
31
+ name = cookbook_metadata.name
32
+ if name.nil? || name.empty?
33
+ File.basename(File.dirname(__FILE__))
34
+ else
35
+ name
36
+ end
37
+ end
38
+
39
+ COOKBOOK_NAME = ENV.fetch('COOKBOOK_NAME', cookbook_name)
40
+ COOKBOOK_PATH = ENV.fetch('COOKBOOK_PATH', 'vendor/cookbooks')
41
+ KNIFE_CONFIG = File.join(COOKBOOK_PATH, '.knife.rb')
42
+
43
+ CLOBBER.include COOKBOOK_PATH, 'Berksfile.lock', '.kitchen', '.vagrant'
44
+
45
+ desc 'Display information about the environment'
46
+ task :env do
47
+ {
48
+ :ruby => 'ruby --version',
49
+ :rubygems => 'gem --version',
50
+ :bundler => 'bundle --version',
51
+ :vagrant => 'vagrant --version',
52
+ :vagrant_berkshelf => 'vagrant plugin list 2>/dev/null | grep berkshelf',
53
+ :virtualbox => 'VBoxManage --version'
54
+ }.each do |key, cmd|
55
+ begin
56
+ result = `#{cmd}`.chomp
57
+ rescue Errno::ENOENT
58
+ result = 'not found'
59
+ end
60
+ puts " * #{key}: #{result}"
61
+ end
62
+ end
63
+
64
+ namespace :test do
65
+ task :prepare_cookbooks do
66
+ sh 'berks', 'install', '--path', COOKBOOK_PATH
67
+ end
68
+
69
+ task :prepare_knife_config do
70
+ File.open(KNIFE_CONFIG, 'w') do |f|
71
+ f.puts "cache_type 'BasicFile'"
72
+ f.puts "cache_options :path => '#{File.join(ENV['HOME'], '.chef', 'checksums')}'"
73
+ end
74
+ end
75
+
76
+ task :prepare => [:prepare_cookbooks, :prepare_knife_config] do
77
+ # Export path to cookbooks
78
+ ENV['COOKBOOK_PATH'] = COOKBOOK_PATH
79
+ # Run cleanup at exit unless an exception was raised.
80
+ at_exit { Rake::Task['test:cleanup'].invoke if $!.nil? }
81
+ end
82
+
83
+ task :cleanup do
84
+ rm_rf COOKBOOK_PATH
85
+ end
86
+
87
+ desc 'Run Knife syntax checks'
88
+ task :syntax => :prepare do
89
+ sh 'knife', 'cookbook', 'test', COOKBOOK_NAME, '--config', KNIFE_CONFIG,
90
+ '--cookbook-path', COOKBOOK_PATH
91
+ end
92
+
93
+ desc 'Run Foodcritic lint checks'
94
+ task :lint => :prepare do
95
+ # TODO: FoodCritic::Rake::LintTask is still experimental
96
+ sh 'foodcritic', '--epic-fail', 'any',
97
+ File.join(COOKBOOK_PATH, COOKBOOK_NAME)
98
+ end
99
+
100
+ desc 'Run ChefSpec examples'
101
+ RSpec::Core::RakeTask.new(:unit) do |t|
102
+ t.pattern = 'spec/unit/*_spec.rb'
103
+ t.rspec_opts = '--color --format documentation'
104
+ end
105
+ task :unit => :prepare
106
+
107
+ desc 'Run serverspec integration tests with Vagrant'
108
+ RSpec::Core::RakeTask.new(:integration) do |t|
109
+ t.pattern = 'spec/integration/**/*_spec.rb'
110
+ t.rspec_opts = '--color --format documentation'
111
+ end
112
+ task :integration => 'vagrant:provision'
113
+
114
+ desc 'Tear down VM used for integration tests'
115
+ task :integration_teardown do
116
+ # Shut VM down unless INTEGRATION_TEARDOWN is set to a different task.
117
+ Rake::Task[ENV.fetch('INTEGRATION_TEARDOWN', 'vagrant:halt')].invoke
118
+ end
119
+
120
+ desc 'Run test:syntax, test:lint, and test:unit'
121
+ task :travis => [:syntax, :lint, :unit]
122
+
123
+ desc 'Run test:syntax, test:lint, test:unit, and test:integration'
124
+ task :all => [:syntax, :lint, :unit, :integration, :integration_teardown]
125
+ end
126
+
127
+ namespace :vagrant do
128
+ desc 'Provision the VM using Chef'
129
+ task :provision do
130
+ # Provision VM depending on its state.
131
+ case `vagrant status`
132
+ when /The VM is running/ then ['provision']
133
+ when /To resume this VM/ then ['up', 'provision']
134
+ else ['up']
135
+ end.each { |cmd| sh 'vagrant', cmd }
136
+ end
137
+
138
+ desc 'SSH into the VM'
139
+ task :ssh do
140
+ sh 'vagrant', 'ssh'
141
+ end
142
+
143
+ desc 'Shutdown the VM'
144
+ task :halt do
145
+ sh 'vagrant', 'halt', '--force'
146
+ end
147
+
148
+ desc 'Destroy the VM'
149
+ task :destroy do
150
+ sh 'vagrant', 'destroy', '--force'
151
+ Rake::Task['test:cleanup'].invoke
152
+ end
153
+ end
154
+
155
+ # Aliases for backwards compatibility and convenience
156
+ task :lint => 'test:lint'
157
+ task :spec => 'test:unit'
158
+ task :test => 'test:all'
159
+
160
+ task :default => :test
@@ -0,0 +1,3 @@
1
+ require 'chefspec'
2
+
3
+ COOKBOOK_PATH = ENV.fetch('COOKBOOK_PATH', 'vendor/cookbooks')
@@ -0,0 +1,3 @@
1
+ module ChefBones
2
+ VERSION = '0.1.2'
3
+ end
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chef-bones
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mathias Lafeldt
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: berkshelf
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: chef
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: chefspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: foodcritic
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rake
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: serverspec
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: Skeleton for a testable Chef cookbook
111
+ email:
112
+ - mathias.lafeldt@gmail.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - .gitignore
118
+ - CHANGELOG.md
119
+ - Gemfile
120
+ - LICENSE
121
+ - README.md
122
+ - Rakefile
123
+ - TESTING.md
124
+ - chef-bones.gemspec
125
+ - lib/chef_bones/integration_spec_helper.rb
126
+ - lib/chef_bones/rake_tasks.rb
127
+ - lib/chef_bones/unit_spec_helper.rb
128
+ - lib/chef_bones/version.rb
129
+ homepage: https://github.com/mlafeldt/chef-bones
130
+ licenses:
131
+ - Apache 2.0
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ segments:
143
+ - 0
144
+ hash: -3822334618583577924
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ none: false
147
+ requirements:
148
+ - - '>='
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ segments:
152
+ - 0
153
+ hash: -3822334618583577924
154
+ requirements: []
155
+ rubyforge_project:
156
+ rubygems_version: 1.8.25
157
+ signing_key:
158
+ specification_version: 3
159
+ summary: Skeleton for a testable Chef cookbook
160
+ test_files: []