mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 14:47:19 -04:00
Fix: missed 'equal' part in time comparison test
In time comparison of LocalDateTime the isBefore is strict, so in case two instants has the same millisecond, it fails in test (happens in Windows tests) Close: 11862 Backport of #11862 to 7.x
This commit is contained in:
parent
734ec04186
commit
fe105710b5
1 changed files with 26 additions and 1 deletions
|
@ -19,6 +19,8 @@
|
|||
|
||||
package org.logstash.config.ir;
|
||||
|
||||
import org.hamcrest.Description;
|
||||
import org.hamcrest.TypeSafeMatcher;
|
||||
import org.jruby.*;
|
||||
import org.jruby.runtime.builtin.IRubyObject;
|
||||
import org.junit.Before;
|
||||
|
@ -35,6 +37,25 @@ import static org.junit.Assert.*;
|
|||
|
||||
public class PipelineConfigTest extends RubyEnvTestCase {
|
||||
|
||||
private static class IsBeforeOrSameMatcher extends TypeSafeMatcher<LocalDateTime> {
|
||||
|
||||
private LocalDateTime after;
|
||||
|
||||
IsBeforeOrSameMatcher(LocalDateTime after) {
|
||||
this.after = after;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean matchesSafely(LocalDateTime item) {
|
||||
return item.isBefore(after) || item.isEqual(after);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeTo(Description description) {
|
||||
description.appendText(" is before " + after);
|
||||
}
|
||||
}
|
||||
|
||||
public static final String PIPELINE_ID = "main";
|
||||
private RubyClass source;
|
||||
private RubySymbol pipelineIdSym;
|
||||
|
@ -87,7 +108,11 @@ public class PipelineConfigTest extends RubyEnvTestCase {
|
|||
assertEquals("returns the pipeline id", PIPELINE_ID, sut.getPipelineId());
|
||||
assertNotNull("returns the config_hash", sut.configHash());
|
||||
assertEquals("returns the merged `ConfigPart#config_string`", configMerged, sut.configString());
|
||||
assertTrue("records when the config was read", sut.getReadAt().isBefore(LocalDateTime.now()));
|
||||
assertThat("records when the config was read", sut.getReadAt(), isBeforeOrSame(LocalDateTime.now()));
|
||||
}
|
||||
|
||||
private static IsBeforeOrSameMatcher isBeforeOrSame(LocalDateTime after) {
|
||||
return new IsBeforeOrSameMatcher(after);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue