Skip to content

Commit

Permalink
test(style): Properly style test file
Browse files Browse the repository at this point in the history
  • Loading branch information
hkupty committed Nov 14, 2023
1 parent 52d648a commit 8729886
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
class CoreSinkTests {

private static final ObjectMapper om = new ObjectMapper();

@Provide
Arbitrary<LogField[]> fields() {
return Arbitraries.of(LogField.class).array(LogField[].class).uniqueElements();
Expand Down Expand Up @@ -85,7 +86,10 @@ Arbitrary<PennaLogEvent> simpleEvent() {
Random random = new SecureRandom();

return Builders.withBuilder(PennaLogEvent::new)
.use(messages).in((evt, m) -> {evt.message = m; return evt;})
.use(messages).in((evt, m) -> {
evt.message = m;
return evt;
})
.use(arguments).in((evt, args) -> {
var msg = new StringBuilder(evt.message);
random.ints(random.nextInt(
Expand All @@ -99,16 +103,31 @@ Arbitrary<PennaLogEvent> simpleEvent() {
.forEach(index -> msg.replace(index, index, "{}"));

evt.message = msg.toString();
for (var arg: args) {
for (var arg : args) {
evt.addArgument(arg);
}
return evt;
})
.use(markers).in((evt, m) -> {evt.markers.addAll(m); return evt;})
.use(kvps).in((evt, m) -> {evt.keyValuePairs.addAll(m); return evt;})
.use(levels).in((evt, m) -> {evt.level = m; return evt;})
.use(threads).in((evt, m) -> {evt.threadName = m.getBytes(); return evt;})
.use(throwableArbitrary()).withProbability(0.3).in((evt, t) -> {evt.throwable = t; return evt;})
.use(markers).in((evt, m) -> {
evt.markers.addAll(m);
return evt;
})
.use(kvps).in((evt, m) -> {
evt.keyValuePairs.addAll(m);
return evt;
})
.use(levels).in((evt, m) -> {
evt.level = m;
return evt;
})
.use(threads).in((evt, m) -> {
evt.threadName = m.getBytes();
return evt;
})
.use(throwableArbitrary()).withProbability(0.3).in((evt, t) -> {
evt.throwable = t;
return evt;
})
.build();
}

Expand Down
9 changes: 6 additions & 3 deletions penna-core/src/test/java/penna/core/logger/LoggerTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ record ThrowableLog(
@JsonProperty("class") String throwable,
String message,
List<String> stacktrace
) {}
) {
}

record LogMessage(
long timestamp,
Expand All @@ -40,15 +41,16 @@ record LogMessage(
List<String> tags,
Map<String, Object> data,
ThrowableLog throwable
) {}
) {
}

private static final ObjectMapper om = new ObjectMapper();

@Test
void log_levels_are_respected() {
var cache = new TreeCache(Config.getDefault());
PennaLogger pennaLogger = cache.getLoggerAt("test");
String[] ref = new String[] {"test"};
String[] ref = new String[]{"test"};

// null-level, no logs
cache.updateConfig(ref, config -> config.replaceLevel(null));
Expand Down Expand Up @@ -176,4 +178,5 @@ void everything_added_to_the_log_is_present_in_the_message() throws IOException
testFile.deleteOnExit();
fos.close();
}

}

0 comments on commit 8729886

Please sign in to comment.