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

Diff for: .gitignore

+14-7
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/

Diff for: .kitchen.yml

+5-14
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]

Diff for: .rubocop.yml

+14
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

Diff for: .travis.yml

+9
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

Diff for: Berksfile

+2-4
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

Diff for: Gemfile

+11
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

Diff for: README.md

+2
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

Diff for: TESTING.md

+43-15
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).

Diff for: attributes/default.rb

+19
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,

Diff for: definitions/logrotate_app.rb

+3-4
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

Diff for: libraries/logrotate_config.rb

+50-30
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,62 @@
1+
#
2+
# Cookbook Name:: logrotate
3+
# Library:: CookbookLogrotate
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
module CookbookLogrotate
221
DIRECTIVES = %w[
3-
compress copy copytruncate daily dateext
4-
delaycompress ifempty mailfirst maillast missingok
5-
monthly nocompress nocopy nocopytruncate nocreate
6-
nodelaycompress nodateext nomail nomissingok noolddir
7-
nosharedscripts noshred notifempty sharedscripts shred
8-
weekly yearly
9-
]
22+
compress copy copytruncate daily dateext
23+
delaycompress ifempty mailfirst maillast missingok
24+
monthly nocompress nocopy nocopytruncate nocreate
25+
nodelaycompress nodateext nomail nomissingok noolddir
26+
nosharedscripts noshred notifempty sharedscripts shred
27+
weekly yearly
28+
]
1029

1130
VALUES = %w[
12-
compresscmd uncompresscmd compressext compressoptions
13-
create dateformat include mail
14-
maxage minsize rotate size
15-
shredcycles start tabooext
16-
]
31+
compresscmd uncompresscmd compressext compressoptions
32+
create dateformat include mail
33+
maxage minsize rotate size
34+
shredcycles start tabooext
35+
]
1736

18-
SCRIPTS = [ 'firstaction', 'prerotate', 'postrotate', 'lastaction', ]
37+
SCRIPTS = %w[firstaction prerotate postrotate lastaction]
1938

2039
DIRECTIVES_AND_VALUES = DIRECTIVES + VALUES
2140

41+
# Helper class for creating configurations
2242
class LogrotateConfiguration
2343
attr_reader :directives, :values, :paths
2444

2545
class << self
26-
def from_hash hash
27-
return LogrotateConfiguration.new hash
46+
def from_hash(hash)
47+
new(hash)
2848
end
2949

30-
def directives_from hash
50+
def directives_from(hash)
3151
hash.select { |k, v| DIRECTIVES.include?(k) && v }.keys
3252
end
3353

34-
def values_from hash
35-
hash.select { |k| VALUES.include? k }
54+
def values_from(hash)
55+
hash.select { |k| VALUES.include?(k) }
3656
end
3757

38-
def paths_from hash
39-
hash.select { |k| !(DIRECTIVES_AND_VALUES.include? k) }.inject({}) do | accum_paths, (path, config) |
58+
def paths_from(hash)
59+
hash.select { |k| !(DIRECTIVES_AND_VALUES.include?(k)) }.reduce({}) do | accum_paths, (path, config) |
4060
accum_paths[path] = {
4161
'directives' => directives_from(config),
4262
'values' => values_from(config),
@@ -47,11 +67,11 @@ def paths_from hash
4767
end
4868
end
4969

50-
def scripts_from hash
51-
defined_scripts = hash.select { |k| SCRIPTS.include? k }
52-
defined_scripts.inject({}) do | accum_scripts, (script, lines) |
53-
if lines.respond_to? :join
54-
accum_scripts[script] = lines.join "\n"
70+
def scripts_from(hash)
71+
defined_scripts = hash.select { |k| SCRIPTS.include?(k) }
72+
defined_scripts.reduce({}) do | accum_scripts, (script, lines) |
73+
if lines.respond_to?(:join)
74+
accum_scripts[script] = lines.join("\n")
5575
else
5676
accum_scripts[script] = lines
5777
end
@@ -63,10 +83,10 @@ def scripts_from hash
6383

6484
private
6585

66-
def initialize hash
67-
@directives = LogrotateConfiguration.directives_from hash
68-
@values = LogrotateConfiguration.values_from hash
69-
@paths = LogrotateConfiguration.paths_from hash
70-
end
86+
def initialize(hash)
87+
@directives = LogrotateConfiguration.directives_from(hash)
88+
@values = LogrotateConfiguration.values_from(hash)
89+
@paths = LogrotateConfiguration.paths_from(hash)
90+
end
7191
end
7292
end

Diff for: metadata.rb

+15-11
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
name "logrotate"
2-
maintainer "Opscode, Inc."
3-
maintainer_email "[email protected]"
4-
license "Apache 2.0"
5-
description "Installs logrotate package and provides a definition for logrotate configs"
1+
name 'logrotate'
2+
maintainer 'Opscode, Inc.'
3+
maintainer_email '[email protected]'
4+
license 'Apache 2.0'
5+
description 'Installs logrotate package and provides a definition for logrotate configs'
66
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
7-
version "1.3.1"
7+
version '1.3.1'
88

9-
recipe "logrotate", "Installs logrotate package"
10-
provides "logrotate_app"
9+
recipe 'logrotate', 'Installs logrotate package'
10+
provides 'logrotate_app'
1111

12-
%w{ redhat centos debian ubuntu scientific amazon fedora }.each do |os|
13-
supports os
14-
end
12+
supports 'amazon'
13+
supports 'centos'
14+
supports 'debian'
15+
supports 'fedora'
16+
supports 'redhat'
17+
supports 'scientific'
18+
supports 'ubuntu'

0 commit comments

Comments
 (0)