-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from DataDog/chefspec
Adds testing suite. Fixes #2
- Loading branch information
Showing
11 changed files
with
193 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
cache_type 'BasicFile' | ||
cache_options(:path => "#{ENV['HOME']}/.chef/checksums") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,7 @@ Gemfile.lock | |
# For Vagrant | ||
.vagrant | ||
/.rbenv-version | ||
|
||
# Berkshelf | ||
Berksfile.lock | ||
cookbooks/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
language: ruby | ||
rvm: | ||
- 1.9.3 | ||
|
||
bundler_args: --without=development | ||
|
||
before_install: | ||
- sudo apt-get update -qq | ||
- sudo apt-get install -qq libgecode-dev | ||
|
||
before_script: | ||
- rake berks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
metadata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,22 @@ | ||
# -*- encoding: utf-8 -*- | ||
source "http://rubygems.org" | ||
gem 'rake' | ||
|
||
chef_version = ENV.key?('CHEF_VERSION') ? "= #{ENV['CHEF_VERSION']}" : ['~> 10'] | ||
|
||
gem "rake", "~> 0.9" | ||
gem "chef", chef_version | ||
|
||
group :development do | ||
gem 'travis-lint' | ||
gem "travis-lint", "~> 1.4.0" | ||
gem "guard", "~> 1.3.2" | ||
gem "guard-foodcritic", "~> 1.0.0" | ||
gem "guard-rspec", "~> 1.2.1" | ||
end | ||
|
||
group :test do | ||
gem 'foodcritic', '>= 1.5.1' # Lint testing | ||
gem "tailor", "~> 1.1.2" # Ruby style | ||
gem "foodcritic", "~> 1.6.1" # Lint testing | ||
gem "berkshelf", "~> 0.4.0" | ||
gem "chefspec", "~> 0.7.0" | ||
gem "fauxhai", "~> 0.0.3" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# A Guardfile | ||
# More info at https://github.com/guard/guard#readme | ||
|
||
guard 'foodcritic', | ||
:cookbook_paths => ".", | ||
:cli => "--epic-fail correctness --chef-version 0.10.8" do | ||
watch(%r{metadata.rb$}) | ||
watch(%r{attributes/.+\.rb$}) | ||
watch(%r{providers/.+\.rb$}) | ||
watch(%r{recipes/.+\.rb$}) | ||
watch(%r{resources/.+\.rb$}) | ||
watch(%r{templates/.+\.rb$}) | ||
end | ||
|
||
# Since a cookbook depends on other cookbooks, this structure is needed. | ||
# The `rake berks` should be performed prior to running this. | ||
spec_paths = Dir.glob(File.join("cookbooks", "**", "spec")) | ||
guard 'rspec', | ||
:version => 2, | ||
:cli => '--color --format nested', | ||
:spec_paths => spec_paths do | ||
|
||
watch(%r{^cookbooks/.+/spec/.+_spec\.rb$}) | ||
watch(%r{^cookbooks/.+/spec/spec_helper.rb$}) { "spec" } | ||
|
||
# Chef paths example | ||
watch(%r{cookbooks/.+/metadata.rb$}) | ||
watch(%r{cookbooks/.+/attributes/.+\.rb$}) | ||
watch(%r{cookbooks/.+/providers/.+\.rb$}) | ||
watch(%r{cookbooks/.+/recipes/.+\.rb$}) | ||
watch(%r{cookbooks/.+/resources/.+\.rb$}) | ||
watch(%r{cookbooks/.+/templates/.+\.rb$}) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,46 @@ | ||
#!/usr/bin/env rake | ||
|
||
# http://acrmp.github.com/foodcritic/ | ||
require 'foodcritic' | ||
# https://github.com/turboladen/tailor | ||
require 'tailor/rake_task' | ||
|
||
task :default => [:foodcritic] | ||
task :default => [:tailor, :foodcritic, :knife, :chefspec] | ||
|
||
Tailor::RakeTask.new do |task| | ||
task.file_set('attributes/**/*.rb', "attributes") do |style| | ||
style.max_line_length 160, level: :warn | ||
end | ||
task.file_set('definitions/**/*.rb', "definitions") | ||
task.file_set('libraries/**/*.rb', "libraries") | ||
task.file_set('metadata.rb', "metadata") | ||
task.file_set('providers/**/*.rb', "providers") | ||
task.file_set('recipes/**/*.rb', "recipes") do |style| | ||
style.max_line_length 160, level: :warn | ||
end | ||
task.file_set('resources/**/*.rb', "resources") | ||
# task.file_set('templates/**/*.erb', "templates") | ||
end | ||
|
||
FoodCritic::Rake::LintTask.new do |t| | ||
t.options = {:fail_tags => ['correctness']} | ||
t.options = {:chef_version => '0.10.8'} | ||
t.options = { :fail_tags => ['correctness'] } | ||
t.options = { :chef_version => '0.10.8' } | ||
end | ||
|
||
# http://berkshelf.com/ | ||
desc "Install Berkshelf shims" | ||
task :berks do | ||
sh %{berks install --shims} | ||
end | ||
|
||
# http://wiki.opscode.com/display/chef/Managing+Cookbooks+With+Knife#ManagingCookbooksWithKnife-test | ||
desc "Test cookbooks via knife" | ||
task :knife do | ||
sh %{knife cookbook test -o cookbooks -a} | ||
end | ||
|
||
# https://github.com/acrmp/chefspec | ||
desc "Run ChefSpec Unit Tests" | ||
task :chefspec do | ||
sh %{rspec cookbooks/datadog} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Put files/directories that should be ignored in this file. | ||
# Lines that start with '# ' are comments. | ||
|
||
## OS | ||
.DS_Store | ||
Icon? | ||
nohup.out | ||
|
||
## EDITORS | ||
\#* | ||
.#* | ||
*~ | ||
*.sw[a-z] | ||
*.bak | ||
REVISION | ||
TAGS* | ||
tmtags | ||
*_flymake.* | ||
*_flymake | ||
*.tmproj | ||
.project | ||
.settings | ||
mkmf.log | ||
|
||
## COMPILED | ||
a.out | ||
*.o | ||
*.pyc | ||
*.so | ||
|
||
## OTHER SCM | ||
*/.bzr/* | ||
*/.hg/* | ||
*/.svn/* | ||
|
||
## Don't send rspecs up in cookbook | ||
.watchr | ||
.rspec | ||
spec/* | ||
spec/fixtures/* | ||
features/* | ||
|
||
## SCM | ||
.gitignore | ||
|
||
# Berkshelf | ||
Berksfile | ||
Berksfile.lock | ||
cookbooks/* | ||
|
||
Guardfile | ||
Rakefile | ||
|
||
# Vagrant | ||
.vagrant |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require 'spec_helper' | ||
|
||
describe 'datadog::dd-agent' do | ||
|
||
# This recipe needs to have an api_key, otherwise `raise` is called. | ||
# It also depends on specific platofrm versions for software install | ||
before do | ||
Fauxhai.mock(platform:'ubuntu', version:'12.04') do |node| | ||
node['datadog'] = {:api_key => "somethingnotnil"} | ||
end | ||
end | ||
|
||
let (:runner) { ChefSpec::ChefRunner.new.converge 'datadog::dd-agent' } | ||
|
||
it 'should install the datadog-agent' do | ||
runner.should install_package 'datadog-agent' | ||
end | ||
|
||
it 'should enable the datadog-agent service' do | ||
runner.should set_service_to_start_on_boot 'datadog-agent' | ||
end | ||
|
||
it 'should ensure the dd-agent directory exists' do | ||
runner.should create_directory '/etc/dd-agent' | ||
end | ||
|
||
it 'should drop an agent config file' do | ||
runner.should create_file '/etc/dd-agent/datadog.conf' | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require 'chefspec' | ||
require 'fauxhai' |