mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 06:37:19 -04:00
- raise an exception if you try to set @timestamp to an invalid value
type. OH STATIC TYPING SOMETIMES I MISS YOU.
This commit is contained in:
parent
2d6a0d6b4f
commit
d7d68ad9b9
2 changed files with 10 additions and 0 deletions
|
@ -119,6 +119,10 @@ class LogStash::Event
|
|||
|
||||
public
|
||||
def []=(str, value)
|
||||
if str == "@timestamp" && !value.is_a?(Time)
|
||||
raise TypeError, "The field '@timestamp' must be a Time, not a #{value.class} (#{value})"
|
||||
end
|
||||
|
||||
r = LogStash::Util::FieldReference.exec(str, @data) do |obj, key|
|
||||
obj[key] = value
|
||||
end
|
||||
|
|
|
@ -25,6 +25,12 @@ describe LogStash::Event do
|
|||
)
|
||||
end
|
||||
|
||||
context "[]=" do
|
||||
it "should raise an exception if you attempt to set @timestamp to a value type other than a Time object" do
|
||||
insist { subject["@timestamp"] = "crash!" }.raises(TypeError)
|
||||
end
|
||||
end
|
||||
|
||||
context "#sprintf" do
|
||||
it "should report a unix timestamp for %{+%s}" do
|
||||
insist { subject.sprintf("%{+%s}") } == "1356998400"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue