Skip to content

Commit

Permalink
fixed EventExporter tests (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
ypopovych authored Aug 14, 2024
1 parent 87215b4 commit 5401301
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 16 deletions.
3 changes: 1 addition & 2 deletions Sources/EventsExporter/Upload/HTTPClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? "")
Expand Down
3 changes: 2 additions & 1 deletion Tests/EventsExporter/EventsExporterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion Tests/EventsExporter/Helpers/CoreMocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
3 changes: 2 additions & 1 deletion Tests/EventsExporter/Logs/LogsExporterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class LogsExporterTests: XCTestCase {
),
performancePreset: .instantDataDelivery,
exporterId: "exporterId",
logger: Log())
logger: Log(),
debugNetwork: false)

let logsExporter = try LogsExporter(config: configuration)

Expand Down
3 changes: 2 additions & 1 deletion Tests/EventsExporter/Spans/SpansExporterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ class SpansExporterTests: XCTestCase {
),
performancePreset: .instantDataDelivery,
exporterId: "exporterId",
logger: Log())
logger: Log(),
debugNetwork: false)

let spansExporter = try SpansExporter(config: configuration)

Expand Down
12 changes: 6 additions & 6 deletions Tests/EventsExporter/Upload/DataUploadWorkerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions Tests/EventsExporter/Upload/DataUploaderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: [])
)

Expand All @@ -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()
)

Expand Down
4 changes: 2 additions & 2 deletions Tests/EventsExporter/Upload/HTTPClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 5401301

Please sign in to comment.