From 95c6e4110f0c3ce84e8766b21fda9133f6111129 Mon Sep 17 00:00:00 2001 From: Brendan Shaklovitz Date: Mon, 17 Oct 2016 16:58:38 -0500 Subject: [PATCH 1/2] Fixed #373 - Postfix template issue --- templates/default/postfix.yaml.erb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/templates/default/postfix.yaml.erb b/templates/default/postfix.yaml.erb index 26d2b77c..fd2bf6a5 100644 --- a/templates/default/postfix.yaml.erb +++ b/templates/default/postfix.yaml.erb @@ -7,10 +7,12 @@ instances: <% Array(instance['queues']).each do |queue| -%> - <%= queue %> <% end -%> + <% if instance.key?('tags') -%> tags: <% Array(instance['tags']).each do |tag| -%> - <%= tag %> <% end -%> + <% end -%> <% end -%> # Postfix check does not require any init_config From 6202b0d51577a87d1745d4fa41671d0be9225af3 Mon Sep 17 00:00:00 2001 From: Olivier Vielpeau Date: Mon, 14 Nov 2016 20:05:16 -0500 Subject: [PATCH 2/2] [postfix] Add spec test --- spec/integrations/postfix_spec.rb | 60 +++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 spec/integrations/postfix_spec.rb diff --git a/spec/integrations/postfix_spec.rb b/spec/integrations/postfix_spec.rb new file mode 100644 index 00000000..dc24bb30 --- /dev/null +++ b/spec/integrations/postfix_spec.rb @@ -0,0 +1,60 @@ +describe 'datadog::postfix' do + expected_yaml = <<-EOF + instances: + - directory: /var/spool/postfix + queues: + - incoming + - active + - deferred + tags: + - prod + - postfix_core + - directory: /var/spool/postfix + queues: + - bounce + init_config: + EOF + + before do + allow_any_instance_of(Chef::Recipe).to receive(:include_recipe).and_call_original + allow_any_instance_of(Chef::Recipe).to receive(:include_recipe).with('sudo') + allow_any_instance_of(Chef::Recipe).to receive(:sudo) + end + + cached(:chef_run) do + ChefSpec::SoloRunner.new(step_into: ['datadog_monitor']) do |node| + node.automatic['languages'] = { python: { version: '2.7.2' } } + + node.set['datadog'] = { + api_key: 'someapikey', + postfix: { + instances: [ + { + directory: '/var/spool/postfix', + queues: ['incoming', 'active', 'deferred'], + tags: ['prod', 'postfix_core'] + }, + { + directory: '/var/spool/postfix', + queues: ['bounce'] + } + ] + } + } + end.converge(described_recipe) + end + + subject { chef_run } + + it_behaves_like 'datadog-agent' + + it { is_expected.to include_recipe('datadog::dd-agent') } + + it { is_expected.to add_datadog_monitor('postfix') } + + it 'renders expected YAML config file' do + expect(chef_run).to render_file('/etc/dd-agent/conf.d/postfix.yaml').with_content { |content| + expect(YAML.load(content).to_json).to be_json_eql(YAML.load(expected_yaml).to_json) + } + end +end