spec/lib/flapjack/data/notification_rule_spec.rb in flapjack-0.8.8 vs spec/lib/flapjack/data/notification_rule_spec.rb in flapjack-0.8.9
- old
+ new
@@ -13,10 +13,11 @@
}
let(:rule_data) {
{:contact_id => '23',
:tags => ["database","physical"],
+ :regex_tags => [],
:entities => ["foo-app-01.example.com"],
:time_restrictions => [ weekdays_8_18 ],
:unknown_media => [],
:warning_media => ["email"],
:critical_media => ["sms", "email"],
@@ -24,18 +25,37 @@
:warning_blackhole => false,
:critical_blackhole => false
}
}
+ let(:regex_rule_data) {
+ {:contact_id => '23',
+ :tags => [],
+ :regex_tags => ["^data.*$","^(physical|bare_metal)$"],
+ :entities => ["foo-app-01.example.com"],
+ :time_restrictions => [ weekdays_8_18 ],
+ :unknown_media => [],
+ :warning_media => ["email"],
+ :critical_media => ["sms", "email"],
+ :unknown_blackhole => false,
+ :warning_blackhole => false,
+ :critical_blackhole => false
+ }
+ }
+
let(:rule_id) { 'ABC123' }
let(:timezone) { ActiveSupport::TimeZone.new("Europe/Moscow") }
let(:existing_rule) {
Flapjack::Data::NotificationRule.add(rule_data, :redis => @redis)
}
+ let(:existing_regex_rule) {
+ Flapjack::Data::NotificationRule.add(regex_rule_data, :redis => @redis)
+ }
+
it "checks that a notification rule exists" do
expect(Flapjack::Data::NotificationRule.exists_with_id?(existing_rule.id, :redis => @redis)).to be true
expect(Flapjack::Data::NotificationRule.exists_with_id?('not_there', :redis => @redis)).to be false
end
@@ -83,9 +103,18 @@
expect(rule.match_tags?(['database', 'physical'].to_set)).to be true
expect(rule.match_tags?(['database', 'physical', 'beetroot'].to_set)).to be true
expect(rule.match_tags?(['database'].to_set)).to be false
expect(rule.match_tags?(['virtual'].to_set)).to be false
+ end
+
+ it "checks whether entity tags match a regex" do
+ rule = existing_regex_rule
+
+ expect(rule.match_regex_tags?(['database', 'physical'].to_set)).to be true
+ expect(rule.match_regex_tags?(['database', 'physical', 'beetroot'].to_set)).to be true
+ expect(rule.match_regex_tags?(['database'].to_set)).to be false
+ expect(rule.match_regex_tags?(['virtual'].to_set)).to be false
end
it "checks if blackhole settings for a rule match a severity level" do
rule_data[:warning_blackhole] = true
rule = Flapjack::Data::NotificationRule.add(rule_data, :redis => @redis)