Add validations for mode values

Fix conditional event_description. Should check for `merge` instead of
`merged`.
This commit is contained in:
Christian Hein 2017-07-26 10:38:03 -03:00
parent e9f025d063
commit 4565c73a33
2 changed files with 11 additions and 1 deletions

View file

@ -84,7 +84,7 @@ module Agents
event_description do
"Events will have the following fields%s:\n\n %s" % [
case options['mode'].to_s
when 'merged'
when 'merge'
', merged with the original contents'
when /\{/
', conditionally merged with the original contents'
@ -98,6 +98,10 @@ module Agents
def validate_options
errors.add(:base, "instructions and mode need to be present.") unless options['instructions'].present? && options['mode'].present?
if options['mode'].present? && !options['mode'].to_s.include?('{{') && !%[clean merge].include?(options['mode'].to_s)
errors.add(:base, "mode must be 'clean' or 'merge'")
end
validate_matchers
end

View file

@ -74,6 +74,12 @@ describe Agents::EventFormattingAgent do
expect(Event.last.payload[:content]).not_to eq(nil)
end
it "should handle Liquid templating in mode" do
@checker.options[:mode] = "{{'merge'}}"
@checker.receive([@event])
expect(Event.last.payload[:content]).not_to eq(nil)
end
it "should handle Liquid templating in instructions" do
@checker.receive([@event])
expect(Event.last.payload[:message]).to eq("Received Some Lorem Ipsum from somevalue .")