Skip to content

Commit 3e508d1

Browse files
author
Alex Guretzki
committed
more logger tests
1 parent 28f12ed commit 3e508d1

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

Tests/UnitTests/LoggerTests.swift

+34-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import XCTest
99

1010
class LoggerTests: XCTestCase {
1111

12-
func test_logger() async throws {
12+
func test_logLevels() async throws {
1313

1414
var logger = MockLogger()
1515

@@ -43,4 +43,37 @@ class LoggerTests: XCTestCase {
4343
logger.withLogLevel(.debug).log("log", from: "debug")
4444
logger.withLogLevel(.debug).debug("debug", from: "debug")
4545
}
46+
47+
func test_logFileLogger() async throws {
48+
49+
let outputFilePath = "output_file_path"
50+
51+
let removeExpectation = expectation(description: "remove was called twice")
52+
removeExpectation.expectedFulfillmentCount = 2
53+
54+
var expectedHandleCreateFileCalls = [
55+
"🪵 [test] log\n",
56+
"🪵 [test] log\n\n🐞 [test] debug\n"
57+
]
58+
59+
var fileHandler = MockFileHandler()
60+
fileHandler.handleRemoveItem = { path in
61+
XCTAssertEqual(path, outputFilePath)
62+
removeExpectation.fulfill()
63+
}
64+
fileHandler.handleCreateFile = { path, data in
65+
XCTAssertEqual(path, outputFilePath)
66+
let expectedInput = expectedHandleCreateFileCalls.removeFirst()
67+
XCTAssertEqual(String(data: data, encoding: .utf8), expectedInput)
68+
return true
69+
}
70+
71+
let logFileLogger = LogFileLogger(fileHandler: fileHandler, outputFilePath: outputFilePath)
72+
73+
logFileLogger.log("log", from: "test")
74+
logFileLogger.debug("debug", from: "test")
75+
76+
await fulfillment(of: [removeExpectation])
77+
XCTAssertTrue(expectedHandleCreateFileCalls.isEmpty)
78+
}
4679
}

0 commit comments

Comments
 (0)