Skip to content

Commit e59d759

Browse files
committed
Add Test Kitchen, ChefSpec, RuboCop, and Foodcritic on Travis CI
Signed-off-by: Seth Vargo <[email protected]>
1 parent ffa2c06 commit e59d759

File tree

33 files changed

+346
-318
lines changed

33 files changed

+346
-318
lines changed

.gitignore

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
.vagrant
2-
Berksfile.lock
3-
Gemfile.lock
41
*~
52
*#
63
.#*
74
\#*#
85
.*.sw[a-z]
96
*.un~
10-
.bundle
11-
.cache
12-
.kitchen
13-
bin
7+
*.tmp
8+
*.bk
9+
*.bkup
1410
.kitchen.local.yml
11+
Berksfile.lock
12+
Gemfile.lock
13+
14+
.bundle/
15+
.cache/
16+
.kitchen/
17+
.vagrant/
18+
.vagrant.d/
19+
bin/
20+
tmp/
21+
vendor/

.kitchen.yml

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,20 @@
11
driver_plugin: vagrant
22
driver_config:
33
require_chef_omnibus: true
4-
customize:
5-
memory: 1024
64

75
platforms:
86
- name: ubuntu-12.04
97
run_list:
10-
- recipe[apt::default]
11-
- name: ubuntu-10.04
12-
run_list:
13-
- recipe[apt::default]
8+
- recipe[apt::default]
149
- name: centos-6.4
15-
- name: centos-5.9
1610

1711
suites:
1812
- name: default
1913
run_list:
20-
- recipe[logrotate_test::default]
21-
- recipe[minitest-handler::default]
14+
- recipe[logrotate::default]
15+
- name: definition
16+
run_list:
17+
- recipe[fake::definition]
2218
- name: global
2319
run_list:
2420
- recipe[logrotate::global]
25-
- recipe[minitest-handler::default]
26-
- name: definition
27-
run_list:
28-
- recipe[logrotate_test::logrotate_app]
29-
- recipe[minitest-handler::default]

.rubocop.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
AllCops:
2+
Excludes:
3+
- vendor/**
4+
5+
AlignParameters:
6+
Enabled: false
7+
Encoding:
8+
Enabled: false
9+
HashSyntax:
10+
Enabled: false
11+
LineLength:
12+
Enabled: false
13+
MethodLength:
14+
Max: 30

.travis.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
rvm:
2+
- 1.9.3
3+
- 2.0.0
4+
before_script:
5+
- bundle exec berks install
6+
script:
7+
- bundle exec foodcritic -f any . --tags ~FC015
8+
- bundle exec rspec --color --format progress
9+
- bundle exec rubocop

Berksfile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ site :opscode
22
metadata
33

44
group :integration do
5-
cookbook "apt"
6-
cookbook "yum"
7-
cookbook "minitest-handler"
8-
cookbook "logrotate_test", :path => "./test/cookbooks/logrotate_test"
5+
cookbook 'apt', '~> 2.0'
6+
cookbook 'fake', path: 'test/fixtures/cookbooks/fake'
97
end

Gemfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
source 'https://rubygems.org'
2+
3+
gem 'berkshelf', '~> 2.0'
4+
gem 'chefspec', '~> 2.0'
5+
gem 'foodcritic', '~> 3.0'
6+
gem 'rubocop', '~> 0.12'
7+
8+
group :integration do
9+
gem 'test-kitchen', '~> 1.0.0.beta'
10+
gem 'kitchen-vagrant', '~> 0.11'
11+
end

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
logrotate Cookbook
22
==================
3+
[![Build Status](https://secure.travis-ci.org/opscode-cookbooks/logrotate.png?branch=master)](http://travis-ci.org/opscode-cookbooks/logrotate)
4+
35
Manages the logrotate package and provides a definition to manage application specific logrotate configuration.
46

57

TESTING.md

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,53 @@
1-
This cookbook includes support for running tests via Test Kitchen (1.0). This has some requirements.
1+
This cookbook uses a variety of testing components:
22

3-
1. You must be using the Git repository, rather than the downloaded cookbook from the Chef Community Site.
4-
2. You must have Vagrant 1.1 installed.
5-
3. You must have a "sane" Ruby 1.9.3 environment.
3+
- Unit tests: [ChefSpec](https://github.com/acrmp/chefspec)
4+
- Integration tests: [Test Kitchen](https://github.com/opscode/test-kitchen)
5+
- Chef Style lints: [Foodcritic](https://github.com/acrmp/foodcritic)
6+
- Ruby Style lints: [Rubocop](https://github.com/bbatsov/rubocop)
67

7-
Once the above requirements are met, install the additional requirements:
88

9-
Install the berkshelf plugin for vagrant, and berkshelf to your local Ruby environment.
9+
Prerequisites
10+
-------------
11+
To develop on this cookbook, you must have a sane Ruby 1.9+ environment. Given the nature of this installation process (and it's variance across multiple operating systems), we will leave this installation process to the user.
1012

11-
vagrant plugin install vagrant-berkshelf
12-
gem install berkshelf
13+
You must also have `bundler` installed:
1314

14-
Install Test Kitchen 1.0 (unreleased yet, use the alpha / prerelease version).
15+
$ gem install bundler
1516

16-
gem install test-kitchen --pre
17+
You must also have Vagrant and VirtualBox installed:
1718

18-
Install the Vagrant driver for Test Kitchen.
19+
- [Vagrant](https://vagrantup.com)
20+
- [VirtualBox](https://virtualbox.org)
1921

20-
gem install kitchen-vagrant
22+
Once installed, you must install the `vagrant-berkshelf` plugin:
2123

22-
Once the above are installed, you should be able to run Test Kitchen:
24+
$ vagrant plugin install vagrant-berkshelf
2325

24-
kitchen list
25-
kitchen test
26+
27+
Development
28+
-----------
29+
1. Clone the git repository from GitHub:
30+
31+
$ git clone [email protected]:opscode-cookbooks/COOKBOOK.git
32+
33+
2. Install the dependencies using bundler:
34+
35+
$ bundle install
36+
37+
3. Create a branch for your changes:
38+
39+
$ git checkout -b my_bug_fix
40+
41+
4. Make any changes
42+
5. Write tests to support those changes. It is highly recommended you write both unit and integration tests.
43+
6. Run the tests:
44+
- `bundle exec rspec`
45+
- `bundle exec foodcritic .`
46+
- `bundle exec rubocop`
47+
- `bundle exec kitchen test`
48+
49+
7. Assuming the tests pass, open a Pull Request on GitHub
50+
8. Open a JIRA ticket for this compontent, linking the JIRA ticket to the Pull Request and visa versa.
51+
9. Mark the JIRA ticket as "Fix Provided"
52+
53+
For more information, see [Opscode's Contribution Guidelines](https://wiki.opscode.com/display/chef/How+to+Contribute).

attributes/default.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
#
2+
# Cookbook Name:: logrotate
3+
# Attribute:: default
4+
#
5+
# Copyright 2013, Opscode
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
120
default['logrotate']['global'] = {
221
'weekly' => true,
322
'rotate' => 4,

definitions/logrotate_app.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
define(:logrotate_app, log_rotate_params) do
3636
include_recipe 'logrotate::default'
3737

38-
acceptable_options = ['missingok', 'compress', 'delaycompress', 'dateext', 'copytruncate', 'notifempty', 'delaycompress', 'ifempty', 'mailfirst', 'nocompress', 'nocopy', 'nocopytruncate', 'nocreate', 'nodelaycompress', 'nomail', 'nomissingok', 'noolddir', 'nosharedscripts', 'notifempty', 'sharedscripts']
39-
options_tmp = params[:options] ||= ["missingok", "compress", "delaycompress", "copytruncate", "notifempty"]
38+
acceptable_options = %w(missingok compress delaycompress dateext copytruncate notifempty delaycompress ifempty mailfirst nocompress nocopy nocopytruncate nocreate nodelaycompress nomail nomissingok noolddir nosharedscripts notifempty sharedscripts)
39+
options_tmp = params[:options] ||= %w(missingok compress delaycompress copytruncate notifempty)
4040
options = options_tmp.respond_to?(:each) ? options_tmp : options_tmp.split
4141

4242
if params[:enable]
@@ -53,7 +53,7 @@
5353
group params[:template_group]
5454
backup false
5555
variables(
56-
:path => Array(params[:path]).map { |path| %Q(#{path}).inspect }.join(' '),
56+
:path => Array(params[:path]).map { |path| path.to_s.inspect }.join(' '),
5757
:create => params[:create],
5858
:frequency => params[:frequency],
5959
:size => params[:size],
@@ -67,7 +67,6 @@
6767
:lastaction => Array(params[:lastaction]).join("\n"),
6868
:options => options
6969
)
70-
notifies :reload, 'service[logrotate]', :delayed
7170
end
7271
else
7372
file "/etc/logrotate.d/#{params[:name]}" do

0 commit comments

Comments
 (0)