From e3f11e6ecde54232f7e3159690b08fcfb3ff1e2a Mon Sep 17 00:00:00 2001 From: Martin Cozzi Date: Mon, 28 Jul 2014 23:23:35 -0700 Subject: [PATCH 1/2] Adds kitchen tests to the cookbook. This is branched off the `service-init` branch. --- .gitignore | 2 ++ .kitchen.yml | 15 ++++++++++ Gemfile | 2 ++ Gemfile.lock | 13 +++++++++ .../default/serverspec/default_spec.rb | 28 +++++++++++++++++++ 5 files changed, 60 insertions(+) create mode 100644 .kitchen.yml create mode 100644 test/integration/default/serverspec/default_spec.rb diff --git a/.gitignore b/.gitignore index 94a808f..87ab7d2 100644 --- a/.gitignore +++ b/.gitignore @@ -53,3 +53,5 @@ Berksfile.lock .*.sw[a-z] *.un~ /cookbooks +.kitchen/ +.kitchen.local.yml diff --git a/.kitchen.yml b/.kitchen.yml new file mode 100644 index 0000000..0d03362 --- /dev/null +++ b/.kitchen.yml @@ -0,0 +1,15 @@ +--- +driver: + name: vagrant + +provisioner: + name: chef_solo + +platforms: + - name: ubuntu-12.04 + +suites: + - name: default + run_list: + - recipe[statsd::default] + attributes: diff --git a/Gemfile b/Gemfile index d8168e6..f1579fa 100644 --- a/Gemfile +++ b/Gemfile @@ -3,3 +3,5 @@ source 'https://rubygems.org' gem 'berkshelf', '~> 3.0' gem 'chef' gem 'chefspec' +gem 'test-kitchen' +gem 'kitchen-vagrant' diff --git a/Gemfile.lock b/Gemfile.lock index 37864f0..5f45ded 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -77,6 +77,8 @@ GEM hitimes (1.2.2) ipaddress (0.8.0) json (1.8.1) + kitchen-vagrant (0.15.0) + test-kitchen (~> 1.0) method_source (0.8.2) mime-types (1.25.1) minitar (0.5.4) @@ -88,6 +90,8 @@ GEM mixlib-shellout (1.4.0) multipart-post (2.0.0) net-http-persistent (2.9.4) + net-scp (1.2.1) + net-ssh (>= 2.6.5) net-ssh (2.9.1) net-ssh-gateway (1.2.0) net-ssh (>= 2.6.5) @@ -146,6 +150,7 @@ GEM rspec-mocks (3.0.3) rspec-support (~> 3.0.0) rspec-support (3.0.3) + safe_yaml (1.0.3) sawyer (0.5.4) addressable (~> 2.3.5) faraday (~> 0.8, < 0.10) @@ -155,6 +160,12 @@ GEM dep_selector (~> 1.0) semverse (~> 1.1) systemu (2.5.2) + 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) timers (4.0.0) hitimes @@ -170,3 +181,5 @@ DEPENDENCIES berkshelf (~> 3.0) chef chefspec + kitchen-vagrant + test-kitchen diff --git a/test/integration/default/serverspec/default_spec.rb b/test/integration/default/serverspec/default_spec.rb new file mode 100644 index 0000000..17f23ca --- /dev/null +++ b/test/integration/default/serverspec/default_spec.rb @@ -0,0 +1,28 @@ +require 'serverspec' + +include Serverspec::Helper::Exec +include Serverspec::Helper::DetectOS + +RSpec.configure do |c| + c.before :all do + c.path = '/sbin:/usr/sbin' + end +end + +describe 'statsd service' do + it 'should be configured for upstart' do + expect(file('/etc/init/statsd.conf')).to be_file + end + + it 'should be enabled' do + expect(service('statsd')).to be_enabled + end + + it 'should be running' do + expect(service('statsd')).to be_running + end + + it 'should be listening' do + expect(port('8125')).to be_listening.with('udp') + end +end From 63cd262f76422d560ab39d014770da12a5eaf9b7 Mon Sep 17 00:00:00 2001 From: Martin Cozzi Date: Tue, 29 Jul 2014 08:13:47 -0700 Subject: [PATCH 2/2] Updates README.md with information to run tests This includes unit tests as well as integration tests. --- README.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cfd8813..d33c397 100644 --- a/README.md +++ b/README.md @@ -61,4 +61,16 @@ For example, to set your email and token for the 'token' => '1234567890ABCDEF' } } -``` \ No newline at end of file +``` + +# Test + +To run unit tests using rspec you can run: +```bash +$ bundle exec rspec +``` + +To run integration tests using kitchen-ci you can run: +```bash +$ bundle exec kitchen test +```