From c4d84645578f018fd9446a3bd420bc3b2c8319ec Mon Sep 17 00:00:00 2001 From: David Joos Date: Sat, 5 Apr 2014 00:34:19 +0100 Subject: [PATCH] Syntax/lint checks / unit tests / integration tests --- .gitignore | 14 +++--- .kitchen.yml | 123 ++++++++++++++++++++++++++---------------------- .rubocop.yml | 23 +++++++++ .travis.yml | 6 ++- CONTRIBUTING.md | 15 ++++++ Gemfile | 17 +++++-- Rakefile | 61 ++++++++++++++++++++++++ TESTING.md | 47 ++++++++++++++++++ metadata.rb | 46 +++++++++--------- 9 files changed, 262 insertions(+), 90 deletions(-) create mode 100644 .rubocop.yml create mode 100644 CONTRIBUTING.md create mode 100644 Rakefile create mode 100644 TESTING.md diff --git a/.gitignore b/.gitignore index 11c28693..bef5fce2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,19 +1,19 @@ -.vagrant -Vagrantfile - -Berksfile.lock *~ *# .#* \#*# .*.sw[a-z] *.un~ -/cookbooks -# Bundler +cookbooks +.coverage +spec + +Berksfile.lock Gemfile.lock +.vagrant +Vagrantfile bin/* .bundle/* - .kitchen .kitchen.local.yml \ No newline at end of file diff --git a/.kitchen.yml b/.kitchen.yml index 5b67e7c8..165220fa 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -1,56 +1,67 @@ ---- -driver_plugin: vagrant -driver_config: - require_chef_omnibus: true - -platforms: - - name: ubuntu-12.04 - driver_config: - box: opscode-ubuntu-12.04 - box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_provisionerless.box -# - name: ubuntu-13.04 -# driver_config: -# box: opscode-ubuntu-13.04 -# box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_ubuntu-13.04_provisionerless.box -# - name: centos-6.3 -# driver_config: -# box: opscode-centos-6.3 -# box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_centos-6.3_provisionerless.box - - name: centos-6.4 - driver_config: - box: opscode-centos-6.4 - box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_centos-6.4_provisionerless.box - -suites: - - name: default - run_list: - - recipe[newrelic::default] - attributes: - newrelic: - service_notify_action: nothing - service_actions: - - nothing -# - name: dotnet-agent -# run_list: -# - recipe[newrelic::default] -# - recipe[newrelic::dotnet-agent] -# - name: java-agent -# run_list: -# - recipe[newrelic::default] -# - recipe[newrelic::java-agent] -# - name: nodejs-agent -# run_list: -# - recipe[newrelic::default] -# - recipe[newrelic::nodejs-agent] -# - name: php-agent -# run_list: -# - recipe[newrelic::default] -# - recipe[newrelic::php-agent] -# - name: python-agent -# run_list: -# - recipe[newrelic::default] -# - recipe[newrelic::python-agent] -# - name: meetme-plugin -# run_list: -# - recipe[newrelic::default] -# - recipe[newrelic::meetme-plugin] \ No newline at end of file +--- +driver_plugin: vagrant +driver_config: + require_chef_omnibus: true + +platforms: + - name: ubuntu-12.04 + driver_config: + box: opscode-ubuntu-12.04 + box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_provisionerless.box +# - name: ubuntu-13.04 +# driver_config: +# box: opscode-ubuntu-13.04 +# box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_ubuntu-13.04_provisionerless.box +# - name: centos-6.3 +# driver_config: +# box: opscode-centos-6.3 +# box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_centos-6.3_provisionerless.box + - name: centos-6.4 + driver_config: + box: opscode-centos-6.4 + box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_centos-6.4_provisionerless.box + +suites: + - name: default + run_list: + - recipe[newrelic::default] + attributes: + newrelic: + license: 78defba8b120b1f16f269f6f53bac7234fe83ee9 +# server-monitor-agent: +# service_notify_action: nothing +# service_actions: +# - nothing +# - name: dotnet-agent +# run_list: +# - recipe[newrelic::dotnet-agent] +# - name: java-agent +# run_list: +# - recipe[newrelic::java-agent] +# - name: meetme-plugin +# run_list: +# - recipe[newrelic::meetme-plugin] +# - name: nodejs-agent +# run_list: +# - recipe[newrelic::nodejs-agent] +# - name: php-agent +# run_list: +# - recipe[newrelic::php-agent] +# - name: python-agent +# run_list: +# - recipe[newrelic::python-agent] + - name: repository + run_list: + - recipe[newrelic::repository] +# - name: ruby-agent +# run_list: +# - recipe[newrelic::ruby-agent] + - name: server-monitor-agent + run_list: + - recipe[newrelic::server-monitor-agent] + attributes: + newrelic: + server-monitor-agent: + service_notify_action: nothing + service_actions: + - nothing \ No newline at end of file diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 00000000..ed9be0cb --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,23 @@ +AlignParameters: + Enabled: false + +FileName: + Enabled: false + +Encoding: + Enabled: false + +LineLength: + Max: 200 + +HashSyntax: + EnforcedStyle: hash_rockets + +RedundantBegin: + Enabled: false + +UselessAssignment: + Enabled: false + +MethodLength: + Enabled: false \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 6a84d0b2..6725077e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,11 @@ before_script: - bundle exec berks install script: - - bundle exec foodcritic -f any . + - bundle exec rake travis + +branches: + only: + - master notifications: email: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..458e4923 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,15 @@ +Contributing +========= + +1. Fork it +2. Create your feature branch (`git checkout -b my-new-feature`) +3. Commit your changes (`git commit -am 'Add some feature'`) +4. [Add tests for your changes](https://github.com/escapestudios-cookbooks/newrelic/blob/master/TESTING.md) +4. Push your changes to your feature branch (`git push origin my-new-feature`) +5. Create a new Pull Request (PR) + +## Testing +Contributions will only be accepted if they are fully tested as specified in [TESTING.md](https://github.com/escapestudios-cookbooks/newrelic/blob/master/TESTING.md). + +## metadata.rb +Please do not modify the version number in the metadata.rb; not all changes to the cookbook may be merged and released in the same version. We will handle the version updates during the release process. \ No newline at end of file diff --git a/Gemfile b/Gemfile index f2fc118d..0c1a3745 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,17 @@ source 'https://rubygems.org' -gem 'foodcritic' gem 'berkshelf' -gem 'test-kitchen' -gem 'kitchen-vagrant' \ No newline at end of file + +group :testing do + gem 'rake' + gem 'rubocop' + gem 'foodcritic' + gem 'chefspec' + gem 'thor' +end + +group :integration do + gem 'test-kitchen' + gem 'kitchen-vagrant' + gem 'serverspec' +end \ No newline at end of file diff --git a/Rakefile b/Rakefile new file mode 100644 index 00000000..51570396 --- /dev/null +++ b/Rakefile @@ -0,0 +1,61 @@ +require 'rspec/core/rake_task' +require 'rubocop/rake_task' +require 'foodcritic' +require 'kitchen' + +#syntax/lint checks +namespace :lint do + desc 'Run Ruby syntax/lint checks' + Rubocop::RakeTask.new(:ruby) + + desc 'Run Chef syntax/lint checks' + FoodCritic::Rake::LintTask.new(:chef) { |task| + task.options = { fail_tags: ['any'] } + } +end + +desc 'Run all syntax/lint checks' +task lint: ['lint:ruby', 'lint:chef'] + +#unit testing: ChefSpec +desc 'Run RSpec and ChefSpec unit tests' +RSpec::Core::RakeTask.new(:unit) + +#integration testing: Test Kitchen +namespace :integration do + desc 'Run Test Kitchen integration tests with Vagrant' + task :vagrant do + Kitchen.logger = Kitchen.default_file_logger + Kitchen::Config.new.instances.each do |instance| + instance.test(:always) + end + end + +# desc 'Run Test Kitchen integration tests with cloud plugins' +# task :cloud do +# run_kitchen = true +# if ENV['TRAVIS'] == 'true' && ENV['TRAVIS_PULL_REQUEST'] != 'false' +# run_kitchen = false +# end +# +# if run_kitchen +# Kitchen.logger = Kitchen.default_file_logger +# @loader = Kitchen::Loader::YAML.new(project_config: './.kitchen.cloud.yml') +# config = Kitchen::Config.new( loader: @loader) +# config.instances.each do |instance| +# instance.test(:always) +# end +# end +# end +end + +desc 'Run all integration tests' +#task integration: ['integration:vagrant', 'integration:cloud'] +task integration: ['integration:vagrant'] + +#Travic CI +desc 'Run tests on Travis CI' +task travis: ['lint', 'unit'] + +#the default rake task should just run it all +task default: ['lint', 'unit', 'integration'] \ No newline at end of file diff --git a/TESTING.md b/TESTING.md new file mode 100644 index 00000000..11c40d6a --- /dev/null +++ b/TESTING.md @@ -0,0 +1,47 @@ +Testing the cookbook +==================== + +Contributions to this cookbook will only be accepted if all tests pass successfully: + +* Ruby syntax/lint checks: [RuboCop](http://batsov.com/rubocop/) +* Chef syntax/lint checks: [Foodcritic](http://acrmp.github.io/foodcritic/) +* Unit tests: [ChefSpec](http://code.sethvargo.com/chefspec/) +* Integration tests: [Test Kitchen](http://kitchen.ci/) + +Setting up the test environment +------------------------------- + +Install the latest version of [Vagrant](http://www.vagrantup.com/downloads.html) and [VirtualBox](https://www.virtualbox.org/wiki/Downloads) (free) or [VMWare Fusion](http://www.vmware.com/products/fusion) (paid). + +Clone the latest version of the cookbook from the repository. + + git clone git@github.com:escapestudios-cookbooks/newrelic.git + cd newrelic + +Install the gems used for testing: + + bundle install + +Install the berkshelf plugin for vagrant: + + vagrant plugin install vagrant-berkshelf + +Running syntax/lint checks +-------------------------- + + bundle exec rake lint + +Running unit tests +------------------ + + bundle exec rake unit + +Running integration tests +------------------------- + + bundle exec rake integration + +Running all checks/tests +------------------------ + + bundle exec rake \ No newline at end of file diff --git a/metadata.rb b/metadata.rb index a14c2f44..abc14912 100644 --- a/metadata.rb +++ b/metadata.rb @@ -1,29 +1,29 @@ -name "newrelic" -maintainer "Escape Studios" -maintainer_email "dev@escapestudios.com" -license "MIT" -description "Installs/Configures New Relic" +name 'newrelic' +maintainer 'Escape Studios' +maintainer_email 'dev@escapestudios.com' +license 'MIT' +description 'Installs/Configures New Relic' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version "1.0.1" +version '1.0.1' -%w{ debian ubuntu redhat centos fedora scientific amazon windows smartos }.each do |os| -supports os +%w({ debian ubuntu redhat centos fedora scientific amazon windows smartos }).each do |os| + supports os end -depends "python" +depends 'python' -recommends "php" -recommends "ms_dotnet4" -recommends "curl" -recommends "nodejs" +recommends 'php' +recommends 'ms_dotnet4' +recommends 'curl' +recommends 'nodejs' -recipe "newrelic", "Adds the New Relic repository, installs & configures the New Relic server monitor agent." -recipe "newrelic::repository", "Adds the New Relic repository." -recipe "newrelic::server-monitor-agent", "Installs & configures the New Relic server monitor agent." -recipe "newrelic::dotnet-agent", "Installs New Relic .NET agent" -recipe "newrelic::java-agent", "Installs the New Relic Java agent." -recipe "newrelic::nodejs-agent", "Installs New Relic Node.js agent" -recipe "newrelic::php-agent", "Installs the New Relic PHP agent." -recipe "newrelic::python-agent", "Installs the New Relic Python agent." -recipe "newrelic::ruby-agent", "Installs the New Relic Ruby agent." -recipe "newrelic::meetme-plugin", "Installs the New Relic MeetMe plugin." \ No newline at end of file +recipe 'newrelic', 'Adds the New Relic repository, installs & configures the New Relic server monitor agent.' +recipe 'newrelic::repository', 'Adds the New Relic repository.' +recipe 'newrelic::server-monitor-agent', 'Installs & configures the New Relic server monitor agent.' +recipe 'newrelic::dotnet-agent', 'Installs New Relic .NET agent.' +recipe 'newrelic::java-agent', 'Installs the New Relic Java agent.' +recipe 'newrelic::nodejs-agent', 'Installs New Relic Node.js agent.' +recipe 'newrelic::php-agent', 'Installs the New Relic PHP agent.' +recipe 'newrelic::python-agent', 'Installs the New Relic Python agent.' +recipe 'newrelic::ruby-agent', 'Installs the New Relic Ruby agent.' +recipe 'newrelic::meetme-plugin', 'Installs the New Relic MeetMe plugin.'