Skip to content

Commit

Permalink
test: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lovetodream committed Apr 21, 2024
1 parent 942ca64 commit 5cbab91
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions Tests/LoggingLokiTests/LokiLogHandlerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ final class LokiLogHandlerTests: XCTestCase {
let expectedFile = "TestFile.swift"
let expectedFunction = "testFunction(_:)"
let expectedLine: UInt = 42
let expectedService = "test.swift-log"
let expectedLabel = "test.swift-log"
let expectedService = "LokiLogTests"

func testLog() async throws {
let transport = TestTransport()
Expand All @@ -50,8 +51,8 @@ final class LokiLogHandlerTests: XCTestCase {
let processing = Task {
try await processor.run()
}
let handler = LokiLogHandler(label: expectedService, processor: processor)
let handler = LokiLogHandler(label: expectedLabel, service: expectedService, processor: processor)

handler.log(level: .error, message: "\(expectedLogMessage)", metadata: ["log": "swift"], source: expectedSource, file: expectedFile, function: expectedFunction, line: expectedLine)

clock.advance(by: .seconds(5)) // tick
Expand Down Expand Up @@ -80,8 +81,8 @@ final class LokiLogHandlerTests: XCTestCase {
let processing = Task {
try await processor.run()
}
let handler = LokiLogHandler(label: expectedService, processor: processor)
let handler = LokiLogHandler(label: expectedLabel, service: expectedService, processor: processor)

handler.log(level: .error, message: "\(expectedLogMessage)", metadata: ["log": "swift"], source: expectedSource, file: expectedFile, function: expectedFunction, line: expectedLine)

clock.advance(by: .seconds(5)) // tick
Expand Down Expand Up @@ -119,7 +120,7 @@ final class LokiLogHandlerTests: XCTestCase {
let processing = Task {
try await processor.run()
}
let handler = LokiLogHandler(label: expectedService, processor: processor)
let handler = LokiLogHandler(label: expectedLabel, service: expectedService, processor: processor)
handler.log(level: .error, message: "\(expectedLogMessage)", metadata: ["log": "swift"], source: expectedSource, file: expectedFile, function: expectedFunction, line: expectedLine)
await sleepCalls.next()
XCTAssertNil(transformer.logs?.first)
Expand Down Expand Up @@ -155,6 +156,9 @@ final class LokiLogHandlerTests: XCTestCase {
XCTAssert(transformer.labels?.contains(where: { key, value in
value == String(expectedLine) && key == "line"
}) ?? false, file: file, line: line)
XCTAssert(transformer.labels?.contains(where: { key, value in
value == expectedLabel && key == "logger"
}) ?? false, file: file, line: line)
XCTAssert(transformer.labels?.contains(where: { key, value in
value == expectedService && key == "service"
}) ?? false, file: file, line: line)
Expand Down

0 comments on commit 5cbab91

Please sign in to comment.