From ea2d03feb69e63c35f9c04260b9ea15e289ca99d Mon Sep 17 00:00:00 2001 From: Mike Fiedler Date: Tue, 11 Dec 2012 09:06:48 -0500 Subject: [PATCH 1/3] Initial chefspec testing --- Rakefile | 6 ++-- spec/dd-agent_spec.rb | 71 ++++++++++++++++++++++++++++++++++--------- spec/default_spec.rb | 9 ++++++ 3 files changed, 69 insertions(+), 17 deletions(-) create mode 100644 spec/default_spec.rb diff --git a/Rakefile b/Rakefile index 3d3a8058..c7c13734 100644 --- a/Rakefile +++ b/Rakefile @@ -19,7 +19,9 @@ Tailor::RakeTask.new do |task| 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| @@ -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 diff --git a/spec/dd-agent_spec.rb b/spec/dd-agent_spec.rb index 6141c7ed..2b57e372 100644 --- a/spec/dd-agent_spec.rb +++ b/spec/dd-agent_spec.rb @@ -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 diff --git a/spec/default_spec.rb b/spec/default_spec.rb new file mode 100644 index 00000000..9ba70ef4 --- /dev/null +++ b/spec/default_spec.rb @@ -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 From cb54d6db94058a1e810f5bfcbc89603491bd6adc Mon Sep 17 00:00:00 2001 From: Mike Fiedler Date: Tue, 11 Dec 2012 13:40:08 -0500 Subject: [PATCH 2/3] Use Ruby 1.8.7-style hashrockets in Rakefile --- Rakefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Rakefile b/Rakefile index c7c13734..838635bf 100644 --- a/Rakefile +++ b/Rakefile @@ -9,18 +9,18 @@ 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('spec/**/*.rb', "tests") do |style| - style.max_line_length 160, level: :warn + style.max_line_length 160, level => :warn end end From 4c35edf72b8ad6920927dcfd2d407aa0ad8ff225 Mon Sep 17 00:00:00 2001 From: Mike Fiedler Date: Tue, 11 Dec 2012 13:45:01 -0500 Subject: [PATCH 3/3] Missed the 'level' as ':level' in last commit --- Rakefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Rakefile b/Rakefile index 838635bf..e93a1387 100644 --- a/Rakefile +++ b/Rakefile @@ -9,18 +9,18 @@ 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('spec/**/*.rb', "tests") do |style| - style.max_line_length 160, level => :warn + style.max_line_length 160, :level => :warn end end