Skip to content

Commit

Permalink
Fix postgres template syntax and parameter output (#304)
Browse files Browse the repository at this point in the history
- Use correct `.key?` syntax, Fix #300
- Emit correct boolean, introduced in #278
- Add postgres spec test

Closes #302

Signed-off-by: Mike Fiedler <[email protected]>
  • Loading branch information
miketheman committed May 4, 2016
1 parent b8cb6dc commit d6eb9d9
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
57 changes: 57 additions & 0 deletions spec/integrations/postgres_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
describe 'datadog::postgres' do
expected_yaml = <<-EOF
instances:
- host: localhost
port: 5432
ssl: true
username: datadog
password: somepass
dbname: my_database
tags:
- spec
relations:
- apple_table
- orange_table
collect_function_metrics: true
init_config:
EOF

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',
postgres: {
instances: [
{
collect_function_metrics: true,
dbname: 'my_database',
password: 'somepass',
port: 5432,
relations: ['apple_table', 'orange_table'],
server: 'localhost',
ssl: true,
tags: ['spec'],
username: 'datadog'
}
]
}
}
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('postgres') }

it 'renders expected YAML config file' do
expect(chef_run).to render_file('/etc/dd-agent/conf.d/postgres.yaml').with_content { |content|
expect(YAML.load(content).to_json).to be_json_eql(YAML.load(expected_yaml).to_json)
}
end
end
4 changes: 2 additions & 2 deletions templates/default/postgres.yaml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ instances:
- <%= r %>
<% end -%>
<% end -%>
<% if i.keys?("collect_function_metrics") -%>
collect_function_metrics: i["collect_function_metrics"]
<%- if i.key?("collect_function_metrics") %>
collect_function_metrics: <%= i["collect_function_metrics"] %>
<% end -%>
<% end -%>

0 comments on commit d6eb9d9

Please sign in to comment.