|
4 | 4 | context 'supported agents' do |
5 | 5 | ALL_SUPPORTED_AGENTS.each do |agent_major_version| |
6 | 6 | let(:pre_condition) { "class {'::datadog_agent': agent_major_version => #{agent_major_version}}" } |
| 7 | + |
| 8 | + let(:title) { 'test' } |
| 9 | + |
7 | 10 | if agent_major_version == 5 |
8 | 11 | let(:conf_file) { '/etc/dd-agent/conf.d/test.yaml' } |
9 | | - |
10 | 12 | else |
11 | 13 | let(:conf_dir) { "#{CONF_DIR}/test.d" } |
12 | 14 | let(:conf_file) { "#{conf_dir}/conf.yaml" } |
13 | 15 | end |
14 | 16 |
|
15 | | - let(:title) { 'test' } |
16 | | - let(:params) do |
17 | | - { |
18 | | - instances: [ |
19 | | - { |
20 | | - one: 'two', |
21 | | - }, |
22 | | - ], |
23 | | - } |
24 | | - end |
| 17 | + gem_spec = Gem.loaded_specs['puppet'] |
25 | 18 |
|
26 | | - it { is_expected.to compile } |
27 | 19 | if agent_major_version == 5 |
28 | 20 | it { is_expected.to contain_file(conf_dir.to_s).that_comes_before("File[#{conf_file}]") } |
29 | 21 | end |
30 | | - it { is_expected.to contain_file(conf_file.to_s).with_content(%r{init_config: }) } |
31 | | - gem_spec = Gem.loaded_specs['puppet'] |
32 | | - if gem_spec.version >= Gem::Version.new('4.0.0') |
33 | | - it { is_expected.to contain_file(conf_file.to_s).with_content(%r{---\ninit_config: \ninstances:\n- one: two\n}) } |
34 | | - else |
35 | | - it { is_expected.to contain_file(conf_file.to_s).with_content(%r{--- \n init_config: \n instances: \n - one: two}) } |
36 | | - end |
37 | 22 | it { is_expected.to contain_file(conf_file.to_s).that_notifies("Service[#{SERVICE_NAME}]") } |
38 | 23 |
|
| 24 | + context 'with instances' do |
| 25 | + let(:params) do |
| 26 | + { |
| 27 | + instances: [ |
| 28 | + { |
| 29 | + one: 'two', |
| 30 | + }, |
| 31 | + ], |
| 32 | + } |
| 33 | + end |
| 34 | + it { is_expected.to compile } |
| 35 | + if gem_spec.version >= Gem::Version.new('4.0.0') |
| 36 | + it { is_expected.to contain_file(conf_file.to_s).with_content(%r{---\ninit_config:\ninstances:\n- one: two\n}) } |
| 37 | + else |
| 38 | + it { is_expected.to contain_file(conf_file.to_s).with_content(%r{--- \n init_config:\n instances: \n - one: two}) } |
| 39 | + end |
| 40 | + end |
| 41 | + |
39 | 42 | context 'with logs' do |
40 | 43 | let(:params) do |
41 | 44 | { |
|
47 | 50 | logs: ['one', 'two'], |
48 | 51 | } |
49 | 52 | end |
50 | | - |
| 53 | + it { is_expected.to compile } |
51 | 54 | if gem_spec.version >= Gem::Version.new('4.0.0') |
52 | 55 | it { is_expected.to contain_file(conf_file).with_content(%r{logs:\n- one\n- two}) } |
53 | 56 | else |
54 | 57 | it { is_expected.to contain_file(conf_file).with_content(%r{logs:\n - one\n - two}) } |
55 | 58 | end |
56 | 59 | end |
| 60 | + |
| 61 | + context 'with ensure absent' do |
| 62 | + let(:params) do |
| 63 | + { |
| 64 | + ensure: 'absent', |
| 65 | + } |
| 66 | + end |
| 67 | + it { is_expected.to compile } |
| 68 | + it { is_expected.to contain_file(conf_file).with_ensure('absent') } |
| 69 | + end |
| 70 | + |
57 | 71 | end |
58 | 72 | end |
59 | 73 | end |
0 commit comments