[spec] Fix hardcoded paths
MODIFY
spec/dd-agent_spec.rb
spec/dd-agent_spec.rb
@@ -133,14 +133,13 @@ describe 'datadog::dd-agent' do
set_env_var('ProgramData', 'C:\ProgramData')
ChefSpec::SoloRunner.new(
:platform => 'windows',
- :version => '2012R2',
- :file_cache_path => 'C:/chef/cache'
+ :version => '2012R2'
) do |node|
node.normal['datadog'] = { 'api_key' => 'somethingnotnil' }
end.converge described_recipe
end
- temp_file = ::File.join('C:/chef/cache', 'ddagent-cli.msi')
+ temp_file = ::File.join(Chef::Config[:file_cache_path], 'ddagent-cli.msi')
mock_digest = Digest::SHA256.new
before do
@@ -161,8 +160,7 @@ describe 'datadog::dd-agent' do
set_env_var('ProgramData', 'C:\ProgramData')
ChefSpec::SoloRunner.new(
:platform => 'windows',
- :version => '2012R2',
- :file_cache_path => 'C:/chef/cache'
+ :version => '2012R2'
) do |node|
node.normal['datadog'] = {
'api_key' => 'somethingnotnil',
@@ -171,7 +169,7 @@ describe 'datadog::dd-agent' do
end.converge described_recipe
end
- temp_file = ::File.join('C:/chef/cache', 'ddagent-cli.exe')
+ temp_file = ::File.join(Chef::Config[:file_cache_path], 'ddagent-cli.exe')
mock_digest = Digest::SHA256.new
before do
@@ -236,18 +234,17 @@ describe 'datadog::dd-agent' do
ChefSpec::SoloRunner.new(
:platform => 'windows',
- :version => '2012R2',
- :file_cache_path => 'C:/chef/cache'
+ :version => '2012R2'
) do |node|
node.normal['datadog'] = {
'agent_major_version' => 5,
'api_key' => 'somethingnotnil',
- 'agent_version' => '5.10.1'
+ 'agent_version' => '5.10.1',
}
end.converge described_recipe
end
- temp_file = ::File.join('C:/chef/cache', 'ddagent-cli.msi')
+ temp_file = ::File.join(Chef::Config[:file_cache_path], 'ddagent-cli.msi')
mock_digest = Digest::SHA256.new
before do
@@ -275,8 +272,7 @@ describe 'datadog::dd-agent' do
set_env_var('ProgramData', 'C:\ProgramData')
ChefSpec::SoloRunner.new(
:platform => 'windows',
- :version => '2012R2',
- :file_cache_path => 'C:/chef/cache'
+ :version => '2012R2'
) do |node|
node.normal['datadog'] = {
'api_key' => 'somethingnotnil',
@@ -285,7 +281,7 @@ describe 'datadog::dd-agent' do
end.converge described_recipe
end
- temp_file = ::File.join('C:/chef/cache', 'ddagent-cli.msi')
+ temp_file = ::File.join(Chef::Config[:file_cache_path], 'ddagent-cli.msi')
it 'installs Datadog Agent' do
expect(chef_run).to install_windows_package('Datadog Agent').with(installer_type: :msi)
@@ -331,8 +327,7 @@ describe 'datadog::dd-agent' do
ChefSpec::SoloRunner.new(
:platform => 'windows',
- :version => '2012R2',
- :file_cache_path => 'C:/chef/cache'
+ :version => '2012R2'
) do |node|
node.normal['datadog'] = {
'agent_major_version' => 6,
@@ -346,7 +341,7 @@ describe 'datadog::dd-agent' do
end.converge described_recipe
end
- temp_file = ::File.join('C:/chef/cache', 'ddagent-cli.msi')
+ temp_file = ::File.join(Chef::Config[:file_cache_path], 'ddagent-cli.msi')
mock_digest = Digest::SHA256.new
before do
@@ -375,8 +370,7 @@ describe 'datadog::dd-agent' do
set_env_var('ProgramData', 'C:\ProgramData')
ChefSpec::SoloRunner.new(
:platform => 'windows',
- :version => '2012R2',
- :file_cache_path => 'C:/chef/cache'
+ :version => '2012R2'
) do |node|
node.normal['datadog'] = {
'agent_major_version' => 6,
@@ -392,7 +386,7 @@ describe 'datadog::dd-agent' do
end.converge described_recipe
end
- temp_file = ::File.join('C:/chef/cache', 'ddagent-cli.msi')
+ temp_file = ::File.join(Chef::Config[:file_cache_path], 'ddagent-cli.msi')
mock_digest = Digest::SHA256.new
before do
@@ -487,8 +481,7 @@ describe 'datadog::dd-agent' do
set_env_var('ProgramData', 'C:\ProgramData')
ChefSpec::SoloRunner.new(
:platform => 'windows',
- :version => '2012R2',
- :file_cache_path => 'C:/chef/cache'
+ :version => '2012R2'
) do |node|
node.normal['datadog'] = {
'agent_major_version' => 5,
@@ -502,7 +495,7 @@ describe 'datadog::dd-agent' do
end.converge described_recipe
end
- temp_file = ::File.join('C:/chef/cache', 'ddagent-cli.msi')
+ temp_file = ::File.join(Chef::Config[:file_cache_path], 'ddagent-cli.msi')
mock_digest = Digest::SHA256.new
before do
@@ -1089,15 +1082,14 @@ describe 'datadog::dd-agent' do
set_env_var('ProgramData', 'C:\ProgramData')
ChefSpec::SoloRunner.new(
platform: 'windows',
- version: '2012R2',
- file_cache_path: 'C:/chef/cache'
+ version: '2012R2'
) do |node|
node.name 'chef-nodename' # expected to be used as the hostname in `datadog.yaml`
node.normal['datadog'] = { 'api_key' => 'somethingnotnil', 'agent_major_version' => 6 }
end.converge described_recipe
end
- temp_file = ::File.join('C:/chef/cache', 'ddagent-cli.msi')
+ temp_file = ::File.join(Chef::Config[:file_cache_path], 'ddagent-cli.msi')
mock_digest = Digest::SHA256.new
before do
@@ -1166,7 +1158,7 @@ describe 'datadog::dd-agent' do
end.converge described_recipe
end
- temp_file = ::File.join('C:/chef/cache', 'ddagent-cli.msi')
+ temp_file = ::File.join(Chef::Config[:file_cache_path], 'ddagent-cli.msi')
mock_digest = Digest::SHA256.new
before do
@@ -1224,8 +1216,7 @@ describe 'datadog::dd-agent' do
set_env_var('ProgramData', 'C:\ProgramData')
ChefSpec::SoloRunner.new(
:platform => 'windows',
- :version => '2012R2',
- :file_cache_path => 'C:/chef/cache'
+ :version => '2012R2'
) do |node|
node.normal['datadog'] = {
'api_key' => 'somethingnotnil',
@@ -1235,7 +1226,7 @@ describe 'datadog::dd-agent' do
end.converge described_recipe
end
- temp_file = ::File.join('C:/chef/cache', 'ddagent-cli.msi')
+ temp_file = ::File.join(Chef::Config[:file_cache_path], 'ddagent-cli.msi')
mock_digest = Digest::SHA256.new
before do
@@ -1263,8 +1254,8 @@ describe 'datadog::dd-agent' do
set_env_var('ProgramData', 'C:\ProgramData')
ChefSpec::SoloRunner.new(
:platform => 'windows',
- :version => '2012R2',
- :file_cache_path => 'C:/chef/cache'
+ :version => '2012R2'
+
) do |node|
node.normal['datadog'] = {
'api_key' => 'somethingnotnil',
@@ -1273,7 +1264,7 @@ describe 'datadog::dd-agent' do
end.converge described_recipe
end
- temp_file = ::File.join('C:/chef/cache', 'ddagent-cli.msi')
+ temp_file = ::File.join(Chef::Config[:file_cache_path], 'ddagent-cli.msi')
it 'installs Datadog Agent' do
expect(chef_run).to install_windows_package('Datadog Agent').with(installer_type: :msi)

MODIFY
spec/repository_spec.rb
spec/repository_spec.rb
@@ -46,7 +46,7 @@ describe 'datadog::repository' do
end
it 'downloads the new RPM key' do
- expect(chef_run).to create_remote_file('DATADOG_RPM_KEY_E09422B3.public').with(path: '/var/chef/cache/DATADOG_RPM_KEY_E09422B3.public')
+ expect(chef_run).to create_remote_file('DATADOG_RPM_KEY_E09422B3.public').with(path: ::File.join(Chef::Config[:file_cache_path], 'DATADOG_RPM_KEY_E09422B3.public'))
end
it 'notifies the GPG key install if a new one is downloaded' do
@@ -88,7 +88,7 @@ describe 'datadog::repository' do
end
it 'downloads the new RPM key' do
- expect(chef_run).to create_remote_file('DATADOG_RPM_KEY_E09422B3.public').with(path: '/var/chef/cache/DATADOG_RPM_KEY_E09422B3.public')
+ expect(chef_run).to create_remote_file('DATADOG_RPM_KEY_E09422B3.public').with(path: ::File.join(Chef::Config[:file_cache_path], 'DATADOG_RPM_KEY_E09422B3.public'))
end
it 'notifies the GPG key install if a new one is downloaded' do
@@ -130,7 +130,7 @@ describe 'datadog::repository' do
end
it 'downloads the new RPM key' do
- expect(chef_run).to create_remote_file('DATADOG_RPM_KEY_E09422B3.public').with(path: '/var/chef/cache/DATADOG_RPM_KEY_E09422B3.public')
+ expect(chef_run).to create_remote_file('DATADOG_RPM_KEY_E09422B3.public').with(path: ::File.join(Chef::Config[:file_cache_path], 'DATADOG_RPM_KEY_E09422B3.public'))
end
it 'notifies the GPG key install if a new one is downloaded' do

MODIFY
spec/shared_examples.rb
spec/shared_examples.rb
@@ -119,7 +119,7 @@ end
shared_examples_for 'windows Datadog Agent v5' do |installer_extension|
it_behaves_like 'common windows resources v5'
- agent_installer = "C:/chef/cache/ddagent-cli.#{installer_extension}"
+ agent_installer = ::File.join(Chef::Config[:file_cache_path], "ddagent-cli.#{installer_extension}")
it 'downloads the remote file only if it\'s changed' do
expect(chef_run).to create_remote_file(agent_installer)
@@ -146,7 +146,7 @@ end
shared_examples_for 'windows Datadog Agent' do |installer_extension|
it_behaves_like 'common windows resources'
- agent_installer = "C:/chef/cache/ddagent-cli.#{installer_extension}"
+ agent_installer = ::File.join(Chef::Config[:file_cache_path], "ddagent-cli.#{installer_extension}")
it 'downloads the remote file only if it\'s changed' do
expect(chef_run).to create_remote_file(agent_installer)

MODIFY
spec/spec_helper.rb
spec/spec_helper.rb
@@ -19,7 +19,7 @@ RSpec.configure do |config|
# @see https://github.com/chef-cookbooks/yum/issues/140
config.log_level = :error
- config.file_cache_path = '/var/chef/cache'
+ config.file_cache_path = Chef::Config[:file_cache_path]
config.before do
# recipes/dd-agent.rb

[spec] Fix hardcoded paths (#742)

Co-authored-by: Jaime Fullaondo <jaime.fullaondo@datadoghq.com>