|
126 | 126 | end |
127 | 127 | end |
128 | 128 |
|
129 | | - context 'dry_run_update_alerts_on_destination' do |
| 129 | + context "#build_alerts_queue(hosts, alerts, groups)" do |
| 130 | + let(:interferon) { Interferon::Interferon.new({ 'processes' => 0 }, true) } |
| 131 | + |
| 132 | + before do |
| 133 | + allow_any_instance_of(MockAlert).to receive(:evaluate) |
| 134 | + end |
| 135 | + |
| 136 | + it 'adds people to alerts when notify.groups{} is used' do |
| 137 | + added = create_test_alert('name1', 'testquery3', '') |
| 138 | + groups = {'a' => ['foo', 'bar']} |
| 139 | + result = interferon.build_alerts_queue(['host'], [added], groups) |
| 140 | + expect(result[0]['name1'][1]).to eq(['foo', 'bar'].to_set) |
| 141 | + end |
| 142 | + |
| 143 | + context 'when notify.fallback_groups{} is used' do |
| 144 | + it 'adds fallback people to alerts when no other groups are found' do |
| 145 | + added = create_test_alert_with_groups_and_fallback_groups(['nonexistent_group'],['fallback_group']) |
| 146 | + groups = {'fallback_group' => ['biz', 'baz']} |
| 147 | + result = interferon.build_alerts_queue(['host'], [added], groups) |
| 148 | + expect(result[0]['name1'][1]).to eq(['biz', 'baz'].to_set) |
| 149 | + end |
| 150 | + |
| 151 | + it 'does not add fallback people to alerts when other groups are found' do |
| 152 | + added = create_test_alert_with_groups_and_fallback_groups(['group'],['fallback_group']) |
| 153 | + groups = {} |
| 154 | + groups['group'] = ['foo', 'bar'] |
| 155 | + groups['fallback_groups'] = ['biz', 'baz'] |
| 156 | + result = interferon.build_alerts_queue(['host'], [added], groups) |
| 157 | + expect(result[0]['name1'][1]).to eq(['foo', 'bar'].to_set) |
| 158 | + end |
| 159 | + end |
| 160 | + end |
| 161 | + |
| 162 | + context "dry_run_update_alerts_on_destination" do |
130 | 163 | let(:interferon) { Interferon::Interferon.new({ 'processes' => 0 }, true) } |
131 | 164 |
|
132 | 165 | before do |
@@ -380,4 +413,18 @@ def create_test_alert(name, datadog_query, message, options = {}) |
380 | 413 |
|
381 | 414 | MockAlert.new(alert_dsl) |
382 | 415 | end |
| 416 | + |
| 417 | + def create_test_alert_with_groups_and_fallback_groups(groups=[], fallback_groups=[]) |
| 418 | + alert_dsl = AlertDSL.new({}) |
| 419 | + |
| 420 | + notify_dsl = NotifyDSL.new({}) |
| 421 | + notify_dsl.groups(groups) |
| 422 | + notify_dsl.fallback_groups(fallback_groups) |
| 423 | + alert_dsl.instance_variable_set(:@notify, notify_dsl) |
| 424 | + |
| 425 | + alert_dsl.name('name1') |
| 426 | + alert_dsl.applies(true) |
| 427 | + |
| 428 | + MockAlert.new(alert_dsl) |
| 429 | + end |
383 | 430 | end |
0 commit comments