Skip to content

Commit

Permalink
[tests] add dd-handler spec test
Browse files Browse the repository at this point in the history
Or at least a beginning of tests, with multiple endpoints
  • Loading branch information
degemer committed Sep 13, 2016
1 parent 0bea55d commit bbe7268
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ before_script:
- eval "$(/opt/chefdk/bin/chef shell-init bash)"
- chef gem install coveralls -v '~> 0.8.13'
- chef gem install json_spec -v '~> 1.1.4'
- chef gem install chef-handler-datadog

script:
- chef --version
Expand Down
95 changes: 95 additions & 0 deletions spec/dd-handler_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
require 'spec_helper'

shared_examples 'a chef-handler-datadog installer' do |version|
it 'includes chef_handler recipe' do
expect(chef_run).to include_recipe('chef_handler')
end

it 'installs the right version of chef-handler-datadog' do
expect(chef_run).to install_chef_gem('chef-handler-datadog').with(version: version)
end
end

shared_examples 'a chef-handler-datadog runner' do |extra_endpoints|
it 'runs the handler' do
handler_config = {
api_key: 'somethingnotnil',
application_key: 'somethingnotnil2',
use_ec2_instance_id: true,
tag_prefix: 'tag:',
url: 'https://app.datadoghq.com',
extra_endpoints: extra_endpoints || []
}

expect(chef_run).to enable_chef_handler('Chef::Handler::Datadog').with(
source: 'chef/handler/datadog',
arguments: [handler_config]
)
end
end

describe 'datadog::dd-handler' do
context 'standard usage' do
cached(:chef_run) do
ChefSpec::SoloRunner.new(
platform: 'ubuntu',
version: '14.04'
) do |node|
node.set['datadog']['api_key'] = 'somethingnotnil'
node.set['datadog']['application_key'] = 'somethingnotnil2'
node.set['datadog']['chef_handler_enable'] = true
node.set['datadog']['use_ec2_instance_id'] = true
end.converge described_recipe
end

it_behaves_like 'a chef-handler-datadog installer'

it_behaves_like 'a chef-handler-datadog runner'
end

context 'multiple endpoints' do
cached(:chef_run) do
ChefSpec::SoloRunner.new(
platform: 'ubuntu',
version: '14.04'
) do |node|
node.set['datadog']['api_key'] = 'somethingnotnil'
node.set['datadog']['application_key'] = 'somethingnotnil2'
node.set['datadog']['chef_handler_enable'] = true
node.set['datadog']['use_ec2_instance_id'] = true
node.set['datadog']['extra_endpoints']['qqqq']['enabled'] = true
node.set['datadog']['extra_endpoints']['qqqq']['api_key'] = 'something'
node.set['datadog']['extra_endpoints']['qqqq']['application_key'] = 'something2'
end.converge described_recipe
end

extra_endpoints = [
Mash.new(api_key: 'something',
application_key: 'something2')
]

it_behaves_like 'a chef-handler-datadog installer'

it_behaves_like 'a chef-handler-datadog runner', extra_endpoints
end
context 'multiple endpoints disabled' do
cached(:chef_run) do
ChefSpec::SoloRunner.new(
platform: 'ubuntu',
version: '14.04'
) do |node|
node.set['datadog']['api_key'] = 'somethingnotnil'
node.set['datadog']['application_key'] = 'somethingnotnil2'
node.set['datadog']['chef_handler_enable'] = true
node.set['datadog']['use_ec2_instance_id'] = true
node.set['datadog']['extra_endpoints']['qqqq']['enabled'] = false
node.set['datadog']['extra_endpoints']['qqqq']['api_key'] = 'something'
node.set['datadog']['extra_endpoints']['qqqq']['application_key'] = 'something2'
end.converge described_recipe
end

it_behaves_like 'a chef-handler-datadog installer'

it_behaves_like 'a chef-handler-datadog runner'
end
end

0 comments on commit bbe7268

Please sign in to comment.