From 0de252be87275ddd9c78f06435acf8040c2170e0 Mon Sep 17 00:00:00 2001 From: Simonas Rupsys Date: Tue, 16 Jul 2019 14:08:24 +0300 Subject: [PATCH] Add support for section arguments --- libraries/helpers.rb | 5 +++-- metadata.rb | 2 +- spec/unit/resources/td_agent_match_spec.rb | 2 ++ test/fixtures/smoke/recipes/default.rb | 18 ++++++++++++++++++ test/fixtures/td-agent-spec/recipes/match.rb | 11 +++++++++++ .../1x-chef12/bash/spec/localhost/lwrp_spec.rb | 8 ++++++++ .../2x-chef12/bash/spec/localhost/lwrp_spec.rb | 8 ++++++++ .../2x-chef13/bash/spec/localhost/lwrp_spec.rb | 8 ++++++++ 8 files changed, 59 insertions(+), 3 deletions(-) diff --git a/libraries/helpers.rb b/libraries/helpers.rb index 11846de..0919874 100644 --- a/libraries/helpers.rb +++ b/libraries/helpers.rb @@ -4,14 +4,15 @@ module Helpers def self.params_to_text(parameters) body = '' parameters.each do |param_key, param_value| + param_key_closing_tag = param_key.to_s.split.first if param_value.is_a?(Hash) body += "<#{param_key}>\n" body += params_to_text(param_value) - body += "\n" + body += "\n" elsif param_value.is_a?(Array) if param_value.all? { |array_value| array_value.is_a?(Hash) } body += param_value.map { |array_value| - "<#{param_key}>\n#{params_to_text(array_value)}\n" + "<#{param_key}>\n#{params_to_text(array_value)}\n" }.join else body += "#{param_key} [#{param_value.map { |array_value| array_value.to_s.dump }.join(", ")}]\n" diff --git a/metadata.rb b/metadata.rb index b4aa6d3..8be98d8 100644 --- a/metadata.rb +++ b/metadata.rb @@ -4,7 +4,7 @@ license "Apache 2.0" description "Installs/Configures td-agent" long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version "3.2.1" +version "3.3.0" recipe "td-agent", "td-agent configuration" chef_version ">= 12" if respond_to?(:chef_version) diff --git a/spec/unit/resources/td_agent_match_spec.rb b/spec/unit/resources/td_agent_match_spec.rb index 27040a1..938c483 100644 --- a/spec/unit/resources/td_agent_match_spec.rb +++ b/spec/unit/resources/td_agent_match_spec.rb @@ -32,9 +32,11 @@ it 'creates unit test output' do expect(chef_run).to create_td_agent_match('01_out_file') + expect(chef_run).to create_td_agent_match('02_buffer_with_arguments') end it 'creates the output config file' do expect(chef_run).to create_template('/etc/td-agent/conf.d/01_out_file.conf') + expect(chef_run).to create_template('/etc/td-agent/conf.d/02_buffer_with_arguments.conf') end end diff --git a/test/fixtures/smoke/recipes/default.rb b/test/fixtures/smoke/recipes/default.rb index c9b2d30..545bb52 100644 --- a/test/fixtures/smoke/recipes/default.rb +++ b/test/fixtures/smoke/recipes/default.rb @@ -101,6 +101,24 @@ end end +td_agent_match 'test_section_attributes' do + type 'null' + tag 'null.*' + if TdAgent::Helpers.apply_params_kludge? + params( + 'buffer tag, argument1, argument2' => { + timekey: '1d' + } + ) + else + parameters( + 'buffer tag, argument1, argument2' => { + timekey: '1d' + } + ) + end +end + td_agent_filter 'test_filter' do type 'record_transformer' tag 'webserver.*' diff --git a/test/fixtures/td-agent-spec/recipes/match.rb b/test/fixtures/td-agent-spec/recipes/match.rb index 2cd95eb..790d2cb 100644 --- a/test/fixtures/td-agent-spec/recipes/match.rb +++ b/test/fixtures/td-agent-spec/recipes/match.rb @@ -14,3 +14,14 @@ } ) end + +td_agent_match '02_buffer_with_arguments' do + action :create + type 'null' + tag 'output.null' + parameters( + 'buffer tag, argument1, argument2' => { + timekey: '1d' + } + ) +end diff --git a/test/integration/1x-chef12/bash/spec/localhost/lwrp_spec.rb b/test/integration/1x-chef12/bash/spec/localhost/lwrp_spec.rb index 6aff86c..274c436 100644 --- a/test/integration/1x-chef12/bash/spec/localhost/lwrp_spec.rb +++ b/test/integration/1x-chef12/bash/spec/localhost/lwrp_spec.rb @@ -40,6 +40,14 @@ # its(:content) { should match %r|^\s*exclude_path\s+\["/tmp/access\.log\.\*\.gz",\s+"/tmp/access\.log\.\*\.bz2"\]$| } end +describe file('/etc/td-agent/conf.d/test_section_attributes.conf') do + it { should be_a_file } + it { should be_mode 644 } + its(:content) { should match %r|^\s*.type null$| } + its(:content) { should match %r|^\s*$| } + its(:content) { should match %r|^\s*$| } +end + describe file('/etc/td-agent/conf.d/test_gelf_match.conf') do it { should be_a_file } it { should be_mode 644 } diff --git a/test/integration/2x-chef12/bash/spec/localhost/lwrp_spec.rb b/test/integration/2x-chef12/bash/spec/localhost/lwrp_spec.rb index 6aff86c..274c436 100644 --- a/test/integration/2x-chef12/bash/spec/localhost/lwrp_spec.rb +++ b/test/integration/2x-chef12/bash/spec/localhost/lwrp_spec.rb @@ -40,6 +40,14 @@ # its(:content) { should match %r|^\s*exclude_path\s+\["/tmp/access\.log\.\*\.gz",\s+"/tmp/access\.log\.\*\.bz2"\]$| } end +describe file('/etc/td-agent/conf.d/test_section_attributes.conf') do + it { should be_a_file } + it { should be_mode 644 } + its(:content) { should match %r|^\s*.type null$| } + its(:content) { should match %r|^\s*$| } + its(:content) { should match %r|^\s*$| } +end + describe file('/etc/td-agent/conf.d/test_gelf_match.conf') do it { should be_a_file } it { should be_mode 644 } diff --git a/test/integration/2x-chef13/bash/spec/localhost/lwrp_spec.rb b/test/integration/2x-chef13/bash/spec/localhost/lwrp_spec.rb index 6aff86c..274c436 100644 --- a/test/integration/2x-chef13/bash/spec/localhost/lwrp_spec.rb +++ b/test/integration/2x-chef13/bash/spec/localhost/lwrp_spec.rb @@ -40,6 +40,14 @@ # its(:content) { should match %r|^\s*exclude_path\s+\["/tmp/access\.log\.\*\.gz",\s+"/tmp/access\.log\.\*\.bz2"\]$| } end +describe file('/etc/td-agent/conf.d/test_section_attributes.conf') do + it { should be_a_file } + it { should be_mode 644 } + its(:content) { should match %r|^\s*.type null$| } + its(:content) { should match %r|^\s*$| } + its(:content) { should match %r|^\s*$| } +end + describe file('/etc/td-agent/conf.d/test_gelf_match.conf') do it { should be_a_file } it { should be_mode 644 }