Skip to content

Commit

Permalink
Merge pull request #374 from nyanshak/fix/373-postfix-template
Browse files Browse the repository at this point in the history
Fixed #373 - Postfix template issue
  • Loading branch information
olivielpeau authored Nov 15, 2016
2 parents 3125ccc + 6202b0d commit fce3813
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
60 changes: 60 additions & 0 deletions spec/integrations/postfix_spec.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions templates/default/postfix.yaml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fce3813

Please sign in to comment.