Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Commit

Permalink
cleanup of testing environment
Browse files Browse the repository at this point in the history
  • Loading branch information
paulczar committed Jan 11, 2014
1 parent 00e1fab commit f383f00
Show file tree
Hide file tree
Showing 21 changed files with 100 additions and 99 deletions.
8 changes: 6 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
AllCops:
Excludes:
- vendor
- test/support/vendor/**

- test/support/**
Includes:
- Rakefile
- Gemfile
- Vagrantfile
- Berksfile
CyclomaticComplexity:
Enabled: false

Expand Down
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
install: BUNDLE_GEMFILE=$PWD/test/support/Gemfile bundle install
script: BUNDLE_GEMFILE=$PWD/test/support/Gemfile bundle exec rake strainer
15 changes: 7 additions & 8 deletions Berksfile
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
source "https://rubygems.org"
# Encoding: utf-8

source 'https://rubygems.org'

gem 'berkshelf'
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
63 changes: 40 additions & 23 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion Strainerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
27 changes: 13 additions & 14 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Encoding: utf-8
# -*- mode: ruby -*-
# vi: set ft=ruby :

Expand All @@ -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',
Expand All @@ -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'
}
],
Expand All @@ -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'
]
}
}
Expand All @@ -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
Expand Down Expand Up @@ -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']
Expand Down Expand Up @@ -165,4 +165,3 @@ Vagrant.configure('2') do |config|
end

end

7 changes: 4 additions & 3 deletions test/integration/server/serverspec/server_spec.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion test/integration/server/serverspec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Encoding: utf-8
require 'serverspec'

include Serverspec::Helper::Exec
Expand All @@ -7,4 +8,4 @@
c.before :all do
c.path = '/sbin:/usr/bin'
end
end
end
18 changes: 10 additions & 8 deletions test/support/Gemfile
Original file line number Diff line number Diff line change
@@ -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'
5 changes: 1 addition & 4 deletions spec/agent_spec.rb → test/unit/spec/agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
5 changes: 1 addition & 4 deletions spec/beaver_spec.rb → test/unit/spec/beaver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
5 changes: 1 addition & 4 deletions spec/default_spec.rb → test/unit/spec/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
5 changes: 1 addition & 4 deletions spec/haproxy_spec.rb → test/unit/spec/haproxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
File renamed without changes.
5 changes: 1 addition & 4 deletions spec/server_spec.rb → test/unit/spec/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
5 changes: 1 addition & 4 deletions spec/source_spec.rb → test/unit/spec/source_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 2 additions & 0 deletions spec/spec_helper.rb → test/unit/spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Encoding: utf-8
require 'chefspec'
require 'chefspec/berkshelf'
require 'chef/application'

::LOG_LEVEL = :fatal

Expand Down
Loading

0 comments on commit f383f00

Please sign in to comment.