diff --git a/spec/classes/datadog_agent_integrations_redis_spec.rb b/spec/classes/datadog_agent_integrations_redis_spec.rb index 4a96f7f7..50173bbc 100644 --- a/spec/classes/datadog_agent_integrations_redis_spec.rb +++ b/spec/classes/datadog_agent_integrations_redis_spec.rb @@ -137,6 +137,42 @@ it { should contain_file(conf_file).without_content(%r{warn_on_missing_keys: false}) } it { should contain_file(conf_file).without_content(%r{command_stats: true}) } end + + context 'with only keys' do + let(:params) {{ + instances: [ + { + 'host' => 'redis1', + 'password' => 'hunter2', + 'port' => 2379, + 'tags' => %w(), + 'keys' => %w(baz bat), + }, + ], + }} + it { should contain_file(conf_file).with_content(%r{host: redis1}) } + it { should contain_file(conf_file).with_content(%r{^[^#]*password: hunter2}) } + it { should contain_file(conf_file).with_content(%r{port: 2379}) } + it { should contain_file(conf_file).with_content(%r{keys:.*\s+- baz\s+- bat}) } + end + + context 'with only tags' do + let(:params) {{ + instances: [ + { + 'host' => 'redis1', + 'password' => 'hunter2', + 'port' => 2379, + 'tags' => %w(baz bat), + 'keys' => %w(), + }, + ], + }} + it { should contain_file(conf_file).with_content(%r{host: redis1}) } + it { should contain_file(conf_file).with_content(%r{^[^#]*password: hunter2}) } + it { should contain_file(conf_file).with_content(%r{port: 2379}) } + it { should contain_file(conf_file).with_content(%r{tags:.*\s+- baz\s+- bat}) } + end end end end diff --git a/templates/agent-conf.d/redisdb.yaml.erb b/templates/agent-conf.d/redisdb.yaml.erb index 20afb87c..64d4d0c7 100644 --- a/templates/agent-conf.d/redisdb.yaml.erb +++ b/templates/agent-conf.d/redisdb.yaml.erb @@ -19,7 +19,7 @@ instances: <% if !instance['command_stats'].nil? -%> command_stats: <%= instance['command_stats'] %> <% end -%> -<% if instance['keys'] and unless instance['keys'].empty? -%> +<% if instance['keys'] and ! instance['keys'].empty? -%> keys: <%- Array(instance['keys'] ).each do |key| -%> <%- if key != '' -%> @@ -27,7 +27,7 @@ instances: <%- end -%> <%- end -%> <% end -%> -<% if instance['tags'] and unless instance['tags'].empty? -%> +<% if instance['tags'] and ! instance['tags'].empty? -%> tags: <%- Array(instance['tags'] ).each do |tag| -%> <%- if tag != '' -%> @@ -36,6 +36,3 @@ instances: <%- end -%> <% end -%> <% end -%> - -<% end -%> -<% end -%>