Skip to content

Commit

Permalink
Add Test Kitchen, ChefSpec, RuboCop, and Foodcritic on Travis CI
Browse files Browse the repository at this point in the history
Signed-off-by: Seth Vargo <sethvargo@gmail.com>
  • Loading branch information
sethvargo committed Oct 4, 2013
1 parent ffa2c06 commit e59d759
Show file tree
Hide file tree
Showing 33 changed files with 346 additions and 318 deletions.
21 changes: 14 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
.vagrant
Berksfile.lock
Gemfile.lock
*~
*#
.#*
\#*#
.*.sw[a-z]
*.un~
.bundle
.cache
.kitchen
bin
*.tmp
*.bk
*.bkup
.kitchen.local.yml
Berksfile.lock
Gemfile.lock

.bundle/
.cache/
.kitchen/
.vagrant/
.vagrant.d/
bin/
tmp/
vendor/
19 changes: 5 additions & 14 deletions .kitchen.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
driver_plugin: vagrant
driver_config:
require_chef_omnibus: true
customize:
memory: 1024

platforms:
- name: ubuntu-12.04
run_list:
- recipe[apt::default]
- name: ubuntu-10.04
run_list:
- recipe[apt::default]
- recipe[apt::default]
- name: centos-6.4
- name: centos-5.9

suites:
- name: default
run_list:
- recipe[logrotate_test::default]
- recipe[minitest-handler::default]
- recipe[logrotate::default]
- name: definition
run_list:
- recipe[fake::definition]
- name: global
run_list:
- recipe[logrotate::global]
- recipe[minitest-handler::default]
- name: definition
run_list:
- recipe[logrotate_test::logrotate_app]
- recipe[minitest-handler::default]
14 changes: 14 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
AllCops:
Excludes:
- vendor/**

AlignParameters:
Enabled: false
Encoding:
Enabled: false
HashSyntax:
Enabled: false
LineLength:
Enabled: false
MethodLength:
Max: 30
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
rvm:
- 1.9.3
- 2.0.0
before_script:
- bundle exec berks install
script:
- bundle exec foodcritic -f any . --tags ~FC015
- bundle exec rspec --color --format progress
- bundle exec rubocop
6 changes: 2 additions & 4 deletions Berksfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ site :opscode
metadata

group :integration do
cookbook "apt"
cookbook "yum"
cookbook "minitest-handler"
cookbook "logrotate_test", :path => "./test/cookbooks/logrotate_test"
cookbook 'apt', '~> 2.0'
cookbook 'fake', path: 'test/fixtures/cookbooks/fake'
end
11 changes: 11 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
source 'https://rubygems.org'

gem 'berkshelf', '~> 2.0'
gem 'chefspec', '~> 2.0'
gem 'foodcritic', '~> 3.0'
gem 'rubocop', '~> 0.12'

group :integration do
gem 'test-kitchen', '~> 1.0.0.beta'
gem 'kitchen-vagrant', '~> 0.11'
end
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
logrotate Cookbook
==================
[![Build Status](https://secure.travis-ci.org/opscode-cookbooks/logrotate.png?branch=master)](http://travis-ci.org/opscode-cookbooks/logrotate)

Manages the logrotate package and provides a definition to manage application specific logrotate configuration.


Expand Down
58 changes: 43 additions & 15 deletions TESTING.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,53 @@
This cookbook includes support for running tests via Test Kitchen (1.0). This has some requirements.
This cookbook uses a variety of testing components:

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

Once the above requirements are met, install the additional requirements:

Install the berkshelf plugin for vagrant, and berkshelf to your local Ruby environment.
Prerequisites
-------------
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.

vagrant plugin install vagrant-berkshelf
gem install berkshelf
You must also have `bundler` installed:

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

gem install test-kitchen --pre
You must also have Vagrant and VirtualBox installed:

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

gem install kitchen-vagrant
Once installed, you must install the `vagrant-berkshelf` plugin:

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

kitchen list
kitchen test

Development
-----------
1. Clone the git repository from GitHub:

$ git clone git@github.com:opscode-cookbooks/COOKBOOK.git

2. Install the dependencies using bundler:

$ bundle install

3. Create a branch for your changes:

$ git checkout -b my_bug_fix

4. Make any changes
5. Write tests to support those changes. It is highly recommended you write both unit and integration tests.
6. Run the tests:
- `bundle exec rspec`
- `bundle exec foodcritic .`
- `bundle exec rubocop`
- `bundle exec kitchen test`

7. Assuming the tests pass, open a Pull Request on GitHub
8. Open a JIRA ticket for this compontent, linking the JIRA ticket to the Pull Request and visa versa.
9. Mark the JIRA ticket as "Fix Provided"

For more information, see [Opscode's Contribution Guidelines](https://wiki.opscode.com/display/chef/How+to+Contribute).
19 changes: 19 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
#
# Cookbook Name:: logrotate
# Attribute:: default
#
# Copyright 2013, Opscode
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

default['logrotate']['global'] = {
'weekly' => true,
'rotate' => 4,
Expand Down
7 changes: 3 additions & 4 deletions definitions/logrotate_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
define(:logrotate_app, log_rotate_params) do
include_recipe 'logrotate::default'

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

if params[:enable]
Expand All @@ -53,7 +53,7 @@
group params[:template_group]
backup false
variables(
:path => Array(params[:path]).map { |path| %Q(#{path}).inspect }.join(' '),
:path => Array(params[:path]).map { |path| path.to_s.inspect }.join(' '),
:create => params[:create],
:frequency => params[:frequency],
:size => params[:size],
Expand All @@ -67,7 +67,6 @@
:lastaction => Array(params[:lastaction]).join("\n"),
:options => options
)
notifies :reload, 'service[logrotate]', :delayed
end
else
file "/etc/logrotate.d/#{params[:name]}" do
Expand Down
80 changes: 50 additions & 30 deletions libraries/logrotate_config.rb
Original file line number Diff line number Diff line change
@@ -1,42 +1,62 @@
#
# Cookbook Name:: logrotate
# Library:: CookbookLogrotate
#
# Copyright 2013, Opscode
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

module CookbookLogrotate
DIRECTIVES = %w[
compress copy copytruncate daily dateext
delaycompress ifempty mailfirst maillast missingok
monthly nocompress nocopy nocopytruncate nocreate
nodelaycompress nodateext nomail nomissingok noolddir
nosharedscripts noshred notifempty sharedscripts shred
weekly yearly
]
compress copy copytruncate daily dateext
delaycompress ifempty mailfirst maillast missingok
monthly nocompress nocopy nocopytruncate nocreate
nodelaycompress nodateext nomail nomissingok noolddir
nosharedscripts noshred notifempty sharedscripts shred
weekly yearly
]

VALUES = %w[
compresscmd uncompresscmd compressext compressoptions
create dateformat include mail
maxage minsize rotate size
shredcycles start tabooext
]
compresscmd uncompresscmd compressext compressoptions
create dateformat include mail
maxage minsize rotate size
shredcycles start tabooext
]

SCRIPTS = [ 'firstaction', 'prerotate', 'postrotate', 'lastaction', ]
SCRIPTS = %w[firstaction prerotate postrotate lastaction]

DIRECTIVES_AND_VALUES = DIRECTIVES + VALUES

# Helper class for creating configurations
class LogrotateConfiguration
attr_reader :directives, :values, :paths

class << self
def from_hash hash
return LogrotateConfiguration.new hash
def from_hash(hash)
new(hash)
end

def directives_from hash
def directives_from(hash)
hash.select { |k, v| DIRECTIVES.include?(k) && v }.keys
end

def values_from hash
hash.select { |k| VALUES.include? k }
def values_from(hash)
hash.select { |k| VALUES.include?(k) }
end

def paths_from hash
hash.select { |k| !(DIRECTIVES_AND_VALUES.include? k) }.inject({}) do | accum_paths, (path, config) |
def paths_from(hash)
hash.select { |k| !(DIRECTIVES_AND_VALUES.include?(k)) }.reduce({}) do | accum_paths, (path, config) |
accum_paths[path] = {
'directives' => directives_from(config),
'values' => values_from(config),
Expand All @@ -47,11 +67,11 @@ def paths_from hash
end
end

def scripts_from hash
defined_scripts = hash.select { |k| SCRIPTS.include? k }
defined_scripts.inject({}) do | accum_scripts, (script, lines) |
if lines.respond_to? :join
accum_scripts[script] = lines.join "\n"
def scripts_from(hash)
defined_scripts = hash.select { |k| SCRIPTS.include?(k) }
defined_scripts.reduce({}) do | accum_scripts, (script, lines) |
if lines.respond_to?(:join)
accum_scripts[script] = lines.join("\n")
else
accum_scripts[script] = lines
end
Expand All @@ -63,10 +83,10 @@ def scripts_from hash

private

def initialize hash
@directives = LogrotateConfiguration.directives_from hash
@values = LogrotateConfiguration.values_from hash
@paths = LogrotateConfiguration.paths_from hash
end
def initialize(hash)
@directives = LogrotateConfiguration.directives_from(hash)
@values = LogrotateConfiguration.values_from(hash)
@paths = LogrotateConfiguration.paths_from(hash)
end
end
end
26 changes: 15 additions & 11 deletions metadata.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
name "logrotate"
maintainer "Opscode, Inc."
maintainer_email "cookbooks@opscode.com"
license "Apache 2.0"
description "Installs logrotate package and provides a definition for logrotate configs"
name 'logrotate'
maintainer 'Opscode, Inc.'
maintainer_email 'cookbooks@opscode.com'
license 'Apache 2.0'
description 'Installs logrotate package and provides a definition for logrotate configs'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "1.3.1"
version '1.3.1'

recipe "logrotate", "Installs logrotate package"
provides "logrotate_app"
recipe 'logrotate', 'Installs logrotate package'
provides 'logrotate_app'

%w{ redhat centos debian ubuntu scientific amazon fedora }.each do |os|
supports os
end
supports 'amazon'
supports 'centos'
supports 'debian'
supports 'fedora'
supports 'redhat'
supports 'scientific'
supports 'ubuntu'
Loading

0 comments on commit e59d759

Please sign in to comment.