-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add %{{TIME_NOW}} pattern for sprintf #16906
Changes from 5 commits
5107f97
d26a7db
7496037
2ad1905
5979511
6cbf6f8
6fce423
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,9 @@ | |
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.junit.Assert.*; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertThrows; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
|
||
public class StringInterpolationTest extends RubyTestBase { | ||
|
@@ -149,6 +151,24 @@ public void TestValueIsHash() throws IOException { | |
assertEquals("{\"k1\":\"v\"}", StringInterpolation.evaluate(event, path)); | ||
} | ||
|
||
@Test | ||
public void TestTimeNow() throws IOException { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know that the other test methods starts with capital letter, but in Java methods starts with lowercase.
|
||
Event event = getTestEvent(); | ||
String pattern = "%{{TIME_NOW}}"; | ||
Timestamp before = new Timestamp(); | ||
Timestamp result = new Timestamp(StringInterpolation.evaluate(event, pattern)); | ||
Timestamp after = new Timestamp(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Secondary note, that you could leave out: I know that it's hard two creation of |
||
assertTrue(before.compareTo(result) < 0); | ||
assertTrue(after.compareTo(result) > 0); | ||
} | ||
|
||
@Test | ||
public void TestBadTimeNow() throws IOException { | ||
Event event = getTestEvent(); | ||
String pattern = "%{{BAD_TIME_NOW}}"; | ||
assertThrows(IllegalArgumentException.class, () -> StringInterpolation.evaluate(event, pattern)); | ||
} | ||
|
||
public Event getTestEvent() { | ||
Map<String, Object> data = new HashMap<>(); | ||
Map<String, String> inner = new HashMap<>(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe all this time related logic could be extracted in separate helper method.