[dd-agent][windows] Fix agent version pinning
When the `agent_version` attribute is a string.
Also added the test that would've caught the bug
MODIFY
recipes/_install-windows.rb
recipes/_install-windows.rb
@@ -21,7 +21,7 @@ dd_agent_version =
if node['datadog']['agent_version'].respond_to?(:each_pair)
node['datadog']['agent_version']['windows']
else
- node['datadog']['agent_verison']
+ node['datadog']['agent_version']
end
# If no version is specified, select the latest package

MODIFY
spec/dd-agent_spec.rb
spec/dd-agent_spec.rb
@@ -223,6 +223,7 @@ describe 'datadog::dd-agent' do
end
context 'allows a string for agent version' do
+ context 'on linux' do
cached(:chef_run) do
ChefSpec::SoloRunner.new(
:platform => 'ubuntu',
@@ -240,6 +241,34 @@ describe 'datadog::dd-agent' do
end
end
+ context 'on 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.set['datadog'] = {
+ 'api_key' => 'somethingnotnil',
+ 'agent_version' => '5.10.1'
+ }
+ end.converge described_recipe
+ end
+
+ temp_file = ::File.join('C:/chef/cache', 'ddagent-cli.msi')
+
+ it_behaves_like 'windows Datadog Agent'
+ # 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
+ it 'installs agent 5.10.1' do
+ expect(chef_run.remote_file(temp_file).source.to_s)
+ .to match(/ddagent-cli-5.10.1.msi/)
+ end
+ end
+ end
+
context 'allows a hash for agent version' do
context 'when ubuntu' do
cached(:chef_run) do

[dd-agent][windows] Fix agent version pinning (#400)

When the `agent_version` attribute is a string.

Also added the test that would've caught the bug