Fix Chef spec.
MODIFY
spec/dd-agent_spec.rb
spec/dd-agent_spec.rb
@@ -232,6 +232,9 @@ describe 'datadog::dd-agent' do
end
end
+ # Allow a hash for Agent version 6
+ # ----------------------
+
context 'allows a hash for agent version' do
context 'when ubuntu' do
cached(:chef_run) do
@@ -240,7 +243,7 @@ describe 'datadog::dd-agent' do
:version => '14.04'
) do |node|
node.normal['datadog'] = {
- 'agent6' => false,
+ 'agent6' => true,
'api_key' => 'somethingnotnil',
'agent6_version' => {
'debian' => '1:6.9.0-1',
@@ -298,7 +301,7 @@ describe 'datadog::dd-agent' do
:version => '25'
) do |node|
node.normal['datadog'] = {
- 'agent6' => false,
+ 'agent6' => true,
'api_key' => 'somethingnotnil',
'agent6_version' => {
'debian' => '1:6.9.0-1',
@@ -321,7 +324,7 @@ describe 'datadog::dd-agent' do
:version => '6.9'
) do |node|
node.normal['datadog'] = {
- 'agent6' => false,
+ 'agent6' => true,
'api_key' => 'somethingnotnil',
'agent6_version' => {
'debian' => '1:6.9.0-1',
@@ -338,6 +341,107 @@ describe 'datadog::dd-agent' do
end
end
+ # Allow a hash for Agent version 5
+ # ----------------------
+
+ context 'allows a hash for agent version v5' do
+ context 'when ubuntu' do
+ cached(:chef_run) do
+ ChefSpec::SoloRunner.new(
+ :platform => 'ubuntu',
+ :version => '14.04'
+ ) do |node|
+ node.normal['datadog'] = {
+ 'agent6' => false,
+ 'api_key' => 'somethingnotnil',
+ 'agent_version' => {
+ 'debian' => '1:5.32.2-1',
+ 'rhel' => '5.32.2-1',
+ 'windows' => '5.4.0'
+ },
+ }
+ end.converge described_recipe
+ end
+
+ it_behaves_like 'debianoids datadog-agent v5'
+ end
+
+ context 'when windows' do
+ cached(:chef_run) do
+ set_env_var('ProgramData', 'C:\ProgramData')
+ ChefSpec::SoloRunner.new(
+ :platform => 'windows',
+ :version => '2012R2',
+ :file_cache_path => 'C:/chef/cache'
+ ) do |node|
+ node.normal['datadog'] = {
+ 'agent6' => false,
+ 'api_key' => 'somethingnotnil',
+ 'agent_version' => {
+ 'debian' => '1:5.32.2-1',
+ 'rhel' => '5.32.2-1',
+ 'windows' => '5.4.0'
+ },
+ }
+ end.converge described_recipe
+ end
+
+ temp_file = ::File.join('C:/chef/cache', 'ddagent-cli.msi')
+
+ it_behaves_like 'windows Datadog Agent v5', :msi
+ # remote_file source gets converted to an array, so we need to do
+ # some tricky things to be able to regex against it
+ # Relevant: http://stackoverflow.com/a/12325983
+ # But we should probably assert the full default attribute somewhere...
+ it 'installs agent 5.4.0' do
+ expect(chef_run.remote_file(temp_file).source.to_s)
+ .to match(/ddagent-cli-5.4.0.msi/)
+ end
+ end
+
+ context 'when fedora' do
+ cached(:chef_run) do
+ ChefSpec::SoloRunner.new(
+ :platform => 'fedora',
+ :version => '25'
+ ) do |node|
+ node.normal['datadog'] = {
+ 'agent6' => false,
+ 'api_key' => 'somethingnotnil',
+ 'agent6_version' => {
+ 'debian' => '1:5.32.2-1',
+ 'rhel' => '5.32.2-1',
+ 'windows' => '5.4.0'
+ },
+ }
+ end.converge described_recipe
+ end
+
+ it_behaves_like 'rhellions datadog-agent v5'
+ end
+
+ context 'when rhel' do
+ cached(:chef_run) do
+ ChefSpec::SoloRunner.new(
+ :platform => 'redhat',
+ :version => '6.9'
+ ) do |node|
+ node.normal['datadog'] = {
+ 'agent6' => false,
+ 'api_key' => 'somethingnotnil',
+ 'agent_version' => {
+ 'debian' => '1:5.32.2-1',
+ 'rhel' => '5.32.2-1',
+ 'windows' => '5.4.0'
+ },
+ }
+ end.converge described_recipe
+ end
+
+ it_behaves_like 'rhellions datadog-agent v5'
+ end
+ end
+
context 'package action' do
context 'default :install' do
cached(:chef_run) do

MODIFY
spec/shared_examples.rb
spec/shared_examples.rb
@@ -46,10 +46,22 @@ shared_examples_for 'common linux resources' do
end
end
+shared_examples_for 'datadog-agent v5' do
+ it_behaves_like 'common linux resources v5'
+end
+
shared_examples_for 'datadog-agent' do
it_behaves_like 'common linux resources'
end
+shared_examples_for 'debianoids datadog-agent v5' do
+ it_behaves_like 'datadog-agent v5'
+
+ it 'installs the datadog-agent' do
+ expect(chef_run).to install_apt_package 'datadog-agent'
+ end
+end
+
shared_examples_for 'debianoids datadog-agent' do
it_behaves_like 'datadog-agent'
@@ -58,6 +70,14 @@ shared_examples_for 'debianoids datadog-agent' do
end
end
+shared_examples_for 'rhellions datadog-agent v5' do
+ it_behaves_like 'datadog-agent v5'
+
+ it 'installs the datadog-agent' do
+ expect(chef_run).to install_yum_package 'datadog-agent'
+ end
+end
+
shared_examples_for 'rhellions datadog-agent' do
it_behaves_like 'datadog-agent'

Fix Chef spec.