diff --git a/NodeKit/Utils/Logging/LoggingContext.swift b/NodeKit/Utils/Logging/LoggingContext.swift index c5e3735a..46e12dd0 100644 --- a/NodeKit/Utils/Logging/LoggingContext.swift +++ b/NodeKit/Utils/Logging/LoggingContext.swift @@ -11,17 +11,17 @@ import Foundation protocol LoggingContextProtocol: Actor { // Лог контекста var log: Logable? { get } - + /// Добавляет лог-сообщение к контексту. /// - Parameter log: лог-сообщение. func add(_ log: Logable?) } actor LoggingContext: LoggingContextProtocol { - + // Лог контекста public private(set) var log: Logable? - + /// Добавляет лог-сообщение к контексту. /// В случае, если у контекста не было лога, то он появится. /// В случае, если у контекста был лог, но у него не было следующего, то этот добавится в качестве следующего лога. @@ -45,5 +45,5 @@ actor LoggingContext: LoggingContextProtocol { self.log = selfLog return } - + } diff --git a/NodeKitTests/Utils/Equatable/Log+Equatalbe.swift b/NodeKitTests/Utils/Equatable/Log+Equatalbe.swift index da04bab5..85d9d543 100644 --- a/NodeKitTests/Utils/Equatable/Log+Equatalbe.swift +++ b/NodeKitTests/Utils/Equatable/Log+Equatalbe.swift @@ -9,7 +9,7 @@ @testable import NodeKit extension Log: Equatable { - + public static func == (lhs: NodeKit.Log, rhs: NodeKit.Log) -> Bool { return lhs.message == rhs.message && lhs.description == rhs.description && @@ -17,5 +17,5 @@ extension Log: Equatable { lhs.id == rhs.id && lhs.order == rhs.order } - + } diff --git a/NodeKitTests/Utils/LoggingContextTests.swift b/NodeKitTests/Utils/LoggingContextTests.swift index d46898b6..d6a75fbe 100644 --- a/NodeKitTests/Utils/LoggingContextTests.swift +++ b/NodeKitTests/Utils/LoggingContextTests.swift @@ -10,103 +10,103 @@ import XCTest final class LoggingContextTests: XCTestCase { - + // MARK: - Sut - + private var sut: LoggingContext! - + // MARK: - Lifecycle - + override func setUp() { super.setUp() sut = LoggingContext() } - + override func tearDown() { super.tearDown() sut = nil } - + // MARK: - Tests - + func testLog_whenNothingAppending_thenResultIsNil() async { // when - + let result = await sut.log - + // then - + XCTAssertNil(result) } - + func testLog_whenOneItemAppending_therResultIsAppendedItem() async throws { // given - + let testLog = Log("Test message", id: "Test id") - + // when - + await sut.add(testLog) - + let log = await sut.log let result = try XCTUnwrap(log as? Log) - + // then - + XCTAssertEqual(result, testLog) } - + func testLog_whenTwoItemsAppending_thenResultIsFirstItemAndNextIsSecondItem() async throws { // given - + let firstLog = Log("Test first message", id: "Test first id") let secondLog = Log("Test second message", id: "Test second id") - + var expectedLog = firstLog expectedLog.next = secondLog - + // when - + await sut.add(firstLog) await sut.add(secondLog) - + let log = await sut.log let result = try XCTUnwrap(log as? Log) let resultNext = try XCTUnwrap(result.next as? Log) - + // then - + XCTAssertEqual(result, expectedLog) XCTAssertEqual(resultNext, secondLog) XCTAssertNil(resultNext.next) } - + func testLog_whenThreeItemsAppending_thenResultIsFirstItemAndNextIsTree() async throws { // given - + let firstLog = Log("Test first message", id: "Test first id") let secondLog = Log("Test second message", id: "Test second id") let thirdLog = Log("Test third message", id: "Test third id") - + var expectedLog = firstLog var expectedThirdLog = thirdLog - + expectedThirdLog.next = secondLog expectedLog.next = expectedThirdLog - + // when - + await sut.add(firstLog) await sut.add(secondLog) await sut.add(thirdLog) - + let log = await sut.log let result = try XCTUnwrap((log) as? Log) let firstNextResult = try XCTUnwrap(result.next as? Log) let secondNextResult = try XCTUnwrap(firstNextResult.next as? Log) - + // then - + XCTAssertEqual(result, expectedLog) XCTAssertEqual(firstNextResult, expectedThirdLog) XCTAssertEqual(secondNextResult, secondLog) @@ -115,40 +115,40 @@ final class LoggingContextTests: XCTestCase { func testLog_whenFourItemsAppending_thenResultIsFirstItemAndNextIsTree() async throws { // given - + let firstLog = Log("Test first message", id: "Test first id") let secondLog = Log("Test second message", id: "Test second id") let thirdLog = Log("Test third message", id: "Test third id") let fourthLog = Log("Test fourth message", id: "Test fourth id") - + var expectedLog = firstLog var expectedFourthLog = fourthLog var expectedThirdLog = thirdLog - + expectedThirdLog.next = secondLog expectedFourthLog.next = expectedThirdLog expectedLog.next = expectedFourthLog - + // when - + await sut.add(firstLog) await sut.add(secondLog) await sut.add(thirdLog) await sut.add(fourthLog) - + let log = await sut.log let result = try XCTUnwrap(log as? Log) let firstNextResult = try XCTUnwrap(result.next as? Log) let secondNextResult = try XCTUnwrap(firstNextResult.next as? Log) let thirdNextResult = try XCTUnwrap(secondNextResult.next as? Log) - + // then - + XCTAssertEqual(result, expectedLog) XCTAssertEqual(firstNextResult, expectedFourthLog) XCTAssertEqual(secondNextResult, expectedThirdLog) XCTAssertEqual(thirdNextResult, secondLog) XCTAssertNil(thirdNextResult.next) } - + }