|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe 'datadog_agent::integrations::jmx' do |
| 4 | + let(:facts) {{ |
| 5 | + operatingsystem: 'Ubuntu', |
| 6 | + }} |
| 7 | + let(:conf_dir) { '/etc/dd-agent/conf.d' } |
| 8 | + let(:dd_user) { 'dd-agent' } |
| 9 | + let(:dd_group) { 'root' } |
| 10 | + let(:dd_package) { 'datadog-agent' } |
| 11 | + let(:dd_service) { 'datadog-agent' } |
| 12 | + let(:conf_file) { "#{conf_dir}/jmx.yaml" } |
| 13 | + |
| 14 | + it { should compile.with_all_deps } |
| 15 | + it { should contain_file(conf_file).with( |
| 16 | + owner: dd_user, |
| 17 | + group: dd_group, |
| 18 | + mode: '0600', |
| 19 | + )} |
| 20 | + it { should contain_file(conf_file).that_requires("Package[#{dd_package}]") } |
| 21 | + it { should contain_file(conf_file).that_notifies("Service[#{dd_service}]") } |
| 22 | + |
| 23 | + context 'with default parameters' do |
| 24 | + it { should contain_file(conf_file).with_content(%r{init_config: \{\}}) } |
| 25 | + it { should contain_file(conf_file).with_content(%r{instances: \[\]}) } |
| 26 | + end |
| 27 | + |
| 28 | + context 'with parameters set' do |
| 29 | + let(:params) do |
| 30 | + { |
| 31 | + 'init_config' => { |
| 32 | + 'custom_jar_paths' => [ |
| 33 | + '/path/to/custom/jarfile.jar', |
| 34 | + '/path/to/another/custom/jarfile2.jar' |
| 35 | + ] |
| 36 | + }, |
| 37 | + 'instances' => [{ |
| 38 | + 'host' => 'jmx1', |
| 39 | + 'port' => '867', |
| 40 | + 'user' => 'userfoo', |
| 41 | + 'password' => 'passbar', |
| 42 | + 'jmx_url' => 'service:jmx:rmi:///jndi/rmi://myhost.host:9999/custompath', |
| 43 | + 'tools_jar_path' => '/usr/lib/jvm/java-7-openjdk-amd64/lib/tools.jar', |
| 44 | + 'java_options' => '-Xmx200m -Xms50m', |
| 45 | + 'java_bin_path' => '/usr/java/jdk1.7.0_101/bin/java', |
| 46 | + 'trust_store_path' => '/var/lib/jmx/trust_store_path', |
| 47 | + 'trust_store_password' => 'hunter2', |
| 48 | + 'tags' => { |
| 49 | + 'foo' => 'bar', |
| 50 | + 'baz' => 'bat' |
| 51 | + }, |
| 52 | + 'conf' => [{ |
| 53 | + 'include' => { |
| 54 | + 'domain' => 'my_domain' |
| 55 | + } |
| 56 | + }] |
| 57 | + }] |
| 58 | + } |
| 59 | + end |
| 60 | + it { should contain_file(conf_file).with_content(%r{- /path/to/custom/jarfile.jar}) } |
| 61 | + it { should contain_file(conf_file).with_content(%r{- /path/to/another/custom/jarfile2.jar}) } |
| 62 | + it { should contain_file(conf_file).with_content(%r{host: jmx1}) } |
| 63 | + |
| 64 | + # Stringification of integers. |
| 65 | + # Puppet treats everything as a string, and then there seems to be |
| 66 | + # quoting differences between YAML export deps for Puppet 3.x and Puppet 4.x. |
| 67 | + # YAML defaults to string representation, but supports other types, so ends |
| 68 | + # up quoting integers from Puppet to explicitly mark out they're strings. |
| 69 | + it { should contain_file(conf_file).with_content(%r{port: ["']?867["']?}) } |
| 70 | + |
| 71 | + it { should contain_file(conf_file).with_content(%r{jmx_url: ["']?service:jmx:rmi:///jndi/rmi://myhost.host:9999/custompath["']?}) } |
| 72 | + it { should contain_file(conf_file).with_content(%r{user: userfoo}) } |
| 73 | + it { should contain_file(conf_file).with_content(%r{password: passbar}) } |
| 74 | + it { should contain_file(conf_file).with_content(%r{java_bin_path: /usr/java/jdk1.7.0_101/bin/java}) } |
| 75 | + it { should contain_file(conf_file).with_content(%r{java_options: ["']?-Xmx200m -Xms50m["']?}) } |
| 76 | + it { should contain_file(conf_file).with_content(%r{trust_store_path: /var/lib/jmx/trust_store_path}) } |
| 77 | + it { should contain_file(conf_file).with_content(%r{trust_store_password: hunter2}) } |
| 78 | + it { should contain_file(conf_file).with_content(%r{tags:\s+foo: bar\s+baz: bat}) } |
| 79 | + it { should contain_file(conf_file).with_content(%r{domain: my_domain}) } |
| 80 | + end |
| 81 | +end |
0 commit comments