- 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:
Jordan Sissel 2013-11-19 12:34:28 -08:00
parent 2d6a0d6b4f
commit d7d68ad9b9
2 changed files with 10 additions and 0 deletions

View file

@ -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

View file

@ -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"