From 12e844c511bb936b9070fae1f4bf6754d2aec195 Mon Sep 17 00:00:00 2001 From: Mike Fiedler Date: Tue, 3 May 2016 19:03:16 -0400 Subject: [PATCH] Fix postgres template syntax and parameter output - Use correct `.key?` syntax, Fix #300 - Emit correct boolean, introduced in #278 - Add postgres spec test Closes #302 Signed-off-by: Mike Fiedler --- spec/integrations/postgres_spec.rb | 57 +++++++++++++++++++++++++++++ templates/default/postgres.yaml.erb | 4 +- 2 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 spec/integrations/postgres_spec.rb diff --git a/spec/integrations/postgres_spec.rb b/spec/integrations/postgres_spec.rb new file mode 100644 index 00000000..d9a67ac7 --- /dev/null +++ b/spec/integrations/postgres_spec.rb @@ -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 diff --git a/templates/default/postgres.yaml.erb b/templates/default/postgres.yaml.erb index 094b3780..4bbbf457 100644 --- a/templates/default/postgres.yaml.erb +++ b/templates/default/postgres.yaml.erb @@ -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 -%>