Skip to content

Commit

Permalink
Merge pull request #18 from DataDog/chefspec
Browse files Browse the repository at this point in the history
Adds testing suite. Fixes #2
  • Loading branch information
alq666 committed Sep 14, 2012
2 parents 9148c99 + c7bfa28 commit 2eefa55
Show file tree
Hide file tree
Showing 11 changed files with 193 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .chef/knife.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cache_type 'BasicFile'
cache_options(:path => "#{ENV['HOME']}/.chef/checksums")
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ Gemfile.lock
# For Vagrant
.vagrant
/.rbenv-version

# Berkshelf
Berksfile.lock
cookbooks/
9 changes: 9 additions & 0 deletions .travis.yml
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
1 change: 1 addition & 0 deletions Berksfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
metadata
18 changes: 15 additions & 3 deletions Gemfile
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
33 changes: 33 additions & 0 deletions Guardfile
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
42 changes: 39 additions & 3 deletions Rakefile
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
55 changes: 55 additions & 0 deletions chefignore
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
3 changes: 2 additions & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
name "datadog"
maintainer "Datadog"
maintainer_email "package@datadoghq.com"
license "Apache 2.0"
Expand All @@ -6,7 +7,7 @@
version "0.0.13"

depends "apt"
depends "chef_handler"
depends "chef_handler", ">= 1.0.6"
depends "yum"

recipe "datadog::default", "Default"
Expand Down
31 changes: 31 additions & 0 deletions spec/dd-agent_spec.rb
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
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require 'chefspec'
require 'fauxhai'

0 comments on commit 2eefa55

Please sign in to comment.