|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe 'datadog_agent::integrations::activemq_xml' do |
| 4 | + context 'supported agents - v5 and v6' do |
| 5 | + agents = { '5' => true, '6' => false } |
| 6 | + agents.each do |_, is_agent5| |
| 7 | + let(:pre_condition) { "class {'::datadog_agent': agent5_enable => #{is_agent5}}" } |
| 8 | + let(:facts) {{ |
| 9 | + operatingsystem: 'Ubuntu', |
| 10 | + }} |
| 11 | + if is_agent5 |
| 12 | + let(:conf_dir) { '/etc/dd-agent/conf.d' } |
| 13 | + else |
| 14 | + let(:conf_dir) { '/etc/datadog-agent/conf.d' } |
| 15 | + end |
| 16 | + let(:dd_user) { 'dd-agent' } |
| 17 | + let(:dd_group) { 'root' } |
| 18 | + let(:dd_package) { 'datadog-agent' } |
| 19 | + let(:dd_service) { 'datadog-agent' } |
| 20 | + if is_agent5 |
| 21 | + let(:conf_file) { "#{conf_dir}/activemq_xml.yaml" } |
| 22 | + else |
| 23 | + let(:conf_file) { "#{conf_dir}/activemq_xml.d/conf.yaml" } |
| 24 | + end |
| 25 | + |
| 26 | + context 'with default parameters' do |
| 27 | + it { should compile } |
| 28 | + end |
| 29 | + |
| 30 | + context 'with password set' do |
| 31 | + let(:params) {{ |
| 32 | + username: 'foo', |
| 33 | + password: 'abc123', |
| 34 | + }} |
| 35 | + |
| 36 | + it { should compile.with_all_deps } |
| 37 | + it { should contain_file(conf_file).with( |
| 38 | + owner: dd_user, |
| 39 | + group: dd_group, |
| 40 | + mode: '0600', |
| 41 | + )} |
| 42 | + it { should contain_file(conf_file).that_requires("Package[#{dd_package}]") } |
| 43 | + it { should contain_file(conf_file).that_notifies("Service[#{dd_service}]") } |
| 44 | + it { should contain_file(conf_file).with_content(/username: foo/) } |
| 45 | + it { should contain_file(conf_file).with_content(/password: abc123/) } |
| 46 | + |
| 47 | + context 'with default parameters' do |
| 48 | + it { |
| 49 | + should contain_file(conf_file) |
| 50 | + .with_content(%r{http://localhost:8161}) |
| 51 | + .with_content(%r{supress_errors: false}) |
| 52 | + .without_content(%r{detailed_queues:}) |
| 53 | + .without_content(%r{detailed_topics:}) |
| 54 | + .without_content(%r{detailed_subscribers:}) |
| 55 | + } |
| 56 | + end |
| 57 | + |
| 58 | + context 'with extra detailed parameters' do |
| 59 | + let(:params) {{ |
| 60 | + supress_errors: true, |
| 61 | + detailed_queues: %w(queue1 queue2), |
| 62 | + detailed_topics: %w(topic1 topic2), |
| 63 | + detailed_subscribers: %w(subscriber1 subscriber2), |
| 64 | + }} |
| 65 | + it { |
| 66 | + should contain_file(conf_file) |
| 67 | + .with_content(%r{http://localhost:8161}) |
| 68 | + .with_content(%r{supress_errors: true}) |
| 69 | + .with_content(%r{detailed_queues:.*\s+- queue1\s+- queue2}) |
| 70 | + .with_content(%r{detailed_topics:.*\s+- topic1\s+- topic2}) |
| 71 | + .with_content(%r{detailed_subscribers:.*\s+- subscriber1\s+- subscriber2}) |
| 72 | + } |
| 73 | + end |
| 74 | + |
| 75 | + context 'with instances set' do |
| 76 | + let(:params) {{ |
| 77 | + instances: [ |
| 78 | + { |
| 79 | + 'url' => 'http://localhost:8161', |
| 80 | + 'username' => 'joe', |
| 81 | + 'password' => 'hunter1', |
| 82 | + 'detailed_queues' => %w(queue1 queue2), |
| 83 | + 'detailed_topics' => %w(topic1 topic2), |
| 84 | + 'detailed_subscribers' => %w(subscriber1 subscriber2), |
| 85 | + }, |
| 86 | + { |
| 87 | + 'url' => 'http://remotehost:8162', |
| 88 | + 'username' => 'moe', |
| 89 | + 'password' => 'hunter2', |
| 90 | + 'detailed_queues' => %w(queue3 queue4), |
| 91 | + 'detailed_topics' => %w(topic3 topic4), |
| 92 | + 'detailed_subscribers' => %w(subscriber3 subscriber4), |
| 93 | + }, |
| 94 | + ], |
| 95 | + }} |
| 96 | + it { |
| 97 | + should contain_file(conf_file) |
| 98 | + .with_content(%r{url: http://localhost:8161}) |
| 99 | + .without_content(%r{supress_errors:}) |
| 100 | + .with_content(%r{username: joe}) |
| 101 | + .with_content(%r{password: hunter1}) |
| 102 | + .with_content(%r{detailed_queues:.*\s+- queue1\s+- queue2}) |
| 103 | + .with_content(%r{detailed_topics:.*\s+- topic1\s+- topic2}) |
| 104 | + .with_content(%r{detailed_subscribers:.*\s+- subscriber1\s+- subscriber2}) |
| 105 | + .with_content(%r{url: http://remotehost:8162}) |
| 106 | + .without_content(%r{supress_errors:}) |
| 107 | + .with_content(%r{username: moe}) |
| 108 | + .with_content(%r{password: hunter2}) |
| 109 | + .with_content(%r{detailed_queues:.*\s+- queue3\s+- queue4}) |
| 110 | + .with_content(%r{detailed_topics:.*\s+- topic3\s+- topic4}) |
| 111 | + .with_content(%r{detailed_subscribers:.*\s+- subscriber3\s+- subscriber4}) |
| 112 | + } |
| 113 | + end |
| 114 | + end |
| 115 | + end |
| 116 | + end |
| 117 | +end |
0 commit comments