-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
66 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
Tests/DatadogTests/DatadogObjc/DDNSURLSessionDelegateTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
* This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
* Copyright 2019-2020 Datadog, Inc. | ||
*/ | ||
|
||
import XCTest | ||
@testable import Datadog | ||
@testable import DatadogObjc | ||
|
||
private class DDURLSessionDelegateMock: DDURLSessionDelegate { | ||
var calledDidFinishCollecting = false | ||
var calledDidCompleteWithError = false | ||
|
||
override func urlSession(_ session: URLSession, task: URLSessionTask, didFinishCollecting metrics: URLSessionTaskMetrics) { | ||
calledDidFinishCollecting = true | ||
} | ||
|
||
override func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) { | ||
calledDidCompleteWithError = true | ||
} | ||
} | ||
|
||
class DDNSURLSessionDelegateTests: XCTestCase { | ||
func testInit() { | ||
let delegate = DDNSURLSessionDelegate() | ||
XCTAssertNil(delegate.swiftDelegate.firstPartyURLsFilter) | ||
} | ||
|
||
func testInitWithAdditionalFirstPartyHosts() { | ||
let delegate = DDNSURLSessionDelegate(additionalFirstPartyHosts: ["foo.com"]) | ||
XCTAssertNotNil(delegate.swiftDelegate.firstPartyURLsFilter) | ||
} | ||
|
||
func testItForwardsCallsToSwiftDelegate() { | ||
let swiftDelegate = DDURLSessionDelegateMock() | ||
let objcDelegate = DDNSURLSessionDelegate() | ||
objcDelegate.swiftDelegate = swiftDelegate | ||
|
||
objcDelegate.urlSession(.shared, task: .mockAny(), didFinishCollecting: .mockAny()) | ||
objcDelegate.urlSession(.shared, task: .mockAny(), didCompleteWithError: ErrorMock()) | ||
|
||
XCTAssertTrue(swiftDelegate.calledDidFinishCollecting) | ||
XCTAssertTrue(swiftDelegate.calledDidCompleteWithError) | ||
} | ||
} |