add test-kitchen example

This commit is contained in:
Christoph Hartmann 2015-10-21 12:56:45 +02:00
parent 44e8c0db54
commit ca92e29575
9 changed files with 146 additions and 0 deletions

1
.gitignore vendored
View file

@ -4,3 +4,4 @@ coverage
.gallery
.kitchen
.delivery/cli.toml
Berksfile.lock

View file

@ -0,0 +1,20 @@
---
driver:
name: vagrant
provisioner:
name: chef_solo
verifier:
name: InSpec
platforms:
- name: centos-7.1
- name: ubuntu-12.04
- name: ubuntu-14.04
suites:
- name: default
run_list:
- recipe[prepare]
attributes:

View file

@ -0,0 +1,3 @@
source 'https://supermarket.chef.io'
metadata

View file

@ -0,0 +1,21 @@
# encoding: utf-8
source 'https://rubygems.org'
gem 'vulcano', path: '../../.'
gem 'train', git: 'git@github.com:chef/train.git'
group :test do
gem 'bundler', '~> 1.5'
gem 'minitest', '~> 5.5'
gem 'rake', '~> 10'
gem 'rubocop', '~> 0.33.0'
gem 'simplecov', '~> 0.10'
end
group :integration do
gem 'berkshelf', '~> 4.0'
gem 'test-kitchen', '~> 1.4'
gem 'kitchen-vagrant'
gem 'kitchen-inspec', git: 'git@github.com:chef/kitchen-inspec.git'
gem 'concurrent-ruby', '~> 0.9'
end

View file

@ -0,0 +1,27 @@
# InSpec Test-Kitchen Example
This example demonstrates a complete roundtrip via [Test-Kitchen](http://kitchen.ci/).
```bash
# install all dependencies
$ bundle install
# show all available tests
$ bundle exec kitchen list
Instance Driver Provisioner Verifier Transport Last Action
default-centos-71 Vagrant ChefSolo InSpec Ssh <Not Created>
default-ubuntu-1204 Vagrant ChefSolo InSpec Ssh <Not Created>
default-ubuntu-1404 Vagrant ChefSolo InSpec Ssh <Not Created>
# Now we are ready to run a complete test
$ bundle exec kitchen test default-ubuntu-1404
-----> Starting Kitchen (v1.4.2)
-----> Verifying <default-ubuntu-1404>...
...
Finished in 0.03241 seconds (files took 0.22475 seconds to load)
5 examples, 0 failures
Finished verifying <default-ubuntu-1404> (0m0.16s).
-----> Kitchen is finished. (0m0.82s)
```

View file

@ -0,0 +1,7 @@
name 'prepare'
maintainer 'Chef Software, Inc.'
maintainer_email 'support@chef.io'
description 'This cookbook prepares the test operating systems'
version '1.0.0'
depends 'apt'
depends 'yum'

View file

@ -0,0 +1,6 @@
# encoding: utf-8
# author: Christoph Hartmann
# author: Dominik Richter
# install nginx
include_recipe('prepare::nginx')

View file

@ -0,0 +1,30 @@
# encoding: utf-8
# author: Christoph Hartmann
# author: Dominik Richter
# install repositories for nginx
case node['platform']
when 'ubuntu'
include_recipe('apt')
# if ubuntu, install
apt_repository 'nginx-php' do
uri 'ppa:nginx/stable'
distribution node['lsb']['codename']
end
when 'centos'
# add repo for Centos 7
yum_repository 'nginx' do
description 'Nginx Repo'
baseurl 'http://nginx.org/packages/centos/7/x86_64'
gpgkey 'http://nginx.org/keys/nginx_signing.key'
action :create
end
end
# install nginx package
package 'nginx'
# start the service
service 'nginx' do
action :start
end

View file

@ -0,0 +1,31 @@
# encoding: utf-8
# author: Christoph Hartmann
# author: Dominik Richter
# use basic tests
describe package('nginx') do
it { should be_installed }
end
# extend tests with metadata
rule '01' do
impact 0.7
title 'Verify nginx service'
desc 'Ensures nginx service is up and running'
describe service('nginx') do
it { should be_enabled }
it { should be_installed }
it { should be_running }
end
end
# implement os dependent tests
if ['ubuntu'].include?(os[:family])
web_user = 'www-data'
elsif ['centos'].include?(os[:family])
web_user = 'nginx'
end
describe user(web_user) do
it { should exist }
end