|
1 | 1 | require 'spec_helper' |
2 | 2 |
|
3 | 3 | describe 'datadog_agent::integrations::apache' 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}/apache.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{apache_status_url: http://localhost/server-status\?auto}) } |
25 | | - it { should contain_file(conf_file).without_content(/tags:/) } |
26 | | - it { should contain_file(conf_file).without_content(/apache_user:/) } |
27 | | - it { should contain_file(conf_file).without_content(/apache_password:/) } |
28 | | - end |
29 | | - |
30 | | - context 'with parameters set' do |
31 | | - let(:params) {{ |
32 | | - url: 'http://foobar', |
33 | | - username: 'userfoo', |
34 | | - password: 'passfoo', |
35 | | - tags: %w{foo bar baz}, |
36 | | - }} |
37 | | - it { should contain_file(conf_file).with_content(%r{apache_status_url: http://foobar}) } |
38 | | - it { should contain_file(conf_file).with_content(/apache_user: userfoo/) } |
39 | | - it { should contain_file(conf_file).with_content(/apache_password: passfoo/) } |
40 | | - end |
41 | | - |
42 | | - context 'with tags parameter single value' do |
43 | | - let(:params) {{ |
44 | | - tags: 'foo', |
45 | | - }} |
46 | | - it { should_not compile } |
47 | | - |
48 | | - skip "this is currently unimplemented behavior" do |
49 | | - it { should contain_file(conf_file).with_content(/tags:\s+- foo\s*?[^-]/m) } |
50 | | - end |
51 | | - end |
52 | | - |
53 | | - context 'with tags parameter array' do |
54 | | - let(:params) {{ |
55 | | - tags: %w{ foo bar baz }, |
56 | | - }} |
57 | | - it { should contain_file(conf_file).with_content(/tags:\s+- foo\s+- bar\s+- baz\s*?[^-]/m) } |
58 | | - end |
59 | | - |
60 | | - context 'with tags parameter empty values' do |
61 | | - context 'mixed in with other tags' do |
62 | | - let(:params) {{ |
63 | | - tags: [ 'foo', '', 'baz' ] |
64 | | - }} |
65 | | - |
66 | | - it { should contain_file(conf_file).with_content(/tags:\s+- foo\s+- baz\s*?[^-]/m) } |
67 | | - end |
68 | | - |
69 | | - context 'single element array of an empty string' do |
70 | | - let(:params) {{ |
71 | | - tags: [''], |
72 | | - }} |
73 | | - |
74 | | - skip("undefined behavior") |
75 | | - end |
76 | | - |
77 | | - context 'single value empty string' do |
78 | | - let(:params) {{ |
79 | | - tags: '', |
| 4 | + context 'supported agents - v5 and v6' do |
| 5 | + agents = { '5' => false, '6' => true } |
| 6 | + agents.each do |_, enabled| |
| 7 | + let(:pre_condition) { "class {'::datadog_agent': agent6_enable => #{enabled}}" } |
| 8 | + let(:facts) {{ |
| 9 | + operatingsystem: 'Ubuntu', |
80 | 10 | }} |
| 11 | + if !enabled |
| 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 | + let(:agent6_enable) { enabled } |
| 21 | + let(:conf_file) { "#{conf_dir}/apache.yaml" } |
| 22 | + |
| 23 | + it { should compile.with_all_deps } |
81 | 24 |
|
82 | | - skip("doubly undefined behavior") |
| 25 | + it { should contain_class('datadog_agent') } |
| 26 | + it { should contain_file(conf_file).with( |
| 27 | + owner: dd_user, |
| 28 | + group: dd_group, |
| 29 | + mode: '0600', |
| 30 | + )} |
| 31 | + it { should contain_file(conf_file).that_requires("Package[#{dd_package}]") } |
| 32 | + it { should contain_file(conf_file).that_notifies("Service[#{dd_service}]") } |
| 33 | + |
| 34 | + context 'with default parameters' do |
| 35 | + it { should contain_file(conf_file).with_content(%r{apache_status_url: http://localhost/server-status\?auto}) } |
| 36 | + it { should contain_file(conf_file).without_content(/tags:/) } |
| 37 | + it { should contain_file(conf_file).without_content(/apache_user:/) } |
| 38 | + it { should contain_file(conf_file).without_content(/apache_password:/) } |
| 39 | + end |
| 40 | + |
| 41 | + context 'with parameters set' do |
| 42 | + let(:params) {{ |
| 43 | + url: 'http://foobar', |
| 44 | + username: 'userfoo', |
| 45 | + password: 'passfoo', |
| 46 | + tags: %w{foo bar baz}, |
| 47 | + }} |
| 48 | + it { should contain_file(conf_file).with_content(%r{apache_status_url: http://foobar}) } |
| 49 | + it { should contain_file(conf_file).with_content(/apache_user: userfoo/) } |
| 50 | + it { should contain_file(conf_file).with_content(/apache_password: passfoo/) } |
| 51 | + end |
| 52 | + |
| 53 | + context 'with tags parameter single value' do |
| 54 | + let(:params) {{ |
| 55 | + tags: 'foo', |
| 56 | + }} |
| 57 | + it { should_not compile } |
| 58 | + |
| 59 | + skip "this is currently unimplemented behavior" do |
| 60 | + it { should contain_file(conf_file).with_content(/tags:\s+- foo\s*?[^-]/m) } |
| 61 | + end |
| 62 | + end |
| 63 | + |
| 64 | + context 'with tags parameter array' do |
| 65 | + let(:params) {{ |
| 66 | + tags: %w{ foo bar baz }, |
| 67 | + }} |
| 68 | + it { should contain_file(conf_file).with_content(/tags:\s+- foo\s+- bar\s+- baz\s*?[^-]/m) } |
| 69 | + end |
| 70 | + |
| 71 | + context 'with tags parameter empty values' do |
| 72 | + context 'mixed in with other tags' do |
| 73 | + let(:params) {{ |
| 74 | + tags: [ 'foo', '', 'baz' ] |
| 75 | + }} |
| 76 | + |
| 77 | + it { should contain_file(conf_file).with_content(/tags:\s+- foo\s+- baz\s*?[^-]/m) } |
| 78 | + end |
| 79 | + |
| 80 | + context 'single element array of an empty string' do |
| 81 | + let(:params) {{ |
| 82 | + tags: [''], |
| 83 | + }} |
| 84 | + |
| 85 | + skip("undefined behavior") |
| 86 | + end |
| 87 | + |
| 88 | + context 'single value empty string' do |
| 89 | + let(:params) {{ |
| 90 | + tags: '', |
| 91 | + }} |
| 92 | + |
| 93 | + skip("doubly undefined behavior") |
| 94 | + end |
| 95 | + end |
83 | 96 | end |
84 | 97 | end |
85 | 98 | end |
0 commit comments