diff --git a/.gitignore b/.gitignore index ed54970..bab42a4 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ metadata.json .sandbox .bundle +.kitchen/ +.kitchen.local.yml diff --git a/.kitchen.yml b/.kitchen.yml new file mode 100644 index 0000000..aa2b4be --- /dev/null +++ b/.kitchen.yml @@ -0,0 +1,20 @@ +--- +driver: + name: vagrant + +provisioner: + name: chef_solo + +platforms: + - name: ubuntu-12.04 + - name: centos-6.4 + +suites: + - name: default + run_list: + - recipe[test_php-fpm::default] + attributes: + php-fpm: + pools: + - name: www + listen: '127.0.0.1:9000' diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..ba74614 --- /dev/null +++ b/.rspec @@ -0,0 +1,3 @@ +--default_path test/unit +--color +--format documentation diff --git a/.ruby-version b/.ruby-version deleted file mode 100644 index 0ca8caf..0000000 --- a/.ruby-version +++ /dev/null @@ -1 +0,0 @@ -1.9.3-p327 diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..2a49a53 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +language: ruby +rvm: + - 2.1 +bundler_args: --without integration diff --git a/Berksfile b/Berksfile new file mode 100644 index 0000000..e1df000 --- /dev/null +++ b/Berksfile @@ -0,0 +1,4 @@ +source "https://api.berkshelf.com" + +metadata +cookbook 'test_php-fpm', path: './test/integration/cookbooks/test_php-fpm' diff --git a/Berksfile.lock b/Berksfile.lock new file mode 100644 index 0000000..fbd8e8e --- /dev/null +++ b/Berksfile.lock @@ -0,0 +1,16 @@ +DEPENDENCIES + php-fpm + path: . + metadata: true + test_php-fpm + path: test/integration/cookbooks/test_php-fpm + +GRAPH + apt (2.3.10) + php-fpm (0.6.6) + apt (>= 0.0.0) + yum (>= 0.0.0) + test_php-fpm (0.1.0) + apt (>= 0.0.0) + php-fpm (>= 0.0.0) + yum (3.2.0) diff --git a/Gemfile b/Gemfile index f32b162..5b8f48b 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,8 @@ source "http://rubygems.org" gem 'rake' -gem "chef", "~> 10.12.0" -gem 'knife-ec2' +gem "chefspec" gem "moneta", "~> 0.6.0" gem 'stove', '~> 2.0.0' +gem 'test-kitchen' +gem 'kitchen-vagrant' diff --git a/Gemfile.lock b/Gemfile.lock index 6234a64..a3ff9d1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,76 +2,73 @@ GEM remote: http://rubygems.org/ specs: addressable (2.3.6) - amq-protocol (1.9.2) - builder (3.2.2) - bunny (1.2.1) - amq-protocol (>= 1.9.2) - chef (10.12.0) - bunny (>= 0.6.0) - erubis - highline (>= 1.6.9) - json (>= 1.4.4, <= 1.6.1) - mixlib-authentication (>= 1.1.0) - mixlib-cli (>= 1.1.0) - mixlib-config (>= 1.1.2) - mixlib-log (>= 1.3.0) - mixlib-shellout - moneta - net-ssh (~> 2.2.2) - net-ssh-multi (~> 1.1.0) - ohai (>= 0.6.0) + chef (11.12.4) + chef-zero (~> 2.0, >= 2.0.2) + diff-lcs (~> 1.2, >= 1.2.4) + erubis (~> 2.7) + highline (~> 1.6, >= 1.6.9) + json (>= 1.4.4, <= 1.8.1) + mime-types (~> 1.16) + mixlib-authentication (~> 1.3) + mixlib-cli (~> 1.4) + mixlib-config (~> 2.0) + mixlib-log (~> 1.3) + mixlib-shellout (~> 1.4) + net-ssh (~> 2.6) + net-ssh-multi (~> 1.1) + ohai (~> 7.0.4) + pry (~> 0.9) rest-client (>= 1.0.4, < 1.7.0) - treetop (~> 1.4.9) - uuidtools yajl-ruby (~> 1.1) + chef-zero (2.0.2) + hashie (~> 2.0) + json + mixlib-log (~> 1.3) + rack + chefspec (3.4.0) + chef (~> 11.0) + fauxhai (~> 2.0) + rspec (~> 2.14) + coderay (1.1.0) + diff-lcs (1.2.5) erubis (2.7.0) - excon (0.33.0) faraday (0.8.9) multipart-post (~> 1.2.0) faraday_middleware (0.9.0) faraday (>= 0.7.4, < 0.9) - fog (1.9.0) - builder - excon (~> 0.14) - formatador (~> 0.2.0) - mime-types - multi_json (~> 1.0) - net-scp (~> 1.0.4) - net-ssh (>= 2.1.3) - nokogiri (~> 1.5.0) - ruby-hmac - formatador (0.2.4) + fauxhai (2.1.2) + net-ssh + ohai + hashie (2.1.1) highline (1.6.21) i18n (0.6.9) ipaddress (0.8.0) - json (1.6.1) - knife-ec2 (0.6.4) - chef (>= 0.10.10) - fog (~> 1.6) + json (1.8.1) + kitchen-vagrant (0.15.0) + test-kitchen (~> 1.0) logify (0.2.0) + method_source (0.8.2) mime-types (1.25.1) minitar (0.5.4) mixlib-authentication (1.3.0) mixlib-log - mixlib-cli (1.4.0) + mixlib-cli (1.5.0) mixlib-config (2.1.0) mixlib-log (1.6.0) mixlib-shellout (1.4.0) moneta (0.6.0) - multi_json (1.9.2) multipart-post (1.2.0) - net-scp (1.0.4) - net-ssh (>= 1.99.1) - net-ssh (2.2.2) - net-ssh-gateway (1.1.0) - net-ssh (>= 1.99.1) - net-ssh-multi (1.1) - net-ssh (>= 2.1.4) - net-ssh-gateway (>= 0.99.0) - nokogiri (1.5.11) + net-scp (1.2.1) + net-ssh (>= 2.6.5) + net-ssh (2.9.0) + net-ssh-gateway (1.2.0) + net-ssh (>= 2.6.5) + net-ssh-multi (1.2.0) + net-ssh (>= 2.6.5) + net-ssh-gateway (>= 1.2.0) octokit (3.0.0) sawyer (~> 0.5.3) - ohai (7.0.2) + ohai (7.0.4) ipaddress mime-types (~> 1.16) mixlib-cli @@ -80,14 +77,27 @@ GEM mixlib-shellout (~> 1.2) systemu (~> 2.5.2) yajl-ruby - polyglot (0.3.4) + pry (0.9.12.6) + coderay (~> 1.0) + method_source (~> 0.8) + slop (~> 3.4) + rack (1.5.2) rake (10.0.3) rest-client (1.6.7) mime-types (>= 1.16) - ruby-hmac (0.4.0) + rspec (2.14.1) + rspec-core (~> 2.14.0) + rspec-expectations (~> 2.14.0) + rspec-mocks (~> 2.14.0) + rspec-core (2.14.8) + rspec-expectations (2.14.5) + diff-lcs (>= 1.1.3, < 2.0) + rspec-mocks (2.14.6) + safe_yaml (1.0.3) sawyer (0.5.4) addressable (~> 2.3.5) faraday (~> 0.8, < 0.10) + slop (3.5.0) solve (0.8.2) stove (2.0.0) faraday (~> 0.8.9) @@ -99,18 +109,22 @@ GEM octokit (~> 3.0) solve (~> 0.8) systemu (2.5.2) - treetop (1.4.15) - polyglot - polyglot (>= 0.3.1) - uuidtools (2.1.4) + test-kitchen (1.2.1) + mixlib-shellout (~> 1.2) + net-scp (~> 1.1) + net-ssh (~> 2.7) + safe_yaml (~> 1.0) + thor (~> 0.18) + thor (0.19.1) yajl-ruby (1.2.0) PLATFORMS ruby DEPENDENCIES - chef (~> 10.12.0) - knife-ec2 + chefspec + kitchen-vagrant moneta (~> 0.6.0) rake stove (~> 2.0.0) + test-kitchen diff --git a/Rakefile b/Rakefile index a656e0f..da04e3e 100644 --- a/Rakefile +++ b/Rakefile @@ -81,3 +81,10 @@ EOH sh %{ vagrant ssh } end end + +begin + require 'kitchen/rake_tasks' + Kitchen::RakeTasks.new +rescue LoadError + puts ">>>>> Kitchen gem not loaded, omitting tasks" unless ENV['CI'] +end diff --git a/attributes/default.rb b/attributes/default.rb index 7743e50..0f84634 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -36,6 +36,7 @@ :name => "www" } ] - +default['php-fpm']['package_name'] = nil +default['php-fpm']['service_name'] = nil default['php-fpm']['yum_url'] = "http://rpms.famillecollet.com/enterprise/$releasever/remi/$basearch/" default['php-fpm']['yum_mirrorlist'] = "http://rpms.famillecollet.com/enterprise/$releasever/remi/mirror" diff --git a/test/integration/cookbooks/test_php-fpm/.kitchen.yml b/test/integration/cookbooks/test_php-fpm/.kitchen.yml new file mode 100644 index 0000000..9cea987 --- /dev/null +++ b/test/integration/cookbooks/test_php-fpm/.kitchen.yml @@ -0,0 +1,16 @@ +--- +driver: + name: vagrant + +provisioner: + name: chef_solo + +platforms: + - name: ubuntu-12.04 + - name: centos-6.4 + +suites: + - name: default + run_list: + - recipe[bar::default] + attributes: diff --git a/test/integration/cookbooks/test_php-fpm/Berksfile b/test/integration/cookbooks/test_php-fpm/Berksfile new file mode 100644 index 0000000..9ac9751 --- /dev/null +++ b/test/integration/cookbooks/test_php-fpm/Berksfile @@ -0,0 +1,4 @@ +source "https://api.berkshelf.com" + +metadata +cookbook 'php-fpm', path: '../../../../' diff --git a/test/integration/cookbooks/test_php-fpm/README.md b/test/integration/cookbooks/test_php-fpm/README.md new file mode 100644 index 0000000..0bd56e2 --- /dev/null +++ b/test/integration/cookbooks/test_php-fpm/README.md @@ -0,0 +1,4 @@ +# bar-cookbook + +TODO: Enter the cookbook description here. + diff --git a/test/integration/cookbooks/test_php-fpm/chefignore b/test/integration/cookbooks/test_php-fpm/chefignore new file mode 100644 index 0000000..a6de142 --- /dev/null +++ b/test/integration/cookbooks/test_php-fpm/chefignore @@ -0,0 +1,96 @@ +# Put files/directories that should be ignored in this file when uploading +# or sharing to the community site. +# Lines that start with '# ' are comments. + +# OS generated files # +###################### +.DS_Store +Icon? +nohup.out +ehthumbs.db +Thumbs.db + +# SASS # +######## +.sass-cache + +# EDITORS # +########### +\#* +.#* +*~ +*.sw[a-z] +*.bak +REVISION +TAGS* +tmtags +*_flymake.* +*_flymake +*.tmproj +.project +.settings +mkmf.log + +## COMPILED ## +############## +a.out +*.o +*.pyc +*.so +*.com +*.class +*.dll +*.exe +*/rdoc/ + +# Testing # +########### +.watchr +.rspec +spec/* +spec/fixtures/* +test/* +features/* +Guardfile +Procfile + +# SCM # +####### +.git +*/.git +.gitignore +.gitmodules +.gitconfig +.gitattributes +.svn +*/.bzr/* +*/.hg/* +*/.svn/* + +# Berkshelf # +############# +Berksfile +Berksfile.lock +cookbooks/* +tmp + +# Cookbooks # +############# +CONTRIBUTING +CHANGELOG* + +# Strainer # +############ +Colanderfile +Strainerfile +.colander +.strainer + +# Vagrant # +########### +.vagrant +Vagrantfile + +# Travis # +########## +.travis.yml diff --git a/test/integration/cookbooks/test_php-fpm/metadata.rb b/test/integration/cookbooks/test_php-fpm/metadata.rb new file mode 100644 index 0000000..99d9702 --- /dev/null +++ b/test/integration/cookbooks/test_php-fpm/metadata.rb @@ -0,0 +1,10 @@ +name 'test_php-fpm' +maintainer '' +maintainer_email '' +license '' +description 'Installs/Configures test_php-fpm' +long_description 'Installs/Configures test_php-fpm' +version '0.1.0' + +depends 'php-fpm' +depends 'apt' diff --git a/test/integration/cookbooks/test_php-fpm/recipes/default.rb b/test/integration/cookbooks/test_php-fpm/recipes/default.rb new file mode 100644 index 0000000..d8d8b0c --- /dev/null +++ b/test/integration/cookbooks/test_php-fpm/recipes/default.rb @@ -0,0 +1,12 @@ +# +# Cookbook Name:: test_php-fpm +# Recipe:: default +# +# Copyright (C) 2014 +# +# + +include_recipe 'apt' if platform_family?('debian') +execute 'yum update -y -q' if platform_family?('rhel', 'fedora') + +include_recipe 'php-fpm' diff --git a/test/integration/default/bats/php_fpm_running.bats b/test/integration/default/bats/php_fpm_running.bats new file mode 100644 index 0000000..39a3570 --- /dev/null +++ b/test/integration/default/bats/php_fpm_running.bats @@ -0,0 +1,5 @@ +#!/usr/bin/env bats + +@test php_fpm_running { + run "ps aux | grep -v grep | grep php-fpm" +} diff --git a/test/unit/default/package_spec.rb b/test/unit/default/package_spec.rb new file mode 100644 index 0000000..d6e9d8d --- /dev/null +++ b/test/unit/default/package_spec.rb @@ -0,0 +1,25 @@ +require_relative '../spec_helper.rb' + +describe 'php-fpm::default' do + before do + %w( /etc/php-fpm.d /etc/php5/fpm/pool.d ).each do |dir| + stub_command("test -d #{dir} || mkdir -p #{dir}").and_return(true) + end + end + + context 'debian' do + let(:chef_run) { ChefSpec::Runner.new(platform: 'ubuntu', version: '12.04').converge(described_recipe)} + + it 'installs php5-fpm' do + expect(chef_run).to upgrade_package('php5-fpm') + end + end + + context 'rhel' do + let(:chef_run) { ChefSpec::Runner.new(platform: 'centos', version: '6.4').converge(described_recipe)} + + it 'installs php-fpm' do + expect(chef_run).to upgrade_package('php-fpm') + end + end +end diff --git a/test/unit/package.rb b/test/unit/package.rb new file mode 100644 index 0000000..f57ef1d --- /dev/null +++ b/test/unit/package.rb @@ -0,0 +1,15 @@ +require_relative '../spec_helper.rb' + +describe 'php-fpm::default' do + let(:chef_run) { ChefSpec::Runner.new(platform: 'ubuntu', version: '12.04').converge(described_recipe)} + + it 'installs php-fpm' do + expect(chef_run).to install_package('php5-fpm') + end + + let(:chef_run) { ChefSpec::Runner.new(platform: 'centos', version: '6.4').converge(described_recipe)} + + it 'installs php-fpm' do + expect(chef_run).to install_package('php-fpm') + end +end diff --git a/test/unit/spec_helper.rb b/test/unit/spec_helper.rb new file mode 100644 index 0000000..1dd5126 --- /dev/null +++ b/test/unit/spec_helper.rb @@ -0,0 +1,2 @@ +require 'chefspec' +require 'chefspec/berkshelf'