Skip to content

Commit

Permalink
Fix Travis CI tests and updates:
Browse files Browse the repository at this point in the history
- Update Berkshelf to 4.
- Update Foodcritic to 6 and fixed new offenses.
- Update RuboCop to 0.41 and fixed new offenses.
- Some testing gem updates.
- Improve TESTING documentation.
- Add `source_url` and `issues_url` to the metadata.
  • Loading branch information
zuazo committed Jul 20, 2016
1 parent feddaee commit 357cceb
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 63 deletions.
22 changes: 14 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
rvm:
- 1.9.3
- 2.0.0
- 2.1
- 2.0.0
- 2.1
- 2.2

sudo: false

env:
- CHEF_VERSION="~> 11.0"
- CHEF_VERSION="~> 12.0"
- CHEF_VERSION="~> 11.0"
- CHEF_VERSION="~> 12.0"

matrix:
exclude:
- rvm: 1.9.3
env: CHEF_VERSION="~> 12.0"
# Gem::InstallError: chef-zero requires Ruby version >= 2.1.0
- rvm: 2.0.0
env: CHEF_VERSION="~> 12.0"

bundler_args: --without doc integration integration_cloud guard

script:
- bundle exec rake travis:ci
- bundle exec rake travis:ci
12 changes: 6 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ end

group :test do
gem 'rake'
gem 'berkshelf', '~> 3.2'
gem 'berkshelf', '~> 4.0'
end

group :style do
gem 'foodcritic', '= 4.0.0'
gem 'rubocop', '= 0.33.0'
gem 'foodcritic', '~> 6.0'
gem 'rubocop', '~> 0.41'
end

group :unit do
gem 'chef', chef_version unless chef_version.nil? # Ruby 1.9.3 support
gem 'simplecov', '~> 0.9'
gem 'should_not', '~> 1.1'
gem 'chefspec', '~> 4.2'
gem 'ohai', '~> 7.4' if RUBY_VERSION < '2'
gem 'rack', '~> 1.0' if RUBY_VERSION < '2.2'
end

group :integration do
Expand All @@ -35,13 +35,13 @@ group :integration do
end

group :integration, :integration_cloud do
gem 'kitchen-ec2', '~> 0.8'
gem 'kitchen-ec2', '~> 1.0'
gem 'kitchen-digitalocean', '~> 0.8'
end

group :guard do
gem 'guard', '~> 2.12'
gem 'guard-foodcritic', '~> 1.1'
gem 'guard-foodcritic', '~> 2.0'
gem 'guard-rubocop', '~> 1.2'
gem 'guard-rspec', '~> 4.6'
# Temporary disabled: Error is: cannot load such file -- guard/kitchen
Expand Down
96 changes: 59 additions & 37 deletions TESTING.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,6 @@
Testing
=======

## Required Gems

* `yard`
* `vagrant`
* `foodcritic`
* `rubocop`
* `berkshelf`
* `simplecov`
* `should_not`
* `chefspec`
* `test-kitchen`
* `kitchen-vagrant`

### Required Gems for Guard

* `guard`
* `guard-foodcritic`
* `guard-rubocop`
* `guard-rspec`
* `guard-kitchen`

More info at [Guard Readme](https://github.com/guard/guard#readme).

## Installing the Requirements

You must have [VirtualBox](https://www.virtualbox.org/) and [Vagrant](http://www.vagrantup.com/) installed.
Expand All @@ -35,35 +12,64 @@ You can install gem dependencies with bundler:

## Generating the Documentation

This will generate the documentation for the source files inside the [*libraries/*](https://github.com/zuazo/ssh_authorized_keys-cookbook/tree/master/libraries) directory.

$ bundle exec rake doc

## Running the Syntax Style Tests
The documentation is included in the source code itself.

## Syntax Style Tests

We use the following tools to test the code style:

* [RuboCop](https://github.com/bbatsov/rubocop#readme)
* [foodcritic](http://www.foodcritic.io/)

To run the tests:

$ bundle exec rake style

## Running the Unit Tests
## Unit Tests

We use [ChefSpec](https://github.com/sethvargo/chefspec#readme) and [RSpec](http://rspec.info/) for the unit tests. RSpec is generally used to test the libraries or some Ruby specific code.

The unit test files are placed in the [*test/unit/*](https://github.com/zuazo/ssh_authorized_keys-cookbook/tree/master/test/unit) directory.

To run the tests:

$ bundle exec rake unit

## Running the Integration Tests
## Integration Tests

We use [Test Kitchen](http://kitchen.ci/) to run the tests and the tests are written using [Serverspec](http://serverspec.org/).

$ bundle exec rake integration
The integration test files are placed in the [*test/integration/*](https://github.com/zuazo/ssh_authorized_keys-cookbook/tree/master/test/integration) directory. Some cookbooks required by this tests are in the [*test/cookbooks/*](https://github.com/zuazo/ssh_authorized_keys-cookbook/tree/master/test/cookbooks) directory.

To run the tests:

$ bundle exec rake integration:vagrant

Or:

$ bundle exec kitchen list
$ bundle exec kitchen test
[...]

### Running Integration Tests in the Cloud
### Integration Tests in Docker

You can run the integration tests using [Docker](https://www.docker.com/) instead of Vagrant if you prefer.

#### Requirements
Of course, you need to have [Docker installed](https://docs.docker.com/engine/installation/).

* `kitchen-vagrant`
* `kitchen-digitalocean`
* `kitchen-ec2`
$ wget -qO- https://get.docker.com/ | sh

You can run the tests in the cloud instead of using vagrant. First, you must set the following environment variables:
Then use the `integration:docker` rake task to run the tests:

$ bundle exec rake integration:docker

### Integration Tests in the Cloud

You can run the tests in the cloud instead of using Vagrant. First, you must set the following environment variables:

* `AWS_ACCESS_KEY_ID`
* `AWS_SECRET_ACCESS_KEY`
Expand All @@ -73,8 +79,24 @@ You can run the tests in the cloud instead of using vagrant. First, you must set
* `DIGITALOCEAN_SSH_KEY_IDS`: DigitalOcean SSH numeric key IDs.
* `DIGITALOCEAN_SSH_KEY_PATH`: DigitalOcean SSH private key local full path. Only when you are not using an SSH Agent.

Then, you must configure test-kitchen to use `.kitchen.cloud.yml` configuration file:
Then use the `integration:cloud` rake task to run the tests:

$ export KITCHEN_LOCAL_YAML=".kitchen.cloud.yml"
$ bundle exec kitchen list
[...]
$ bundle exec rake integration:cloud

## Guard

Guard is a tool that runs the tests automatically while you are making changes to the source files.

To run Guard:

$ guard

More info at [Guard Readme](https://github.com/guard/guard#readme).

## Available Rake Tasks

There are multiple Rake tasks that you can use to run the tests:

$ rake -T

See [Rakefile documentation](https://github.com/ruby/rake/blob/master/doc/rakefile.rdoc) for more information.
25 changes: 13 additions & 12 deletions libraries/resource_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Cookbook Name:: ssh_authorized_keys
# Library:: resource_helpers
# Author:: Xabier de Zuazo (<xabier@zuazo.org>)
# Copyright:: Copyright (c) 2015-2016 Xabier de Zuazo
# Copyright:: Copyright (c) 2015 Onddo Labs, SL.
# License:: Apache License, Version 2.0
#
Expand Down Expand Up @@ -48,9 +49,9 @@ module ResourceHelpers
# @return void
def assert_user(user)
return if user.is_a?(String) && !user.empty?
fail Chef::Exceptions::ValidationFailed,
'ssh_authorize_key: user parameter must be a valid system user! '\
"You passed #{user.inspect}."
raise Chef::Exceptions::ValidationFailed,
'ssh_authorize_key: user parameter must be a valid system user! '\
"You passed #{user.inspect}."
end

# Asserts that the SSH public key is correct.
Expand All @@ -60,9 +61,9 @@ def assert_user(user)
# @return void
def assert_key(key)
return if key.is_a?(String) && !SSH_KEY_REGEX.match(key).nil?
fail Chef::Exceptions::ValidationFailed,
'ssh_authorize_key: key parameter must be a valid SSH public key! '\
"You passed #{key.inspect}."
raise Chef::Exceptions::ValidationFailed,
'ssh_authorize_key: key parameter must be a valid SSH public key! '\
"You passed #{key.inspect}."
end

# Returns allowed SSH key types list.
Expand All @@ -85,9 +86,9 @@ def allowed_keytypes
# @return void
def assert_keytype(keytype)
return if allowed_keytypes.include?(keytype)
fail Chef::Exceptions::ValidationFailed,
'ssh_authorize_key: keytype parameter must be equal to one of: '\
"#{allowed_keytypes.join(', ')}! You passed #{keytype.inspect}."
raise Chef::Exceptions::ValidationFailed,
'ssh_authorize_key: keytype parameter must be equal to one of: '\
"#{allowed_keytypes.join(', ')}! You passed #{keytype.inspect}."
end

# Asserts that the key comment is correct.
Expand All @@ -99,9 +100,9 @@ def assert_comment(comment)
if comment.is_a?(String) && !comment.empty? && !comment.include?("\n")
return
end
fail Chef::Exceptions::ValidationFailed,
'ssh_authorize_key: comment parameter must be valid! You passed '\
"#{comment.inspect}."
raise Chef::Exceptions::ValidationFailed,
'ssh_authorize_key: comment parameter must be valid! You passed '\
"#{comment.inspect}."
end

# Returns the home directory of a system user.
Expand Down
7 changes: 7 additions & 0 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '0.4.0' # WiP

if respond_to?(:source_url)
source_url "https://github.com/zuazo/#{name}-cookbook"
end
if respond_to?(:issues_url)
issues_url "https://github.com/zuazo/#{name}-cookbook/issues"
end

supports 'aix'
supports 'amazon'
supports 'debian'
Expand Down

0 comments on commit 357cceb

Please sign in to comment.