Skip to content

Commit 4e2911c

Browse files
committed
Add test for withMetadata convenience function
1 parent cea90dd commit 4e2911c

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Tests/LoggingTests/LoggingTest.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,25 @@ class LoggingTest: XCTestCase {
357357
"nested-list": ["l1str", ["l2str1", "l2str2"]]])
358358
}
359359

360+
func testWithMetadata() {
361+
let testLogging = TestLogging()
362+
LoggingSystem.bootstrapInternal { testLogging.make(label: $0) }
363+
364+
var logger = Logger(label: "\(#function)")
365+
let metadata: Logger.Metadata = [
366+
"foo": ["bar", "buz"],
367+
"empty-list": [],
368+
"nested-list": ["l1str", ["l2str1", "l2str2"]]
369+
]
370+
logger.withMetadata(metadata: metadata)
371+
logger.info("hello world!")
372+
testLogging.history.assertExist(level: .info,
373+
message: "hello world!",
374+
metadata: ["foo": ["bar", "buz"],
375+
"empty-list": [],
376+
"nested-list": ["l1str", ["l2str1", "l2str2"]]])
377+
}
378+
360379
// Example of custom "box" which may be used to implement "render at most once" semantics
361380
// Not thread-safe, thus should not be shared across threads.
362381
internal final class LazyMetadataBox: CustomStringConvertible {

0 commit comments

Comments
 (0)