Fix broken assertions on Windows

See gh-46334
This commit is contained in:
Stéphane Nicoll
2025-08-21 17:52:43 +02:00
parent 7a5e77fe67
commit 1590e4d2b3
3 changed files with 23 additions and 24 deletions
@@ -101,13 +101,14 @@ class ElasticCommonSchemaStructuredLogFormatterTests extends AbstractStructuredL
expectedError.put("message", "Boom");
assertThat(error).containsAllEntriesOf(expectedError);
String stackTrace = (String) error.get("stack_trace");
assertThat(stackTrace).startsWith(
"""
java.lang.RuntimeException: Boom
\tat org.springframework.boot.logging.log4j2.ElasticCommonSchemaStructuredLogFormatterTests.shouldFormatException""");
assertThat(json).contains(
"""
java.lang.RuntimeException: Boom\\n\\tat org.springframework.boot.logging.log4j2.ElasticCommonSchemaStructuredLogFormatterTests.shouldFormatException""");
assertThat(stackTrace)
.startsWith(String.format("java.lang.RuntimeException: Boom%n\tat org.springframework.boot.logging.log4j2."
+ "ElasticCommonSchemaStructuredLogFormatterTests.shouldFormatException"));
assertThat(json).contains(String
.format("java.lang.RuntimeException: Boom%n\\tat org.springframework.boot.logging.log4j2."
+ "ElasticCommonSchemaStructuredLogFormatterTests.shouldFormatException")
.replace("\n", "\\n")
.replace("\r", "\\r"));
}
@Test
@@ -136,21 +136,18 @@ class GraylogExtendedLogFormatStructuredLogFormatterTests extends AbstractStruct
String fullMessage = (String) deserialized.get("full_message");
String stackTrace = (String) deserialized.get("_error_stack_trace");
assertThat(fullMessage).startsWith(
"""
message
java.lang.RuntimeException: Boom
\tat org.springframework.boot.logging.log4j2.GraylogExtendedLogFormatStructuredLogFormatterTests.shouldFormatException""");
assertThat(stackTrace).startsWith(
"""
java.lang.RuntimeException: Boom
\tat org.springframework.boot.logging.log4j2.GraylogExtendedLogFormatStructuredLogFormatterTests.shouldFormatException""");
"message\n\njava.lang.RuntimeException: Boom%n\tat org.springframework.boot.logging.log4j2.GraylogExtendedLogFormatStructuredLogFormatterTests.shouldFormatException"
.formatted());
assertThat(deserialized)
.containsAllEntriesOf(map("_error_type", "java.lang.RuntimeException", "_error_message", "Boom"));
assertThat(stackTrace).startsWith(
"java.lang.RuntimeException: Boom%n\tat org.springframework.boot.logging.log4j2.GraylogExtendedLogFormatStructuredLogFormatterTests.shouldFormatException"
.formatted());
assertThat(json).contains(
"""
message\\n\\njava.lang.RuntimeException: Boom\\n\\tat org.springframework.boot.logging.log4j2.GraylogExtendedLogFormatStructuredLogFormatterTests.shouldFormatException""");
"java.lang.RuntimeException: Boom%n\\tat org.springframework.boot.logging.log4j2.GraylogExtendedLogFormatStructuredLogFormatterTests.shouldFormatException"
.formatted()
.replace("\n", "\\n")
.replace("\r", "\\r"));
}
@Test
@@ -80,12 +80,13 @@ class LogstashStructuredLogFormatterTests extends AbstractStructuredLoggingTests
Map<String, Object> deserialized = deserialize(json);
String stackTrace = (String) deserialized.get("stack_trace");
assertThat(stackTrace).startsWith(
"""
java.lang.RuntimeException: Boom
\tat org.springframework.boot.logging.log4j2.LogstashStructuredLogFormatterTests.shouldFormatException""");
"java.lang.RuntimeException: Boom%n\tat org.springframework.boot.logging.log4j2.LogstashStructuredLogFormatterTests.shouldFormatException"
.formatted());
assertThat(json).contains(
"""
java.lang.RuntimeException: Boom\\n\\tat org.springframework.boot.logging.log4j2.LogstashStructuredLogFormatterTests.shouldFormatException""");
"java.lang.RuntimeException: Boom%n\\tat org.springframework.boot.logging.log4j2.LogstashStructuredLogFormatterTests.shouldFormatException"
.formatted()
.replace("\n", "\\n")
.replace("\r", "\\r"));
}
@Test