Skip to content

Commit 95fb725

Browse files
authored
Fix log as array (#232)
## Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> The print method and logInConsole were printing the results as Array. This PR fixes that. Fixes # (issue) ## Type of change <!--- Please delete options that are not relevant. --> - [x] Bug fix (non-breaking change which fixes an issue) ## Checklist <!--- Please delete options that are not relevant. --> - [x] My code follows the code style of this project. - [x] All new and existing tests passed. --------- Co-authored-by: brennobemoura <[email protected]>
1 parent e121cf7 commit 95fb725

File tree

7 files changed

+29
-16
lines changed

7 files changed

+29
-16
lines changed

Sources/RequestDL/Internals/Extensions/Override/Internals.Override.Print.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ extension Internals.Override {
1313

1414
@TaskLocal
1515
fileprivate static var closure: Closure = {
16-
Swift.print($2, separator: $0, terminator: $1)
16+
Swift.print(
17+
describing($2, separator: $0),
18+
separator: $0,
19+
terminator: $1
20+
)
1721
}
1822

1923
static func replace<T: Sendable>(with closure: @escaping Closure, perform: @Sendable () async throws -> T) async rethrows -> T {
@@ -26,7 +30,15 @@ extension Internals.Override {
2630
#if DEBUG
2731
Print.closure(separator, terminator, items)
2832
#else
29-
Swift.print(items, separator: separator, terminator: terminator)
33+
Swift.print(
34+
describing(items, separator: separator),
35+
separator: separator,
36+
terminator: terminator
37+
)
3038
#endif
3139
}
3240
}
41+
42+
private func describing(_ items: [Sendable], separator: String) -> String {
43+
items.map(String.init(describing:)).joined(separator: separator)
44+
}

Sources/RequestDL/Tasks/Sources/Interceptors/Log In Console/Interceptors.LogInConsole.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ extension RequestTask {
7373
case let result as TaskResult<Data>:
7474
return result.logInConsoleOutput()
7575
case let data as Data:
76-
return data.logInConsoleOutput()
76+
return [data.logInConsoleOutput()]
7777
default:
78-
return ["Success: \($0)"]
78+
return ["\($0)"]
7979
}
8080
}
8181
))
@@ -116,16 +116,16 @@ extension RequestTask<Data> {
116116
interceptor(Interceptors.LogInConsole(
117117
isActive: isActive,
118118
results: {
119-
$0.logInConsoleOutput()
119+
[$0.logInConsoleOutput()]
120120
}
121121
))
122122
}
123123
}
124124

125125
extension Data {
126126

127-
fileprivate func logInConsoleOutput(isPayload: Bool = false) -> [String] {
128-
[(isPayload ? "Payload: " : "Success: ") + (String(data: self, encoding: .utf8) ?? debugDescription)]
127+
fileprivate func logInConsoleOutput() -> String {
128+
(String(data: self, encoding: .utf8) ?? debugDescription)
129129
}
130130
}
131131

@@ -137,9 +137,9 @@ extension TaskResult {
137137
]
138138

139139
if let payload = payload as? Data {
140-
contents.append(contentsOf: payload.logInConsoleOutput(isPayload: true))
140+
contents.append("\n" + payload.logInConsoleOutput())
141141
} else {
142-
contents.append("Payload: \(payload)")
142+
contents.append("\n" + String(describing: payload))
143143
}
144144

145145
return contents

Tests/RequestDLTests/Internals/Sources/Secure Connection/Secure Connection/InternalsSecureConnectionTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ struct InternalsSecureConnectionTests {
257257
@Test
258258
func secureConnection_whenClient_shouldBeValid() async throws {
259259
// Given
260-
var secureConnection = Internals.SecureConnection()
260+
let secureConnection = Internals.SecureConnection()
261261
let configuration: TLSConfiguration = .clientDefault
262262

263263
// When

Tests/RequestDLTests/Internals/Sources/Session/Session Configuration/InternalsSessionConfigurationTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ struct InternalsSessionConfigurationTests {
238238
@Test
239239
func configuration_whenInit_shouldBeDefault() async throws {
240240
// When
241-
var configuration = Internals.Session.Configuration()
241+
let configuration = Internals.Session.Configuration()
242242
let builtConfiguration = try configuration.build()
243243

244244
// Then

Tests/RequestDLTests/Internals/Sources/Session/Session/Models/InternalsRequestTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ struct InternalsRequestTests {
7272
@Test
7373
func request_whenUnsetReadingMode() async throws {
7474
// Given
75-
var request = Internals.Request()
75+
let request = Internals.Request()
7676
// Then
7777
#expect(request.readingMode == .length(1_024))
7878
}

Tests/RequestDLTests/Tasks/Sources/Interceptors/Log In Console/InterceptorsLogInConsoleTests.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ struct InterceptorsLogInConsoleTests {
3434
#expect(strings().first?.contains(
3535
"""
3636
Head: \(result.head)
37-
Payload: \(String(data: data, encoding: .utf8) ?? "")
37+
38+
\(String(data: data, encoding: .utf8) ?? "")
3839
"""
3940
) ?? false
4041
)
@@ -67,7 +68,8 @@ struct InterceptorsLogInConsoleTests {
6768
// Then
6869
#expect(strings().first?.contains(
6970
"""
70-
Success: \(String(data: data, encoding: .utf8) ?? "")
71+
72+
\(String(data: data, encoding: .utf8) ?? "")
7173
"""
7274
) ?? false)
7375
}
@@ -101,7 +103,7 @@ struct InterceptorsLogInConsoleTests {
101103

102104
// Then
103105
#expect(strings().first?.contains(
104-
"Success: \(value)"
106+
"\(value)"
105107
) ?? false)
106108
}
107109
}

Tests/RequestDLTests/Tasks/Sources/Raw Task/Mocked/MockedTaskTests.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ struct MockedTaskTests {
2929
// Then
3030
let response = result.head
3131

32-
#expect(response != nil)
3332
#expect(response.status.code == statusCode)
3433
#expect(result.payload == data)
3534

0 commit comments

Comments
 (0)