Skip to content

Commit 19d9e13

Browse files
mergify[bot]yaauie
andauthored
[8.19] (backport #18124) test: explicitly load ascii fixture as ascii, do line-oriented parsing (#18125)
* test: explicitly load ascii fixture as ascii, do line-oriented parsing (#18124) (cherry picked from commit 6a51c82) # Conflicts: # logstash-core/src/test/java/org/logstash/EventTest.java * Update logstash-core/src/test/java/org/logstash/EventTest.java --------- Co-authored-by: Rye Biesemeyer <[email protected]>
1 parent 75ba04f commit 19d9e13

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

logstash-core/src/test/java/org/logstash/EventTest.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.util.HexFormat;
3434
import java.util.List;
3535
import java.util.Map;
36+
import java.util.stream.Collectors;
3637
import org.jruby.RubyString;
3738
import org.jruby.RubySymbol;
3839
import org.jruby.RubyTime;
@@ -149,7 +150,7 @@ public void bigNumsBinaryRoundtrip() throws Exception {
149150

150151
@Test
151152
public void deserializeStringrefExtensionEnabled() throws Exception {
152-
byte[] stringrefCBOR = loadAnnotatedCBORFixture("stringref-enabled.annotated-cbor.txt");
153+
byte[] stringrefCBOR = loadAnnotatedCBORFixture("stringref-enabled.annotated-cbor.asc");
153154
Event event = Event.deserialize(stringrefCBOR);
154155
event.getField("[event][original]");
155156
assertEquals("stringref", event.getField("test"));
@@ -158,7 +159,7 @@ public void deserializeStringrefExtensionEnabled() throws Exception {
158159

159160
@Test
160161
public void deserializeStringrefExtensionDisabled() throws Exception {
161-
byte[] stringrefCBOR = loadAnnotatedCBORFixture("stringref-disabled.annotated-cbor.txt");
162+
byte[] stringrefCBOR = loadAnnotatedCBORFixture("stringref-disabled.annotated-cbor.asc");
162163
Event event = Event.deserialize(stringrefCBOR);
163164
event.getField("[event][original]");
164165
assertEquals("stringref", event.getField("test"));
@@ -627,9 +628,13 @@ static byte[] loadAnnotatedCBORFixture(String name) throws IOException {
627628
try (InputStream resourceAsStream = EventTest.class.getResourceAsStream(name)) {
628629
assertNotNull(resourceAsStream);
629630

630-
String annotated = new String(resourceAsStream.readAllBytes(), StandardCharsets.UTF_8);
631-
// annotated CBOR: strip #-initiated line comments, then strip whitespace to get hex
632-
String hexBytes = annotated.replaceAll("#.*(\\n|$)", "").replaceAll("\\s", "");
631+
final String annotatedFixture = new String(resourceAsStream.readAllBytes(), StandardCharsets.US_ASCII);
632+
final String hexBytes = annotatedFixture.lines()
633+
// strip #-prefixed annotations
634+
.map(line -> line.split("#", 2)[0])
635+
// strip all remaining whitespace
636+
.map(line -> line.replaceAll("\\s", ""))
637+
.collect(Collectors.joining());
633638

634639
// result should be even number of hex digits
635640
assert hexBytes.matches("(?i:[0-9a-f]{2})*");
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)