Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moar chefspec testing #35

Merged
merged 3 commits into from
Dec 26, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ 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
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
style.max_line_length 160, :level => :warn
end
task.file_set('resources/**/*.rb', "resources")
# task.file_set('templates/**/*.erb', "templates")
task.file_set('spec/**/*.rb', "tests") do |style|
style.max_line_length 160, :level => :warn
end
end

FoodCritic::Rake::LintTask.new do |t|
Expand All @@ -42,5 +44,5 @@ end
# https://github.com/acrmp/chefspec
desc "Run ChefSpec Unit Tests"
task :chefspec do
sh %{rspec cookbooks/datadog/spec/}
sh %{rspec --color cookbooks/datadog/spec/}
end
71 changes: 56 additions & 15 deletions spec/dd-agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,69 @@

# 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" }
context 'when using a debian-family distro' do
before do
Fauxhai.mock(:platform => 'ubuntu', :version => '12.04') do |node|
node['datadog'] = { :api_key => "somethingnotnil" }
end
end
end

let (:runner) { ChefSpec::ChefRunner.new.converge 'datadog::dd-agent' }
let (:chef_run) { ChefSpec::ChefRunner.new.converge 'datadog::dd-agent' }

it 'should install the datadog-agent' do
runner.should install_package 'datadog-agent'
end
it 'sets up an apt repository' do
pending "step into apt"
end

it 'should enable the datadog-agent service' do
runner.should set_service_to_start_on_boot 'datadog-agent'
end
it 'installs the datadog-agent' do
chef_run.should install_package 'datadog-agent'
end

it 'enables the datadog-agent service' do
chef_run.should set_service_to_start_on_boot 'datadog-agent'
end

it 'ensures the dd-agent directory exists' do
chef_run.should create_directory '/etc/dd-agent'
end

it 'should ensure the dd-agent directory exists' do
runner.should create_directory '/etc/dd-agent'
it 'drops an agent config file' do
chef_run.should create_file '/etc/dd-agent/datadog.conf'
end
end

it 'should drop an agent config file' do
runner.should create_file '/etc/dd-agent/datadog.conf'
context 'when using a redhat-family distro above 6.x' do
before do
Fauxhai.mock(platform: 'centos', version: '6.3') do |node|
node['datadog'] = { :api_key => "somethingnotnil" }
end
end

let (:chef_run) { ChefSpec::ChefRunner.new.converge 'datadog::dd-agent' }

it 'sets up the EPEL repository' do
pending "step intp yum::epel?"
end

it 'sets up a yum repository' do
pending "step into yum"
end

it 'installs the datadog-agent package' do
chef_run.should install_package 'datadog-agent'
end

it 'does not install the datadog-agent-base package' do
chef_run.should_not install_package 'datadog-agent-base'
end

it 'enables the datadog-agent service' do
chef_run.should set_service_to_start_on_boot 'datadog-agent'
end

it 'creates a configuration file' do
chef_run.should create_file '/etc/dd-agent/datadog.conf'
# chef_run.should notify 'service[datadog-agent]', :restart
end
end

end
9 changes: 9 additions & 0 deletions spec/default_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'spec_helper'

describe 'datadog::default' do
let (:chef_run) { ChefSpec::ChefRunner.new.converge 'datadog::default' }

it 'should do nothing' do
end

end