From f383f00a5debcdcda0dc8df74a128aae8c1ca05d Mon Sep 17 00:00:00 2001 From: paulczar Date: Sat, 11 Jan 2014 12:26:02 -0600 Subject: [PATCH] cleanup of testing environment --- .rubocop.yml | 8 ++- .travis.yml | 3 +- Berksfile | 15 +++-- Gemfile | 4 +- README.md | 7 +-- Rakefile | 63 ++++++++++++------- Strainerfile | 2 +- Vagrantfile | 27 ++++---- .../server/serverspec/server_spec.rb | 7 ++- .../server/serverspec/spec_helper.rb | 3 +- test/support/Gemfile | 18 +++--- {spec => test/unit/spec}/agent_spec.rb | 5 +- {spec => test/unit/spec}/beaver_spec.rb | 5 +- {spec => test/unit/spec}/default_spec.rb | 5 +- {spec => test/unit/spec}/haproxy_spec.rb | 5 +- {spec => test/unit/spec}/index_cleaer_spec.rb | 5 +- {spec => test/unit/spec}/pyshipper_spec.rb | 0 {spec => test/unit/spec}/server_spec.rb | 5 +- {spec => test/unit/spec}/source_spec.rb | 5 +- {spec => test/unit/spec}/spec_helper.rb | 2 + {spec => test/unit/spec}/zero_mq_repo.rb | 5 +- 21 files changed, 100 insertions(+), 99 deletions(-) rename {spec => test/unit/spec}/agent_spec.rb (63%) rename {spec => test/unit/spec}/beaver_spec.rb (63%) rename {spec => test/unit/spec}/default_spec.rb (63%) rename {spec => test/unit/spec}/haproxy_spec.rb (63%) rename {spec => test/unit/spec}/index_cleaer_spec.rb (63%) rename {spec => test/unit/spec}/pyshipper_spec.rb (100%) rename {spec => test/unit/spec}/server_spec.rb (63%) rename {spec => test/unit/spec}/source_spec.rb (63%) rename {spec => test/unit/spec}/spec_helper.rb (89%) rename {spec => test/unit/spec}/zero_mq_repo.rb (63%) diff --git a/.rubocop.yml b/.rubocop.yml index cf48bc1..33c419c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,8 +1,12 @@ AllCops: Excludes: - vendor - - test/support/vendor/** - + - test/support/** + Includes: + - Rakefile + - Gemfile + - Vagrantfile + - Berksfile CyclomaticComplexity: Enabled: false diff --git a/.travis.yml b/.travis.yml index ff570d9..e88cf5e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,4 +3,5 @@ gemfile: - test/support/Gemfile rvm: - 1.9.3 -script: BUNDLE_GEMFILE=$PWD/test/support/Gemfile bundle exec rake install_deps strainer \ No newline at end of file +install: BUNDLE_GEMFILE=$PWD/test/support/Gemfile bundle install +script: BUNDLE_GEMFILE=$PWD/test/support/Gemfile bundle exec rake strainer \ No newline at end of file diff --git a/Berksfile b/Berksfile index 7244ffc..d3a195b 100644 --- a/Berksfile +++ b/Berksfile @@ -1,14 +1,13 @@ -metadata +# Encoding: utf-8 -# Don't need to list cookbooks in here that are also listed in the metadata depends statements -# unless there are specific overrides like git repo or version are needed +metadata cookbook 'rabbitmq', git: 'git://github.com/opscode-cookbooks/rabbitmq.git' group :test do - cookbook 'minitest-handler', git: 'git://github.com/btm/minitest-handler-cookbook.git' - cookbook 'elasticsearch', git: 'git://github.com/elasticsearch/cookbook-elasticsearch.git' - cookbook 'kibana', git: 'git://github.com/lusis/chef-kibana.git' - cookbook 'curl' - cookbook 'ark' + cookbook 'minitest-handler', git: 'git://github.com/btm/minitest-handler-cookbook.git' + cookbook 'elasticsearch', git: 'git://github.com/elasticsearch/cookbook-elasticsearch.git' + cookbook 'kibana', git: 'git://github.com/lusis/chef-kibana.git' + cookbook 'curl' + cookbook 'ark' end diff --git a/Gemfile b/Gemfile index 837a1fc..79c2e71 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ -source "https://rubygems.org" +# Encoding: utf-8 + +source 'https://rubygems.org' gem 'berkshelf' diff --git a/README.md b/README.md index e4faf8c..bf5ecce 100644 --- a/README.md +++ b/README.md @@ -247,16 +247,13 @@ vagrant up precise64 ## Strainer ``` -BUNDLE_GEMFILE=$(pwd)/test/support/Gemfile bundle install -BUNDLE_GEMFILE=$(pwd)/test/support/Gemfile bundle exec berks install -BUNDLE_GEMFILE=$(pwd)/test/support/Gemfile bundle exec strainer test +rake strainer ``` ## Test-Kitchen + ServerSpec ``` -BUNDLE_GEMFILE=$(pwd)/test/support/Gemfile bundle exec \ - kitchen test --destroy=always +rake kitchen ``` Contributing diff --git a/Rakefile b/Rakefile index 0c96596..6452486 100644 --- a/Rakefile +++ b/Rakefile @@ -1,56 +1,73 @@ #!/usr/bin/env rake +# Encoding: utf-8 @cookbook_path = '/tmp/logstash-cookbooks' -@cookbook = "logstash" +@cookbook = 'logstash' +@gemfile = "#{File.dirname(__FILE__)}/test/support/Gemfile" -desc "install dependencies using Berkshelf" +desc 'install dependencies using Berkshelf' task :install_deps do - system("berks install --path=#{@cookbook_path}") + install_deps end -desc "Runs foodcritic linter" +desc 'Runs foodcritic linter' task :foodcritic do - if Gem::Version.new("1.9.2") <= Gem::Version.new(RUBY_VERSION.dup) + if Gem::Version.new('1.9.2') <= Gem::Version.new(RUBY_VERSION.dup) sandbox = File.join(File.dirname(__FILE__), %w{tmp foodcritic}, @cookbook) prepare_test_sandbox(sandbox) - + sh "foodcritic --epic-fail any #{File.dirname(sandbox)}" else puts "WARN: foodcritic run is skipped as Ruby #{RUBY_VERSION} is < 1.9.2." end end -desc "Runs Strainer" +desc 'Runs Strainer' task :strainer do - if Gem::Version.new("1.9.2") <= Gem::Version.new(RUBY_VERSION.dup) - sandbox = '/tmp/cookbook_logstash' - prepare_test_sandbox(sandbox) - rm_rf '/tmp/strainer' - gemfile="#{File.dirname(__FILE__)}/test/support/Gemfile" - puts gemfile - sh "cd #{sandbox} && BUNDLE_GEMFILE=#{gemfile} bundle exec strainer test --sandbox=/tmp/strainer --cookbooks-path=#{@cookbook_path}" + if Gem::Version.new('1.9.2') <= Gem::Version.new(RUBY_VERSION.dup) + # sandbox = '/tmp/cookbook_logstash' + # prepare_test_sandbox(sandbox) + # rm_rf '/tmp/strainer' + install_deps + # puts gemfile + puts "BUNDLE_GEMFILE=#{@gemfile} bundle exec strainer test --sandbox=/tmp/strainer --cookbooks-path=#{@cookbook_path}" + system({ 'BUNDLE_GEMFILE' => @gemfile }, "bundle exec strainer test --sandbox=/tmp/strainer --cookbooks-path=#{@cookbook_path}") else puts "WARN: strainer run is skipped as Ruby #{RUBY_VERSION} is < 1.9.2." end end -task :default => 'foodcritic' +desc 'Runs Test Kitchen' +task :kitchen do + begin + require 'kitchen/rake_tasks' + Kitchen::RakeTasks.new + rescue LoadError + puts '>>>>> Kitchen gem not loaded, omitting tasks' unless ENV['CI'] + end + if Gem::Version.new('1.9.2') <= Gem::Version.new(RUBY_VERSION.dup) + install_deps + system({ 'BUNDLE_GEMFILE' => @gemfile }, 'bundle exec kitchen test --destroy=always') + end +end + +task default: 'strainer' + +private + +def install_deps + puts "BUNDLE_GEMFILE=#{@gemfile} bundle exec berks install --path=#{@cookbook_path}" + system({ 'BUNDLE_GEMFILE' => @gemfile }, "bundle exec berks install --path=#{@cookbook_path}") +end private def prepare_test_sandbox(sandbox) files = %w{ *.md *.rb attributes definitions files providers Strainerfile .rubocop* - recipes resources templates spec } + recipes resources templates test/integration test/serverspec } rm_rf sandbox mkdir_p sandbox cp_r Dir.glob("{#{files.join(',')}}"), sandbox puts "\n\n" 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/Strainerfile b/Strainerfile index 7798db6..6e6bd91 100644 --- a/Strainerfile +++ b/Strainerfile @@ -2,4 +2,4 @@ rubocop: bundle exec rubocop -c $SANDBOX/$COOKBOOK/.rubocop.yml $SANDBOX/$COOKBOOK knife test: bundle exec knife cookbook test $COOKBOOK foodcritic: bundle exec foodcritic --epic-fail any $SANDBOX/$COOKBOOK -chefspec: bundle exec rspec $SANDBOX/$COOKBOOK/spec +chefspec: bundle exec rspec $SANDBOX/$COOKBOOK/test/unit/spec diff --git a/Vagrantfile b/Vagrantfile index 6209ead..c55eb3f 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,3 +1,4 @@ +# Encoding: utf-8 # -*- mode: ruby -*- # vi: set ft=ruby : @@ -20,9 +21,9 @@ chef_json = { jdk_version: '7' }, kibana: { - webserver_listen: "0.0.0.0", - webserver: "nginx", - install_type: "file" + webserver_listen: '0.0.0.0', + webserver: 'nginx', + install_type: 'file' }, logstash: { supervisor_gid: 'adm', @@ -34,7 +35,7 @@ chef_json = { inputs: [ file: { type: 'syslog', - path: ['/var/log/syslog','/var/log/messages'], + path: ['/var/log/syslog', '/var/log/messages'], start_position: 'beginning' } ], @@ -44,16 +45,16 @@ chef_json = { block: { grok: { match: [ - "message", + 'message', "%{SYSLOGTIMESTAMP:timestamp} %{IPORHOST:host} (?:%{PROG:program}(?:\[%{POSINT:pid}\])?: )?%{GREEDYDATA:message}" ] }, date: { match: [ - "timestamp", - "MMM d HH:mm:ss", - "MMM dd HH:mm:ss", - "ISO8601" + 'timestamp', + 'MMM d HH:mm:ss', + 'MMM dd HH:mm:ss', + 'ISO8601' ] } } @@ -76,8 +77,8 @@ Vagrant.configure('2') do |config| # Common Settings config.omnibus.chef_version = 'latest' config.vm.hostname = 'logstash' - config.vm.network "forwarded_port", guest: 9292, host: 9292 - config.vm.network "forwarded_port", guest: 9200, host: 9200 + config.vm.network 'forwarded_port', guest: 9292, host: 9292 + config.vm.network 'forwarded_port', guest: 9200, host: 9200 config.vm.provider :virtualbox do |vb| vb.customize ['modifyvm', :id, '--memory', '1024'] end @@ -128,9 +129,8 @@ Vagrant.configure('2') do |config| end end - config.vm.define :centos6_64 do |dist_config| - dist_config.vm.box = 'opscode-centos-6.3' #centos6_64' + dist_config.vm.box = 'opscode-centos-6.3' # centos6_64' dist_config.vm.box_url = 'https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_centos-6.4_provisionerless.box' dist_config.vm.provision :chef_solo do |chef| chef.cookbooks_path = ['/tmp/logstash-cookbooks'] @@ -165,4 +165,3 @@ Vagrant.configure('2') do |config| end end - diff --git a/test/integration/server/serverspec/server_spec.rb b/test/integration/server/serverspec/server_spec.rb index 32432dc..c4c74e4 100644 --- a/test/integration/server/serverspec/server_spec.rb +++ b/test/integration/server/serverspec/server_spec.rb @@ -1,10 +1,11 @@ +# Encoding: utf-8 require 'spec_helper' describe 'logstash server' do - it { pending 'it writes the tests for its code or else it gets the hose again' } + it { pending 'it writes the tests for the code or else it gets the hose again' } end describe service('logstash_server') do - it { should be_enabled } - it { should be_running } + it { should be_enabled } + it { should be_running } end diff --git a/test/integration/server/serverspec/spec_helper.rb b/test/integration/server/serverspec/spec_helper.rb index b2a8246..219f365 100644 --- a/test/integration/server/serverspec/spec_helper.rb +++ b/test/integration/server/serverspec/spec_helper.rb @@ -1,3 +1,4 @@ +# Encoding: utf-8 require 'serverspec' include Serverspec::Helper::Exec @@ -7,4 +8,4 @@ c.before :all do c.path = '/sbin:/usr/bin' end -end \ No newline at end of file +end diff --git a/test/support/Gemfile b/test/support/Gemfile index 47f707b..798815b 100644 --- a/test/support/Gemfile +++ b/test/support/Gemfile @@ -1,11 +1,13 @@ -source "https://rubygems.org" +# Encoding: utf-8 + +source 'https://rubygems.org' gem 'rake', '~> 10.1.0' -gem 'foodcritic', '~> 3.0.0', :platforms => :ruby_19 -gem 'chef', '~> 11.8.0', :platforms => :ruby_19 -gem 'berkshelf', '~> 2.0.0', :platforms => :ruby_19 -gem 'rubocop', '~> 0.16.0', :platforms => :ruby_19 -gem 'chefspec', '~> 3.1.4', :platforms => :ruby_19 -gem 'strainer', '~> 3.3.0', :platforms => :ruby_19 -gem 'test-kitchen', '~> 1.1.1', :platforms => :ruby_19 +gem 'foodcritic', '~> 3.0.0', platforms: :ruby_19 +gem 'chef', '~> 11.8.0', platforms: :ruby_19 +gem 'berkshelf', '~> 2.0.0', platforms: :ruby_19 +gem 'rubocop', '~> 0.16.0', platforms: :ruby_19 +gem 'chefspec', '~> 3.1.4', platforms: :ruby_19 +gem 'strainer', '~> 3.3.0', platforms: :ruby_19 +gem 'test-kitchen', '~> 1.1.1', platforms: :ruby_19 gem 'kitchen-vagrant' diff --git a/spec/agent_spec.rb b/test/unit/spec/agent_spec.rb similarity index 63% rename from spec/agent_spec.rb rename to test/unit/spec/agent_spec.rb index 244b756..b122224 100644 --- a/spec/agent_spec.rb +++ b/test/unit/spec/agent_spec.rb @@ -4,10 +4,7 @@ describe 'logstash::agent' do before { logstash_stubs } describe 'ubuntu' do - before do - @chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS - @chef_run.converge 'logstash::agent' - end + let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) } it 'writes some chefspec code' do pending 'todo' diff --git a/spec/beaver_spec.rb b/test/unit/spec/beaver_spec.rb similarity index 63% rename from spec/beaver_spec.rb rename to test/unit/spec/beaver_spec.rb index a2a66c2..1088fe1 100644 --- a/spec/beaver_spec.rb +++ b/test/unit/spec/beaver_spec.rb @@ -4,10 +4,7 @@ describe 'logstash::beaver' do before { logstash_stubs } describe 'ubuntu' do - before do - @chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS - @chef_run.converge 'logstash::beaver' - end + let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) } it 'writes some chefspec code' do pending 'todo' diff --git a/spec/default_spec.rb b/test/unit/spec/default_spec.rb similarity index 63% rename from spec/default_spec.rb rename to test/unit/spec/default_spec.rb index 48c54d9..b995568 100644 --- a/spec/default_spec.rb +++ b/test/unit/spec/default_spec.rb @@ -4,10 +4,7 @@ describe 'logstash::default' do before { logstash_stubs } describe 'ubuntu' do - before do - @chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS - @chef_run.converge 'logstash::default' - end + let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) } it 'writes some chefspec code' do pending 'todo' diff --git a/spec/haproxy_spec.rb b/test/unit/spec/haproxy_spec.rb similarity index 63% rename from spec/haproxy_spec.rb rename to test/unit/spec/haproxy_spec.rb index 6d9d697..c9cfe80 100644 --- a/spec/haproxy_spec.rb +++ b/test/unit/spec/haproxy_spec.rb @@ -4,10 +4,7 @@ describe 'logstash::haproxy' do before { logstash_stubs } describe 'ubuntu' do - before do - @chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS - @chef_run.converge 'logstash::haproxy' - end + let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) } it 'writes some chefspec code' do pending 'todo' diff --git a/spec/index_cleaer_spec.rb b/test/unit/spec/index_cleaer_spec.rb similarity index 63% rename from spec/index_cleaer_spec.rb rename to test/unit/spec/index_cleaer_spec.rb index a55892c..c4ae32e 100644 --- a/spec/index_cleaer_spec.rb +++ b/test/unit/spec/index_cleaer_spec.rb @@ -4,10 +4,7 @@ describe 'logstash::index_cleaner' do before { logstash_stubs } describe 'ubuntu' do - before do - @chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS - @chef_run.converge 'logstash::index_cleaner' - end + let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) } it 'writes some chefspec code' do pending 'todo' diff --git a/spec/pyshipper_spec.rb b/test/unit/spec/pyshipper_spec.rb similarity index 100% rename from spec/pyshipper_spec.rb rename to test/unit/spec/pyshipper_spec.rb diff --git a/spec/server_spec.rb b/test/unit/spec/server_spec.rb similarity index 63% rename from spec/server_spec.rb rename to test/unit/spec/server_spec.rb index 76395b1..0934e77 100644 --- a/spec/server_spec.rb +++ b/test/unit/spec/server_spec.rb @@ -4,10 +4,7 @@ describe 'logstash::server' do before { logstash_stubs } describe 'ubuntu' do - before do - @chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS - @chef_run.converge 'logstash::server' - end + let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) } it 'writes some chefspec code' do pending 'todo' diff --git a/spec/source_spec.rb b/test/unit/spec/source_spec.rb similarity index 63% rename from spec/source_spec.rb rename to test/unit/spec/source_spec.rb index 3462df7..e520082 100644 --- a/spec/source_spec.rb +++ b/test/unit/spec/source_spec.rb @@ -4,10 +4,7 @@ describe 'logstash::source' do before { logstash_stubs } describe 'ubuntu' do - before do - @chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS - @chef_run.converge 'logstash::source' - end + let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) } it 'writes some chefspec code' do pending 'todo' diff --git a/spec/spec_helper.rb b/test/unit/spec/spec_helper.rb similarity index 89% rename from spec/spec_helper.rb rename to test/unit/spec/spec_helper.rb index c868779..cee8990 100644 --- a/spec/spec_helper.rb +++ b/test/unit/spec/spec_helper.rb @@ -1,5 +1,7 @@ # Encoding: utf-8 require 'chefspec' +require 'chefspec/berkshelf' +require 'chef/application' ::LOG_LEVEL = :fatal diff --git a/spec/zero_mq_repo.rb b/test/unit/spec/zero_mq_repo.rb similarity index 63% rename from spec/zero_mq_repo.rb rename to test/unit/spec/zero_mq_repo.rb index 8e46dd7..2b72d78 100644 --- a/spec/zero_mq_repo.rb +++ b/test/unit/spec/zero_mq_repo.rb @@ -4,10 +4,7 @@ describe 'logstash::zero_mq_repo' do before { logstash_stubs } describe 'ubuntu' do - before do - @chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS - @chef_run.converge 'logstash::zero_mq_repo' - end + let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) } it 'writes some chefspec code' do pending 'todo'