From 54013013f89aa03ff5541c831aceba358ef16b34 Mon Sep 17 00:00:00 2001 From: Yehor Popovych Date: Wed, 14 Aug 2024 17:12:03 +0100 Subject: [PATCH] fixed EventExporter tests (#118) --- Sources/EventsExporter/Upload/HTTPClient.swift | 3 +-- Tests/EventsExporter/EventsExporterTests.swift | 3 ++- Tests/EventsExporter/Helpers/CoreMocks.swift | 2 +- Tests/EventsExporter/Logs/LogsExporterTests.swift | 3 ++- Tests/EventsExporter/Spans/SpansExporterTests.swift | 3 ++- .../Upload/DataUploadWorkerTests.swift | 12 ++++++------ Tests/EventsExporter/Upload/DataUploaderTests.swift | 4 ++-- Tests/EventsExporter/Upload/HTTPClientTests.swift | 4 ++-- 8 files changed, 18 insertions(+), 16 deletions(-) diff --git a/Sources/EventsExporter/Upload/HTTPClient.swift b/Sources/EventsExporter/Upload/HTTPClient.swift index 2ad50f95..fdf7b36c 100644 --- a/Sources/EventsExporter/Upload/HTTPClient.swift +++ b/Sources/EventsExporter/Upload/HTTPClient.swift @@ -54,8 +54,7 @@ internal final class HTTPClient { Log.debug("[NET] => \(request)\n\tERR: \(err)\n\tRES: \(res)\n\tDATA: \(data))") return } - let resData = data.flatMap{ String(data: $0, encoding: .utf8) } - var log = """ + let log = """ [NET] => \(request.url!) RES CODE: \(httpres.statusCode) ERROR: \(error?.localizedDescription ?? "") diff --git a/Tests/EventsExporter/EventsExporterTests.swift b/Tests/EventsExporter/EventsExporterTests.swift index 8708618e..ac2b6c38 100644 --- a/Tests/EventsExporter/EventsExporterTests.swift +++ b/Tests/EventsExporter/EventsExporterTests.swift @@ -58,7 +58,8 @@ class EventsExporterTests: XCTestCase { logsURL: URL(string: "http://localhost:33333/logs")! ), exporterId: "exporterId", - logger: Log()) + logger: Log(), + debugNetwork: false) let datadogExporter = try! EventsExporter(config: exporterConfiguration) diff --git a/Tests/EventsExporter/Helpers/CoreMocks.swift b/Tests/EventsExporter/Helpers/CoreMocks.swift index a29a696d..a324e75e 100644 --- a/Tests/EventsExporter/Helpers/CoreMocks.swift +++ b/Tests/EventsExporter/Helpers/CoreMocks.swift @@ -128,7 +128,7 @@ extension SingleRequestBuilder: AnyMockable { extension HTTPClient { static func mockAny() -> HTTPClient { - return HTTPClient(session: URLSession(configuration: URLSessionConfiguration.default)) + return HTTPClient(session: URLSession(configuration: URLSessionConfiguration.default), debug: false) } } diff --git a/Tests/EventsExporter/Logs/LogsExporterTests.swift b/Tests/EventsExporter/Logs/LogsExporterTests.swift index a9b2d644..78c09732 100644 --- a/Tests/EventsExporter/Logs/LogsExporterTests.swift +++ b/Tests/EventsExporter/Logs/LogsExporterTests.swift @@ -49,7 +49,8 @@ class LogsExporterTests: XCTestCase { ), performancePreset: .instantDataDelivery, exporterId: "exporterId", - logger: Log()) + logger: Log(), + debugNetwork: false) let logsExporter = try LogsExporter(config: configuration) diff --git a/Tests/EventsExporter/Spans/SpansExporterTests.swift b/Tests/EventsExporter/Spans/SpansExporterTests.swift index e743bb35..fde07b5f 100644 --- a/Tests/EventsExporter/Spans/SpansExporterTests.swift +++ b/Tests/EventsExporter/Spans/SpansExporterTests.swift @@ -50,7 +50,8 @@ class SpansExporterTests: XCTestCase { ), performancePreset: .instantDataDelivery, exporterId: "exporterId", - logger: Log()) + logger: Log(), + debugNetwork: false) let spansExporter = try SpansExporter(config: configuration) diff --git a/Tests/EventsExporter/Upload/DataUploadWorkerTests.swift b/Tests/EventsExporter/Upload/DataUploadWorkerTests.swift index 54bead0a..7a286ede 100644 --- a/Tests/EventsExporter/Upload/DataUploadWorkerTests.swift +++ b/Tests/EventsExporter/Upload/DataUploadWorkerTests.swift @@ -38,7 +38,7 @@ class DataUploadWorkerTests: XCTestCase { func testItUploadsAllData() { let server = ServerMock(delivery: .success(response: .mockResponseWith(statusCode: 200))) let dataUploader = DataUploader( - httpClient: HTTPClient(session: server.getInterceptedURLSession()), + httpClient: HTTPClient(session: server.getInterceptedURLSession(), debug: false), requestBuilder: SingleRequestBuilder.mockAny() ) @@ -133,7 +133,7 @@ class DataUploadWorkerTests: XCTestCase { let server = ServerMock(delivery: .success(response: .mockResponseWith(statusCode: 200))) let dataUploader = DataUploader( - httpClient: HTTPClient(session: server.getInterceptedURLSession()), + httpClient: HTTPClient(session: server.getInterceptedURLSession(), debug: false), requestBuilder: SingleRequestBuilder.mockAny() ) let worker = DataUploadWorker( @@ -164,7 +164,7 @@ class DataUploadWorkerTests: XCTestCase { let server = ServerMock(delivery: .success(response: .mockResponseWith(statusCode: 500))) let dataUploader = DataUploader( - httpClient: HTTPClient(session: server.getInterceptedURLSession()), + httpClient: HTTPClient(session: server.getInterceptedURLSession(), debug: false), requestBuilder: SingleRequestBuilder.mockAny() ) let worker = DataUploadWorker( @@ -195,7 +195,7 @@ class DataUploadWorkerTests: XCTestCase { let server = ServerMock(delivery: .success(response: .mockResponseWith(statusCode: 200))) let dataUploader = DataUploader( - httpClient: HTTPClient(session: server.getInterceptedURLSession()), + httpClient: HTTPClient(session: server.getInterceptedURLSession(), debug: false), requestBuilder: SingleRequestBuilder.mockAny() ) let worker = DataUploadWorker( @@ -217,7 +217,7 @@ class DataUploadWorkerTests: XCTestCase { // Given let server = ServerMock(delivery: .success(response: .mockResponseWith(statusCode: 200))) let dataUploader = DataUploader( - httpClient: HTTPClient(session: server.getInterceptedURLSession()), + httpClient: HTTPClient(session: server.getInterceptedURLSession(), debug: false), requestBuilder: SingleRequestBuilder.mockAny() ) let worker = DataUploadWorker( @@ -239,7 +239,7 @@ class DataUploadWorkerTests: XCTestCase { func testItFlushesAllData() { let server = ServerMock(delivery: .success(response: .mockResponseWith(statusCode: 200))) let dataUploader = DataUploader( - httpClient: HTTPClient(session: server.getInterceptedURLSession()), + httpClient: HTTPClient(session: server.getInterceptedURLSession(), debug: false), requestBuilder: SingleRequestBuilder.mockAny() ) let worker = DataUploadWorker( diff --git a/Tests/EventsExporter/Upload/DataUploaderTests.swift b/Tests/EventsExporter/Upload/DataUploaderTests.swift index 85d004f0..56725438 100644 --- a/Tests/EventsExporter/Upload/DataUploaderTests.swift +++ b/Tests/EventsExporter/Upload/DataUploaderTests.swift @@ -16,7 +16,7 @@ class DataUploaderTests: XCTestCase { let server = ServerMock(delivery: .success(response: randomResponse)) let uploader = DataUploader( - httpClient: HTTPClient(session: server.getInterceptedURLSession()), + httpClient: HTTPClient(session: server.getInterceptedURLSession(), debug: false), requestBuilder: SingleRequestBuilder.mockWith(headers: []) ) @@ -37,7 +37,7 @@ class DataUploaderTests: XCTestCase { let server = ServerMock(delivery: .failure(error: randomError)) let uploader = DataUploader( - httpClient: HTTPClient(session: server.getInterceptedURLSession()), + httpClient: HTTPClient(session: server.getInterceptedURLSession(), debug: false), requestBuilder: SingleRequestBuilder.mockAny() ) diff --git a/Tests/EventsExporter/Upload/HTTPClientTests.swift b/Tests/EventsExporter/Upload/HTTPClientTests.swift index 04b9e20a..9a5309a7 100644 --- a/Tests/EventsExporter/Upload/HTTPClientTests.swift +++ b/Tests/EventsExporter/Upload/HTTPClientTests.swift @@ -11,7 +11,7 @@ class HTTPClientTests: XCTestCase { func testWhenRequestIsDelivered_itReturnsHTTPResponse() { let server = ServerMock(delivery: .success(response: .mockResponseWith(statusCode: 200))) let expectation = self.expectation(description: "receive response") - let client = HTTPClient(session: server.getInterceptedURLSession()) + let client = HTTPClient(session: server.getInterceptedURLSession(), debug: false) client.send(request: .mockAny()) { result in switch result { @@ -31,7 +31,7 @@ class HTTPClientTests: XCTestCase { let mockError = NSError(domain: "network", code: 999, userInfo: [NSLocalizedDescriptionKey: "no internet connection"]) let server = ServerMock(delivery: .failure(error: mockError)) let expectation = self.expectation(description: "receive response") - let client = HTTPClient(session: server.getInterceptedURLSession()) + let client = HTTPClient(session: server.getInterceptedURLSession(), debug: false) client.send(request: .mockAny()) { result in switch result {